lll-sdk 0.0.0-experimental-20250902142618 → 0.0.0-experimental-20250902142929

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,12 +1,24 @@
1
- var Ku=Object.create;var Hs=Object.defineProperty;var Wu=Object.getOwnPropertyDescriptor;var zu=Object.getOwnPropertyNames;var Xu=Object.getPrototypeOf,Ju=Object.prototype.hasOwnProperty;var vt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var dr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Yu=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of zu(t))!Ju.call(e,n)&&n!==i&&Hs(e,n,{get:()=>t[n],enumerable:!(r=Wu(t,n))||r.enumerable});return e};var Gs=(e,t,i)=>(i=e!=null?Ku(Xu(e)):{},Yu(t||!e||!e.__esModule?Hs(i,"default",{value:e,enumerable:!0}):i,e));var ba=dr((wa,Io)=>{"use strict";(function(e,t){"use strict";function i(S,h){if(!S)throw new Error(h||"Assertion failed")}function r(S,h){S.super_=h;var o=function(){};o.prototype=h.prototype,S.prototype=new o,S.prototype.constructor=S}function n(S,h,o){if(n.isBN(S))return S;this.negative=0,this.words=null,this.length=0,this.red=null,S!==null&&((h==="le"||h==="be")&&(o=h,h=10),this._init(S||0,h||10,o||"be"))}typeof e=="object"?e.exports=n:t.BN=n,n.BN=n,n.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=vt("buffer").Buffer}catch{}n.isBN=function(h){return h instanceof n?!0:h!==null&&typeof h=="object"&&h.constructor.wordSize===n.wordSize&&Array.isArray(h.words)},n.max=function(h,o){return h.cmp(o)>0?h:o},n.min=function(h,o){return h.cmp(o)<0?h:o},n.prototype._init=function(h,o,l){if(typeof h=="number")return this._initNumber(h,o,l);if(typeof h=="object")return this._initArray(h,o,l);o==="hex"&&(o=16),i(o===(o|0)&&o>=2&&o<=36),h=h.toString().replace(/\s+/g,"");var d=0;h[0]==="-"&&(d++,this.negative=1),d<h.length&&(o===16?this._parseHex(h,d,l):(this._parseBase(h,o,d),l==="le"&&this._initArray(this.toArray(),o,l)))},n.prototype._initNumber=function(h,o,l){h<0&&(this.negative=1,h=-h),h<67108864?(this.words=[h&67108863],this.length=1):h<4503599627370496?(this.words=[h&67108863,h/67108864&67108863],this.length=2):(i(h<9007199254740992),this.words=[h&67108863,h/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},n.prototype._initArray=function(h,o,l){if(i(typeof h.length=="number"),h.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(h.length/3),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var m,_,b=0;if(l==="be")for(d=h.length-1,m=0;d>=0;d-=3)_=h[d]|h[d-1]<<8|h[d-2]<<16,this.words[m]|=_<<b&67108863,this.words[m+1]=_>>>26-b&67108863,b+=24,b>=26&&(b-=26,m++);else if(l==="le")for(d=0,m=0;d<h.length;d+=3)_=h[d]|h[d+1]<<8|h[d+2]<<16,this.words[m]|=_<<b&67108863,this.words[m+1]=_>>>26-b&67108863,b+=24,b>=26&&(b-=26,m++);return this._strip()};function a(S,h){var o=S.charCodeAt(h);if(o>=48&&o<=57)return o-48;if(o>=65&&o<=70)return o-55;if(o>=97&&o<=102)return o-87;i(!1,"Invalid character in "+S)}function c(S,h,o){var l=a(S,o);return o-1>=h&&(l|=a(S,o-1)<<4),l}n.prototype._parseHex=function(h,o,l){this.length=Math.ceil((h.length-o)/6),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var m=0,_=0,b;if(l==="be")for(d=h.length-1;d>=o;d-=2)b=c(h,o,d)<<m,this.words[_]|=b&67108863,m>=18?(m-=18,_+=1,this.words[_]|=b>>>26):m+=8;else{var w=h.length-o;for(d=w%2===0?o+1:o;d<h.length;d+=2)b=c(h,o,d)<<m,this.words[_]|=b&67108863,m>=18?(m-=18,_+=1,this.words[_]|=b>>>26):m+=8}this._strip()};function p(S,h,o,l){for(var d=0,m=0,_=Math.min(S.length,o),b=h;b<_;b++){var w=S.charCodeAt(b)-48;d*=l,w>=49?m=w-49+10:w>=17?m=w-17+10:m=w,i(w>=0&&m<l,"Invalid character"),d+=m}return d}n.prototype._parseBase=function(h,o,l){this.words=[0],this.length=1;for(var d=0,m=1;m<=67108863;m*=o)d++;d--,m=m/o|0;for(var _=h.length-l,b=_%d,w=Math.min(_,_-b)+l,f=0,u=l;u<w;u+=d)f=p(h,u,u+d,o),this.imuln(m),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(b!==0){var M=1;for(f=p(h,u,h.length,o),u=0;u<b;u++)M*=o;this.imuln(M),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this._strip()},n.prototype.copy=function(h){h.words=new Array(this.length);for(var o=0;o<this.length;o++)h.words[o]=this.words[o];h.length=this.length,h.negative=this.negative,h.red=this.red};function g(S,h){S.words=h.words,S.length=h.length,S.negative=h.negative,S.red=h.red}if(n.prototype._move=function(h){g(h,this)},n.prototype.clone=function(){var h=new n(null);return this.copy(h),h},n.prototype._expand=function(h){for(;this.length<h;)this.words[this.length++]=0;return this},n.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},n.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=v}catch{n.prototype.inspect=v}else n.prototype.inspect=v;function v(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var y=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],A=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];n.prototype.toString=function(h,o){h=h||10,o=o|0||1;var l;if(h===16||h==="hex"){l="";for(var d=0,m=0,_=0;_<this.length;_++){var b=this.words[_],w=((b<<d|m)&16777215).toString(16);m=b>>>24-d&16777215,d+=2,d>=26&&(d-=26,_--),m!==0||_!==this.length-1?l=y[6-w.length]+w+l:l=w+l}for(m!==0&&(l=m.toString(16)+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(h===(h|0)&&h>=2&&h<=36){var f=A[h],u=k[h];l="";var M=this.clone();for(M.negative=0;!M.isZero();){var q=M.modrn(u).toString(h);M=M.idivn(u),M.isZero()?l=q+l:l=y[f-q.length]+q+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}i(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var h=this.words[0];return this.length===2?h+=this.words[1]*67108864:this.length===3&&this.words[2]===1?h+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-h:h},n.prototype.toJSON=function(){return this.toString(16,2)},s&&(n.prototype.toBuffer=function(h,o){return this.toArrayLike(s,h,o)}),n.prototype.toArray=function(h,o){return this.toArrayLike(Array,h,o)};var U=function(h,o){return h.allocUnsafe?h.allocUnsafe(o):new h(o)};n.prototype.toArrayLike=function(h,o,l){this._strip();var d=this.byteLength(),m=l||Math.max(1,d);i(d<=m,"byte array longer than desired length"),i(m>0,"Requested array length <= 0");var _=U(h,m),b=o==="le"?"LE":"BE";return this["_toArrayLike"+b](_,d),_},n.prototype._toArrayLikeLE=function(h,o){for(var l=0,d=0,m=0,_=0;m<this.length;m++){var b=this.words[m]<<_|d;h[l++]=b&255,l<h.length&&(h[l++]=b>>8&255),l<h.length&&(h[l++]=b>>16&255),_===6?(l<h.length&&(h[l++]=b>>24&255),d=0,_=0):(d=b>>>24,_+=2)}if(l<h.length)for(h[l++]=d;l<h.length;)h[l++]=0},n.prototype._toArrayLikeBE=function(h,o){for(var l=h.length-1,d=0,m=0,_=0;m<this.length;m++){var b=this.words[m]<<_|d;h[l--]=b&255,l>=0&&(h[l--]=b>>8&255),l>=0&&(h[l--]=b>>16&255),_===6?(l>=0&&(h[l--]=b>>24&255),d=0,_=0):(d=b>>>24,_+=2)}if(l>=0)for(h[l--]=d;l>=0;)h[l--]=0},Math.clz32?n.prototype._countBits=function(h){return 32-Math.clz32(h)}:n.prototype._countBits=function(h){var o=h,l=0;return o>=4096&&(l+=13,o>>>=13),o>=64&&(l+=7,o>>>=7),o>=8&&(l+=4,o>>>=4),o>=2&&(l+=2,o>>>=2),l+o},n.prototype._zeroBits=function(h){if(h===0)return 26;var o=h,l=0;return(o&8191)===0&&(l+=13,o>>>=13),(o&127)===0&&(l+=7,o>>>=7),(o&15)===0&&(l+=4,o>>>=4),(o&3)===0&&(l+=2,o>>>=2),(o&1)===0&&l++,l},n.prototype.bitLength=function(){var h=this.words[this.length-1],o=this._countBits(h);return(this.length-1)*26+o};function P(S){for(var h=new Array(S.bitLength()),o=0;o<h.length;o++){var l=o/26|0,d=o%26;h[o]=S.words[l]>>>d&1}return h}n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var h=0,o=0;o<this.length;o++){var l=this._zeroBits(this.words[o]);if(h+=l,l!==26)break}return h},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(h){return this.negative!==0?this.abs().inotn(h).iaddn(1):this.clone()},n.prototype.fromTwos=function(h){return this.testn(h-1)?this.notn(h).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return this.negative!==0},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.prototype.iuor=function(h){for(;this.length<h.length;)this.words[this.length++]=0;for(var o=0;o<h.length;o++)this.words[o]=this.words[o]|h.words[o];return this._strip()},n.prototype.ior=function(h){return i((this.negative|h.negative)===0),this.iuor(h)},n.prototype.or=function(h){return this.length>h.length?this.clone().ior(h):h.clone().ior(this)},n.prototype.uor=function(h){return this.length>h.length?this.clone().iuor(h):h.clone().iuor(this)},n.prototype.iuand=function(h){var o;this.length>h.length?o=h:o=this;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]&h.words[l];return this.length=o.length,this._strip()},n.prototype.iand=function(h){return i((this.negative|h.negative)===0),this.iuand(h)},n.prototype.and=function(h){return this.length>h.length?this.clone().iand(h):h.clone().iand(this)},n.prototype.uand=function(h){return this.length>h.length?this.clone().iuand(h):h.clone().iuand(this)},n.prototype.iuxor=function(h){var o,l;this.length>h.length?(o=this,l=h):(o=h,l=this);for(var d=0;d<l.length;d++)this.words[d]=o.words[d]^l.words[d];if(this!==o)for(;d<o.length;d++)this.words[d]=o.words[d];return this.length=o.length,this._strip()},n.prototype.ixor=function(h){return i((this.negative|h.negative)===0),this.iuxor(h)},n.prototype.xor=function(h){return this.length>h.length?this.clone().ixor(h):h.clone().ixor(this)},n.prototype.uxor=function(h){return this.length>h.length?this.clone().iuxor(h):h.clone().iuxor(this)},n.prototype.inotn=function(h){i(typeof h=="number"&&h>=0);var o=Math.ceil(h/26)|0,l=h%26;this._expand(o),l>0&&o--;for(var d=0;d<o;d++)this.words[d]=~this.words[d]&67108863;return l>0&&(this.words[d]=~this.words[d]&67108863>>26-l),this._strip()},n.prototype.notn=function(h){return this.clone().inotn(h)},n.prototype.setn=function(h,o){i(typeof h=="number"&&h>=0);var l=h/26|0,d=h%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<d:this.words[l]=this.words[l]&~(1<<d),this._strip()},n.prototype.iadd=function(h){var o;if(this.negative!==0&&h.negative===0)return this.negative=0,o=this.isub(h),this.negative^=1,this._normSign();if(this.negative===0&&h.negative!==0)return h.negative=0,o=this.isub(h),h.negative=1,o._normSign();var l,d;this.length>h.length?(l=this,d=h):(l=h,d=this);for(var m=0,_=0;_<d.length;_++)o=(l.words[_]|0)+(d.words[_]|0)+m,this.words[_]=o&67108863,m=o>>>26;for(;m!==0&&_<l.length;_++)o=(l.words[_]|0)+m,this.words[_]=o&67108863,m=o>>>26;if(this.length=l.length,m!==0)this.words[this.length]=m,this.length++;else if(l!==this)for(;_<l.length;_++)this.words[_]=l.words[_];return this},n.prototype.add=function(h){var o;return h.negative!==0&&this.negative===0?(h.negative=0,o=this.sub(h),h.negative^=1,o):h.negative===0&&this.negative!==0?(this.negative=0,o=h.sub(this),this.negative=1,o):this.length>h.length?this.clone().iadd(h):h.clone().iadd(this)},n.prototype.isub=function(h){if(h.negative!==0){h.negative=0;var o=this.iadd(h);return h.negative=1,o._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(h),this.negative=1,this._normSign();var l=this.cmp(h);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var d,m;l>0?(d=this,m=h):(d=h,m=this);for(var _=0,b=0;b<m.length;b++)o=(d.words[b]|0)-(m.words[b]|0)+_,_=o>>26,this.words[b]=o&67108863;for(;_!==0&&b<d.length;b++)o=(d.words[b]|0)+_,_=o>>26,this.words[b]=o&67108863;if(_===0&&b<d.length&&d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this.length=Math.max(this.length,b),d!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(h){return this.clone().isub(h)};function W(S,h,o){o.negative=h.negative^S.negative;var l=S.length+h.length|0;o.length=l,l=l-1|0;var d=S.words[0]|0,m=h.words[0]|0,_=d*m,b=_&67108863,w=_/67108864|0;o.words[0]=b;for(var f=1;f<l;f++){for(var u=w>>>26,M=w&67108863,q=Math.min(f,h.length-1),$=Math.max(0,f-S.length+1);$<=q;$++){var z=f-$|0;d=S.words[z]|0,m=h.words[$]|0,_=d*m+M,u+=_/67108864|0,M=_&67108863}o.words[f]=M|0,w=u|0}return w!==0?o.words[f]=w|0:o.length--,o._strip()}var j=function(h,o,l){var d=h.words,m=o.words,_=l.words,b=0,w,f,u,M=d[0]|0,q=M&8191,$=M>>>13,z=d[1]|0,ie=z&8191,C=z>>>13,T=d[2]|0,x=T&8191,F=T>>>13,L=d[3]|0,G=L&8191,B=L>>>13,D=d[4]|0,Z=D&8191,H=D>>>13,V=d[5]|0,ee=V&8191,te=V>>>13,le=d[6]|0,Ee=le&8191,ce=le>>>13,pe=d[7]|0,Ce=pe&8191,ue=pe>>>13,Se=d[8]|0,et=Se&8191,fe=Se>>>13,Re=d[9]|0,Ye=Re&8191,he=Re>>>13,Ie=m[0]|0,ze=Ie&8191,de=Ie>>>13,Ue=m[1]|0,ot=Ue&8191,me=Ue>>>13,je=m[2]|0,st=je&8191,ge=je>>>13,qe=m[3]|0,at=qe&8191,_e=qe>>>13,$e=m[4]|0,lt=$e&8191,ve=$e>>>13,He=m[5]|0,ut=He&8191,we=He>>>13,Ge=m[6]|0,ct=Ge&8191,be=Ge>>>13,Ve=m[7]|0,dt=Ve&8191,ye=Ve>>>13,Ze=m[8]|0,ht=Ze&8191,Me=Ze>>>13,Ke=m[9]|0,ft=Ke&8191,Ae=Ke>>>13;l.negative=h.negative^o.negative,l.length=19,w=Math.imul(q,ze),f=Math.imul(q,de),f=f+Math.imul($,ze)|0,u=Math.imul($,de);var Be=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Be>>>26)|0,Be&=67108863,w=Math.imul(ie,ze),f=Math.imul(ie,de),f=f+Math.imul(C,ze)|0,u=Math.imul(C,de),w=w+Math.imul(q,ot)|0,f=f+Math.imul(q,me)|0,f=f+Math.imul($,ot)|0,u=u+Math.imul($,me)|0;var Gt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,w=Math.imul(x,ze),f=Math.imul(x,de),f=f+Math.imul(F,ze)|0,u=Math.imul(F,de),w=w+Math.imul(ie,ot)|0,f=f+Math.imul(ie,me)|0,f=f+Math.imul(C,ot)|0,u=u+Math.imul(C,me)|0,w=w+Math.imul(q,st)|0,f=f+Math.imul(q,ge)|0,f=f+Math.imul($,st)|0,u=u+Math.imul($,ge)|0;var Vt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,w=Math.imul(G,ze),f=Math.imul(G,de),f=f+Math.imul(B,ze)|0,u=Math.imul(B,de),w=w+Math.imul(x,ot)|0,f=f+Math.imul(x,me)|0,f=f+Math.imul(F,ot)|0,u=u+Math.imul(F,me)|0,w=w+Math.imul(ie,st)|0,f=f+Math.imul(ie,ge)|0,f=f+Math.imul(C,st)|0,u=u+Math.imul(C,ge)|0,w=w+Math.imul(q,at)|0,f=f+Math.imul(q,_e)|0,f=f+Math.imul($,at)|0,u=u+Math.imul($,_e)|0;var Zt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,w=Math.imul(Z,ze),f=Math.imul(Z,de),f=f+Math.imul(H,ze)|0,u=Math.imul(H,de),w=w+Math.imul(G,ot)|0,f=f+Math.imul(G,me)|0,f=f+Math.imul(B,ot)|0,u=u+Math.imul(B,me)|0,w=w+Math.imul(x,st)|0,f=f+Math.imul(x,ge)|0,f=f+Math.imul(F,st)|0,u=u+Math.imul(F,ge)|0,w=w+Math.imul(ie,at)|0,f=f+Math.imul(ie,_e)|0,f=f+Math.imul(C,at)|0,u=u+Math.imul(C,_e)|0,w=w+Math.imul(q,lt)|0,f=f+Math.imul(q,ve)|0,f=f+Math.imul($,lt)|0,u=u+Math.imul($,ve)|0;var Kt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,w=Math.imul(ee,ze),f=Math.imul(ee,de),f=f+Math.imul(te,ze)|0,u=Math.imul(te,de),w=w+Math.imul(Z,ot)|0,f=f+Math.imul(Z,me)|0,f=f+Math.imul(H,ot)|0,u=u+Math.imul(H,me)|0,w=w+Math.imul(G,st)|0,f=f+Math.imul(G,ge)|0,f=f+Math.imul(B,st)|0,u=u+Math.imul(B,ge)|0,w=w+Math.imul(x,at)|0,f=f+Math.imul(x,_e)|0,f=f+Math.imul(F,at)|0,u=u+Math.imul(F,_e)|0,w=w+Math.imul(ie,lt)|0,f=f+Math.imul(ie,ve)|0,f=f+Math.imul(C,lt)|0,u=u+Math.imul(C,ve)|0,w=w+Math.imul(q,ut)|0,f=f+Math.imul(q,we)|0,f=f+Math.imul($,ut)|0,u=u+Math.imul($,we)|0;var Wt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,w=Math.imul(Ee,ze),f=Math.imul(Ee,de),f=f+Math.imul(ce,ze)|0,u=Math.imul(ce,de),w=w+Math.imul(ee,ot)|0,f=f+Math.imul(ee,me)|0,f=f+Math.imul(te,ot)|0,u=u+Math.imul(te,me)|0,w=w+Math.imul(Z,st)|0,f=f+Math.imul(Z,ge)|0,f=f+Math.imul(H,st)|0,u=u+Math.imul(H,ge)|0,w=w+Math.imul(G,at)|0,f=f+Math.imul(G,_e)|0,f=f+Math.imul(B,at)|0,u=u+Math.imul(B,_e)|0,w=w+Math.imul(x,lt)|0,f=f+Math.imul(x,ve)|0,f=f+Math.imul(F,lt)|0,u=u+Math.imul(F,ve)|0,w=w+Math.imul(ie,ut)|0,f=f+Math.imul(ie,we)|0,f=f+Math.imul(C,ut)|0,u=u+Math.imul(C,we)|0,w=w+Math.imul(q,ct)|0,f=f+Math.imul(q,be)|0,f=f+Math.imul($,ct)|0,u=u+Math.imul($,be)|0;var zt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(zt>>>26)|0,zt&=67108863,w=Math.imul(Ce,ze),f=Math.imul(Ce,de),f=f+Math.imul(ue,ze)|0,u=Math.imul(ue,de),w=w+Math.imul(Ee,ot)|0,f=f+Math.imul(Ee,me)|0,f=f+Math.imul(ce,ot)|0,u=u+Math.imul(ce,me)|0,w=w+Math.imul(ee,st)|0,f=f+Math.imul(ee,ge)|0,f=f+Math.imul(te,st)|0,u=u+Math.imul(te,ge)|0,w=w+Math.imul(Z,at)|0,f=f+Math.imul(Z,_e)|0,f=f+Math.imul(H,at)|0,u=u+Math.imul(H,_e)|0,w=w+Math.imul(G,lt)|0,f=f+Math.imul(G,ve)|0,f=f+Math.imul(B,lt)|0,u=u+Math.imul(B,ve)|0,w=w+Math.imul(x,ut)|0,f=f+Math.imul(x,we)|0,f=f+Math.imul(F,ut)|0,u=u+Math.imul(F,we)|0,w=w+Math.imul(ie,ct)|0,f=f+Math.imul(ie,be)|0,f=f+Math.imul(C,ct)|0,u=u+Math.imul(C,be)|0,w=w+Math.imul(q,dt)|0,f=f+Math.imul(q,ye)|0,f=f+Math.imul($,dt)|0,u=u+Math.imul($,ye)|0;var Xt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,w=Math.imul(et,ze),f=Math.imul(et,de),f=f+Math.imul(fe,ze)|0,u=Math.imul(fe,de),w=w+Math.imul(Ce,ot)|0,f=f+Math.imul(Ce,me)|0,f=f+Math.imul(ue,ot)|0,u=u+Math.imul(ue,me)|0,w=w+Math.imul(Ee,st)|0,f=f+Math.imul(Ee,ge)|0,f=f+Math.imul(ce,st)|0,u=u+Math.imul(ce,ge)|0,w=w+Math.imul(ee,at)|0,f=f+Math.imul(ee,_e)|0,f=f+Math.imul(te,at)|0,u=u+Math.imul(te,_e)|0,w=w+Math.imul(Z,lt)|0,f=f+Math.imul(Z,ve)|0,f=f+Math.imul(H,lt)|0,u=u+Math.imul(H,ve)|0,w=w+Math.imul(G,ut)|0,f=f+Math.imul(G,we)|0,f=f+Math.imul(B,ut)|0,u=u+Math.imul(B,we)|0,w=w+Math.imul(x,ct)|0,f=f+Math.imul(x,be)|0,f=f+Math.imul(F,ct)|0,u=u+Math.imul(F,be)|0,w=w+Math.imul(ie,dt)|0,f=f+Math.imul(ie,ye)|0,f=f+Math.imul(C,dt)|0,u=u+Math.imul(C,ye)|0,w=w+Math.imul(q,ht)|0,f=f+Math.imul(q,Me)|0,f=f+Math.imul($,ht)|0,u=u+Math.imul($,Me)|0;var Jt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,w=Math.imul(Ye,ze),f=Math.imul(Ye,de),f=f+Math.imul(he,ze)|0,u=Math.imul(he,de),w=w+Math.imul(et,ot)|0,f=f+Math.imul(et,me)|0,f=f+Math.imul(fe,ot)|0,u=u+Math.imul(fe,me)|0,w=w+Math.imul(Ce,st)|0,f=f+Math.imul(Ce,ge)|0,f=f+Math.imul(ue,st)|0,u=u+Math.imul(ue,ge)|0,w=w+Math.imul(Ee,at)|0,f=f+Math.imul(Ee,_e)|0,f=f+Math.imul(ce,at)|0,u=u+Math.imul(ce,_e)|0,w=w+Math.imul(ee,lt)|0,f=f+Math.imul(ee,ve)|0,f=f+Math.imul(te,lt)|0,u=u+Math.imul(te,ve)|0,w=w+Math.imul(Z,ut)|0,f=f+Math.imul(Z,we)|0,f=f+Math.imul(H,ut)|0,u=u+Math.imul(H,we)|0,w=w+Math.imul(G,ct)|0,f=f+Math.imul(G,be)|0,f=f+Math.imul(B,ct)|0,u=u+Math.imul(B,be)|0,w=w+Math.imul(x,dt)|0,f=f+Math.imul(x,ye)|0,f=f+Math.imul(F,dt)|0,u=u+Math.imul(F,ye)|0,w=w+Math.imul(ie,ht)|0,f=f+Math.imul(ie,Me)|0,f=f+Math.imul(C,ht)|0,u=u+Math.imul(C,Me)|0,w=w+Math.imul(q,ft)|0,f=f+Math.imul(q,Ae)|0,f=f+Math.imul($,ft)|0,u=u+Math.imul($,Ae)|0;var Yt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,w=Math.imul(Ye,ot),f=Math.imul(Ye,me),f=f+Math.imul(he,ot)|0,u=Math.imul(he,me),w=w+Math.imul(et,st)|0,f=f+Math.imul(et,ge)|0,f=f+Math.imul(fe,st)|0,u=u+Math.imul(fe,ge)|0,w=w+Math.imul(Ce,at)|0,f=f+Math.imul(Ce,_e)|0,f=f+Math.imul(ue,at)|0,u=u+Math.imul(ue,_e)|0,w=w+Math.imul(Ee,lt)|0,f=f+Math.imul(Ee,ve)|0,f=f+Math.imul(ce,lt)|0,u=u+Math.imul(ce,ve)|0,w=w+Math.imul(ee,ut)|0,f=f+Math.imul(ee,we)|0,f=f+Math.imul(te,ut)|0,u=u+Math.imul(te,we)|0,w=w+Math.imul(Z,ct)|0,f=f+Math.imul(Z,be)|0,f=f+Math.imul(H,ct)|0,u=u+Math.imul(H,be)|0,w=w+Math.imul(G,dt)|0,f=f+Math.imul(G,ye)|0,f=f+Math.imul(B,dt)|0,u=u+Math.imul(B,ye)|0,w=w+Math.imul(x,ht)|0,f=f+Math.imul(x,Me)|0,f=f+Math.imul(F,ht)|0,u=u+Math.imul(F,Me)|0,w=w+Math.imul(ie,ft)|0,f=f+Math.imul(ie,Ae)|0,f=f+Math.imul(C,ft)|0,u=u+Math.imul(C,Ae)|0;var Qt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,w=Math.imul(Ye,st),f=Math.imul(Ye,ge),f=f+Math.imul(he,st)|0,u=Math.imul(he,ge),w=w+Math.imul(et,at)|0,f=f+Math.imul(et,_e)|0,f=f+Math.imul(fe,at)|0,u=u+Math.imul(fe,_e)|0,w=w+Math.imul(Ce,lt)|0,f=f+Math.imul(Ce,ve)|0,f=f+Math.imul(ue,lt)|0,u=u+Math.imul(ue,ve)|0,w=w+Math.imul(Ee,ut)|0,f=f+Math.imul(Ee,we)|0,f=f+Math.imul(ce,ut)|0,u=u+Math.imul(ce,we)|0,w=w+Math.imul(ee,ct)|0,f=f+Math.imul(ee,be)|0,f=f+Math.imul(te,ct)|0,u=u+Math.imul(te,be)|0,w=w+Math.imul(Z,dt)|0,f=f+Math.imul(Z,ye)|0,f=f+Math.imul(H,dt)|0,u=u+Math.imul(H,ye)|0,w=w+Math.imul(G,ht)|0,f=f+Math.imul(G,Me)|0,f=f+Math.imul(B,ht)|0,u=u+Math.imul(B,Me)|0,w=w+Math.imul(x,ft)|0,f=f+Math.imul(x,Ae)|0,f=f+Math.imul(F,ft)|0,u=u+Math.imul(F,Ae)|0;var ei=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(Ye,at),f=Math.imul(Ye,_e),f=f+Math.imul(he,at)|0,u=Math.imul(he,_e),w=w+Math.imul(et,lt)|0,f=f+Math.imul(et,ve)|0,f=f+Math.imul(fe,lt)|0,u=u+Math.imul(fe,ve)|0,w=w+Math.imul(Ce,ut)|0,f=f+Math.imul(Ce,we)|0,f=f+Math.imul(ue,ut)|0,u=u+Math.imul(ue,we)|0,w=w+Math.imul(Ee,ct)|0,f=f+Math.imul(Ee,be)|0,f=f+Math.imul(ce,ct)|0,u=u+Math.imul(ce,be)|0,w=w+Math.imul(ee,dt)|0,f=f+Math.imul(ee,ye)|0,f=f+Math.imul(te,dt)|0,u=u+Math.imul(te,ye)|0,w=w+Math.imul(Z,ht)|0,f=f+Math.imul(Z,Me)|0,f=f+Math.imul(H,ht)|0,u=u+Math.imul(H,Me)|0,w=w+Math.imul(G,ft)|0,f=f+Math.imul(G,Ae)|0,f=f+Math.imul(B,ft)|0,u=u+Math.imul(B,Ae)|0;var ti=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(Ye,lt),f=Math.imul(Ye,ve),f=f+Math.imul(he,lt)|0,u=Math.imul(he,ve),w=w+Math.imul(et,ut)|0,f=f+Math.imul(et,we)|0,f=f+Math.imul(fe,ut)|0,u=u+Math.imul(fe,we)|0,w=w+Math.imul(Ce,ct)|0,f=f+Math.imul(Ce,be)|0,f=f+Math.imul(ue,ct)|0,u=u+Math.imul(ue,be)|0,w=w+Math.imul(Ee,dt)|0,f=f+Math.imul(Ee,ye)|0,f=f+Math.imul(ce,dt)|0,u=u+Math.imul(ce,ye)|0,w=w+Math.imul(ee,ht)|0,f=f+Math.imul(ee,Me)|0,f=f+Math.imul(te,ht)|0,u=u+Math.imul(te,Me)|0,w=w+Math.imul(Z,ft)|0,f=f+Math.imul(Z,Ae)|0,f=f+Math.imul(H,ft)|0,u=u+Math.imul(H,Ae)|0;var ii=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(Ye,ut),f=Math.imul(Ye,we),f=f+Math.imul(he,ut)|0,u=Math.imul(he,we),w=w+Math.imul(et,ct)|0,f=f+Math.imul(et,be)|0,f=f+Math.imul(fe,ct)|0,u=u+Math.imul(fe,be)|0,w=w+Math.imul(Ce,dt)|0,f=f+Math.imul(Ce,ye)|0,f=f+Math.imul(ue,dt)|0,u=u+Math.imul(ue,ye)|0,w=w+Math.imul(Ee,ht)|0,f=f+Math.imul(Ee,Me)|0,f=f+Math.imul(ce,ht)|0,u=u+Math.imul(ce,Me)|0,w=w+Math.imul(ee,ft)|0,f=f+Math.imul(ee,Ae)|0,f=f+Math.imul(te,ft)|0,u=u+Math.imul(te,Ae)|0;var ri=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(Ye,ct),f=Math.imul(Ye,be),f=f+Math.imul(he,ct)|0,u=Math.imul(he,be),w=w+Math.imul(et,dt)|0,f=f+Math.imul(et,ye)|0,f=f+Math.imul(fe,dt)|0,u=u+Math.imul(fe,ye)|0,w=w+Math.imul(Ce,ht)|0,f=f+Math.imul(Ce,Me)|0,f=f+Math.imul(ue,ht)|0,u=u+Math.imul(ue,Me)|0,w=w+Math.imul(Ee,ft)|0,f=f+Math.imul(Ee,Ae)|0,f=f+Math.imul(ce,ft)|0,u=u+Math.imul(ce,Ae)|0;var ni=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(Ye,dt),f=Math.imul(Ye,ye),f=f+Math.imul(he,dt)|0,u=Math.imul(he,ye),w=w+Math.imul(et,ht)|0,f=f+Math.imul(et,Me)|0,f=f+Math.imul(fe,ht)|0,u=u+Math.imul(fe,Me)|0,w=w+Math.imul(Ce,ft)|0,f=f+Math.imul(Ce,Ae)|0,f=f+Math.imul(ue,ft)|0,u=u+Math.imul(ue,Ae)|0;var oi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(Ye,ht),f=Math.imul(Ye,Me),f=f+Math.imul(he,ht)|0,u=Math.imul(he,Me),w=w+Math.imul(et,ft)|0,f=f+Math.imul(et,Ae)|0,f=f+Math.imul(fe,ft)|0,u=u+Math.imul(fe,Ae)|0;var si=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(Ye,ft),f=Math.imul(Ye,Ae),f=f+Math.imul(he,ft)|0,u=Math.imul(he,Ae);var ai=(b+w|0)+((f&8191)<<13)|0;return b=(u+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,_[0]=Be,_[1]=Gt,_[2]=Vt,_[3]=Zt,_[4]=Kt,_[5]=Wt,_[6]=zt,_[7]=Xt,_[8]=Jt,_[9]=Yt,_[10]=Qt,_[11]=ei,_[12]=ti,_[13]=ii,_[14]=ri,_[15]=ni,_[16]=oi,_[17]=si,_[18]=ai,b!==0&&(_[19]=b,l.length++),l};Math.imul||(j=W);function K(S,h,o){o.negative=h.negative^S.negative,o.length=S.length+h.length;for(var l=0,d=0,m=0;m<o.length-1;m++){var _=d;d=0;for(var b=l&67108863,w=Math.min(m,h.length-1),f=Math.max(0,m-S.length+1);f<=w;f++){var u=m-f,M=S.words[u]|0,q=h.words[f]|0,$=M*q,z=$&67108863;_=_+($/67108864|0)|0,z=z+b|0,b=z&67108863,_=_+(z>>>26)|0,d+=_>>>26,_&=67108863}o.words[m]=b,l=_,_=d}return l!==0?o.words[m]=l:o.length--,o._strip()}function X(S,h,o){return K(S,h,o)}n.prototype.mulTo=function(h,o){var l,d=this.length+h.length;return this.length===10&&h.length===10?l=j(this,h,o):d<63?l=W(this,h,o):d<1024?l=K(this,h,o):l=X(this,h,o),l};function Q(S,h){this.x=S,this.y=h}Q.prototype.makeRBT=function(h){for(var o=new Array(h),l=n.prototype._countBits(h)-1,d=0;d<h;d++)o[d]=this.revBin(d,l,h);return o},Q.prototype.revBin=function(h,o,l){if(h===0||h===l-1)return h;for(var d=0,m=0;m<o;m++)d|=(h&1)<<o-m-1,h>>=1;return d},Q.prototype.permute=function(h,o,l,d,m,_){for(var b=0;b<_;b++)d[b]=o[h[b]],m[b]=l[h[b]]},Q.prototype.transform=function(h,o,l,d,m,_){this.permute(_,h,o,l,d,m);for(var b=1;b<m;b<<=1)for(var w=b<<1,f=Math.cos(2*Math.PI/w),u=Math.sin(2*Math.PI/w),M=0;M<m;M+=w)for(var q=f,$=u,z=0;z<b;z++){var ie=l[M+z],C=d[M+z],T=l[M+z+b],x=d[M+z+b],F=q*T-$*x;x=q*x+$*T,T=F,l[M+z]=ie+T,d[M+z]=C+x,l[M+z+b]=ie-T,d[M+z+b]=C-x,z!==w&&(F=f*q-u*$,$=f*$+u*q,q=F)}},Q.prototype.guessLen13b=function(h,o){var l=Math.max(o,h)|1,d=l&1,m=0;for(l=l/2|0;l;l=l>>>1)m++;return 1<<m+1+d},Q.prototype.conjugate=function(h,o,l){if(!(l<=1))for(var d=0;d<l/2;d++){var m=h[d];h[d]=h[l-d-1],h[l-d-1]=m,m=o[d],o[d]=-o[l-d-1],o[l-d-1]=-m}},Q.prototype.normalize13b=function(h,o){for(var l=0,d=0;d<o/2;d++){var m=Math.round(h[2*d+1]/o)*8192+Math.round(h[2*d]/o)+l;h[d]=m&67108863,m<67108864?l=0:l=m/67108864|0}return h},Q.prototype.convert13b=function(h,o,l,d){for(var m=0,_=0;_<o;_++)m=m+(h[_]|0),l[2*_]=m&8191,m=m>>>13,l[2*_+1]=m&8191,m=m>>>13;for(_=2*o;_<d;++_)l[_]=0;i(m===0),i((m&-8192)===0)},Q.prototype.stub=function(h){for(var o=new Array(h),l=0;l<h;l++)o[l]=0;return o},Q.prototype.mulp=function(h,o,l){var d=2*this.guessLen13b(h.length,o.length),m=this.makeRBT(d),_=this.stub(d),b=new Array(d),w=new Array(d),f=new Array(d),u=new Array(d),M=new Array(d),q=new Array(d),$=l.words;$.length=d,this.convert13b(h.words,h.length,b,d),this.convert13b(o.words,o.length,u,d),this.transform(b,_,w,f,d,m),this.transform(u,_,M,q,d,m);for(var z=0;z<d;z++){var ie=w[z]*M[z]-f[z]*q[z];f[z]=w[z]*q[z]+f[z]*M[z],w[z]=ie}return this.conjugate(w,f,d),this.transform(w,f,$,_,d,m),this.conjugate($,_,d),this.normalize13b($,d),l.negative=h.negative^o.negative,l.length=h.length+o.length,l._strip()},n.prototype.mul=function(h){var o=new n(null);return o.words=new Array(this.length+h.length),this.mulTo(h,o)},n.prototype.mulf=function(h){var o=new n(null);return o.words=new Array(this.length+h.length),X(this,h,o)},n.prototype.imul=function(h){return this.clone().mulTo(h,this)},n.prototype.imuln=function(h){var o=h<0;o&&(h=-h),i(typeof h=="number"),i(h<67108864);for(var l=0,d=0;d<this.length;d++){var m=(this.words[d]|0)*h,_=(m&67108863)+(l&67108863);l>>=26,l+=m/67108864|0,l+=_>>>26,this.words[d]=_&67108863}return l!==0&&(this.words[d]=l,this.length++),this.length=h===0?1:this.length,o?this.ineg():this},n.prototype.muln=function(h){return this.clone().imuln(h)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(h){var o=P(h);if(o.length===0)return new n(1);for(var l=this,d=0;d<o.length&&o[d]===0;d++,l=l.sqr());if(++d<o.length)for(var m=l.sqr();d<o.length;d++,m=m.sqr())o[d]!==0&&(l=l.mul(m));return l},n.prototype.iushln=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26,d=67108863>>>26-o<<26-o,m;if(o!==0){var _=0;for(m=0;m<this.length;m++){var b=this.words[m]&d,w=(this.words[m]|0)-b<<o;this.words[m]=w|_,_=b>>>26-o}_&&(this.words[m]=_,this.length++)}if(l!==0){for(m=this.length-1;m>=0;m--)this.words[m+l]=this.words[m];for(m=0;m<l;m++)this.words[m]=0;this.length+=l}return this._strip()},n.prototype.ishln=function(h){return i(this.negative===0),this.iushln(h)},n.prototype.iushrn=function(h,o,l){i(typeof h=="number"&&h>=0);var d;o?d=(o-o%26)/26:d=0;var m=h%26,_=Math.min((h-m)/26,this.length),b=67108863^67108863>>>m<<m,w=l;if(d-=_,d=Math.max(0,d),w){for(var f=0;f<_;f++)w.words[f]=this.words[f];w.length=_}if(_!==0)if(this.length>_)for(this.length-=_,f=0;f<this.length;f++)this.words[f]=this.words[f+_];else this.words[0]=0,this.length=1;var u=0;for(f=this.length-1;f>=0&&(u!==0||f>=d);f--){var M=this.words[f]|0;this.words[f]=u<<26-m|M>>>m,u=M&b}return w&&u!==0&&(w.words[w.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(h,o,l){return i(this.negative===0),this.iushrn(h,o,l)},n.prototype.shln=function(h){return this.clone().ishln(h)},n.prototype.ushln=function(h){return this.clone().iushln(h)},n.prototype.shrn=function(h){return this.clone().ishrn(h)},n.prototype.ushrn=function(h){return this.clone().iushrn(h)},n.prototype.testn=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26,d=1<<o;if(this.length<=l)return!1;var m=this.words[l];return!!(m&d)},n.prototype.imaskn=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(o!==0&&l++,this.length=Math.min(l,this.length),o!==0){var d=67108863^67108863>>>o<<o;this.words[this.length-1]&=d}return this._strip()},n.prototype.maskn=function(h){return this.clone().imaskn(h)},n.prototype.iaddn=function(h){return i(typeof h=="number"),i(h<67108864),h<0?this.isubn(-h):this.negative!==0?this.length===1&&(this.words[0]|0)<=h?(this.words[0]=h-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(h),this.negative=1,this):this._iaddn(h)},n.prototype._iaddn=function(h){this.words[0]+=h;for(var o=0;o<this.length&&this.words[o]>=67108864;o++)this.words[o]-=67108864,o===this.length-1?this.words[o+1]=1:this.words[o+1]++;return this.length=Math.max(this.length,o+1),this},n.prototype.isubn=function(h){if(i(typeof h=="number"),i(h<67108864),h<0)return this.iaddn(-h);if(this.negative!==0)return this.negative=0,this.iaddn(h),this.negative=1,this;if(this.words[0]-=h,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var o=0;o<this.length&&this.words[o]<0;o++)this.words[o]+=67108864,this.words[o+1]-=1;return this._strip()},n.prototype.addn=function(h){return this.clone().iaddn(h)},n.prototype.subn=function(h){return this.clone().isubn(h)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(h,o,l){var d=h.length+l,m;this._expand(d);var _,b=0;for(m=0;m<h.length;m++){_=(this.words[m+l]|0)+b;var w=(h.words[m]|0)*o;_-=w&67108863,b=(_>>26)-(w/67108864|0),this.words[m+l]=_&67108863}for(;m<this.length-l;m++)_=(this.words[m+l]|0)+b,b=_>>26,this.words[m+l]=_&67108863;if(b===0)return this._strip();for(i(b===-1),b=0,m=0;m<this.length;m++)_=-(this.words[m]|0)+b,b=_>>26,this.words[m]=_&67108863;return this.negative=1,this._strip()},n.prototype._wordDiv=function(h,o){var l=this.length-h.length,d=this.clone(),m=h,_=m.words[m.length-1]|0,b=this._countBits(_);l=26-b,l!==0&&(m=m.ushln(l),d.iushln(l),_=m.words[m.length-1]|0);var w=d.length-m.length,f;if(o!=="mod"){f=new n(null),f.length=w+1,f.words=new Array(f.length);for(var u=0;u<f.length;u++)f.words[u]=0}var M=d.clone()._ishlnsubmul(m,1,w);M.negative===0&&(d=M,f&&(f.words[w]=1));for(var q=w-1;q>=0;q--){var $=(d.words[m.length+q]|0)*67108864+(d.words[m.length+q-1]|0);for($=Math.min($/_|0,67108863),d._ishlnsubmul(m,$,q);d.negative!==0;)$--,d.negative=0,d._ishlnsubmul(m,1,q),d.isZero()||(d.negative^=1);f&&(f.words[q]=$)}return f&&f._strip(),d._strip(),o!=="div"&&l!==0&&d.iushrn(l),{div:f||null,mod:d}},n.prototype.divmod=function(h,o,l){if(i(!h.isZero()),this.isZero())return{div:new n(0),mod:new n(0)};var d,m,_;return this.negative!==0&&h.negative===0?(_=this.neg().divmod(h,o),o!=="mod"&&(d=_.div.neg()),o!=="div"&&(m=_.mod.neg(),l&&m.negative!==0&&m.iadd(h)),{div:d,mod:m}):this.negative===0&&h.negative!==0?(_=this.divmod(h.neg(),o),o!=="mod"&&(d=_.div.neg()),{div:d,mod:_.mod}):(this.negative&h.negative)!==0?(_=this.neg().divmod(h.neg(),o),o!=="div"&&(m=_.mod.neg(),l&&m.negative!==0&&m.isub(h)),{div:_.div,mod:m}):h.length>this.length||this.cmp(h)<0?{div:new n(0),mod:this}:h.length===1?o==="div"?{div:this.divn(h.words[0]),mod:null}:o==="mod"?{div:null,mod:new n(this.modrn(h.words[0]))}:{div:this.divn(h.words[0]),mod:new n(this.modrn(h.words[0]))}:this._wordDiv(h,o)},n.prototype.div=function(h){return this.divmod(h,"div",!1).div},n.prototype.mod=function(h){return this.divmod(h,"mod",!1).mod},n.prototype.umod=function(h){return this.divmod(h,"mod",!0).mod},n.prototype.divRound=function(h){var o=this.divmod(h);if(o.mod.isZero())return o.div;var l=o.div.negative!==0?o.mod.isub(h):o.mod,d=h.ushrn(1),m=h.andln(1),_=l.cmp(d);return _<0||m===1&&_===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},n.prototype.modrn=function(h){var o=h<0;o&&(h=-h),i(h<=67108863);for(var l=(1<<26)%h,d=0,m=this.length-1;m>=0;m--)d=(l*d+(this.words[m]|0))%h;return o?-d:d},n.prototype.modn=function(h){return this.modrn(h)},n.prototype.idivn=function(h){var o=h<0;o&&(h=-h),i(h<=67108863);for(var l=0,d=this.length-1;d>=0;d--){var m=(this.words[d]|0)+l*67108864;this.words[d]=m/h|0,l=m%h}return this._strip(),o?this.ineg():this},n.prototype.divn=function(h){return this.clone().idivn(h)},n.prototype.egcd=function(h){i(h.negative===0),i(!h.isZero());var o=this,l=h.clone();o.negative!==0?o=o.umod(h):o=o.clone();for(var d=new n(1),m=new n(0),_=new n(0),b=new n(1),w=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++w;for(var f=l.clone(),u=o.clone();!o.isZero();){for(var M=0,q=1;(o.words[0]&q)===0&&M<26;++M,q<<=1);if(M>0)for(o.iushrn(M);M-- >0;)(d.isOdd()||m.isOdd())&&(d.iadd(f),m.isub(u)),d.iushrn(1),m.iushrn(1);for(var $=0,z=1;(l.words[0]&z)===0&&$<26;++$,z<<=1);if($>0)for(l.iushrn($);$-- >0;)(_.isOdd()||b.isOdd())&&(_.iadd(f),b.isub(u)),_.iushrn(1),b.iushrn(1);o.cmp(l)>=0?(o.isub(l),d.isub(_),m.isub(b)):(l.isub(o),_.isub(d),b.isub(m))}return{a:_,b,gcd:l.iushln(w)}},n.prototype._invmp=function(h){i(h.negative===0),i(!h.isZero());var o=this,l=h.clone();o.negative!==0?o=o.umod(h):o=o.clone();for(var d=new n(1),m=new n(0),_=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var b=0,w=1;(o.words[0]&w)===0&&b<26;++b,w<<=1);if(b>0)for(o.iushrn(b);b-- >0;)d.isOdd()&&d.iadd(_),d.iushrn(1);for(var f=0,u=1;(l.words[0]&u)===0&&f<26;++f,u<<=1);if(f>0)for(l.iushrn(f);f-- >0;)m.isOdd()&&m.iadd(_),m.iushrn(1);o.cmp(l)>=0?(o.isub(l),d.isub(m)):(l.isub(o),m.isub(d))}var M;return o.cmpn(1)===0?M=d:M=m,M.cmpn(0)<0&&M.iadd(h),M},n.prototype.gcd=function(h){if(this.isZero())return h.abs();if(h.isZero())return this.abs();var o=this.clone(),l=h.clone();o.negative=0,l.negative=0;for(var d=0;o.isEven()&&l.isEven();d++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var m=o.cmp(l);if(m<0){var _=o;o=l,l=_}else if(m===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(d)},n.prototype.invm=function(h){return this.egcd(h).a.umod(h)},n.prototype.isEven=function(){return(this.words[0]&1)===0},n.prototype.isOdd=function(){return(this.words[0]&1)===1},n.prototype.andln=function(h){return this.words[0]&h},n.prototype.bincn=function(h){i(typeof h=="number");var o=h%26,l=(h-o)/26,d=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=d,this;for(var m=d,_=l;m!==0&&_<this.length;_++){var b=this.words[_]|0;b+=m,m=b>>>26,b&=67108863,this.words[_]=b}return m!==0&&(this.words[_]=m,this.length++),this},n.prototype.isZero=function(){return this.length===1&&this.words[0]===0},n.prototype.cmpn=function(h){var o=h<0;if(this.negative!==0&&!o)return-1;if(this.negative===0&&o)return 1;this._strip();var l;if(this.length>1)l=1;else{o&&(h=-h),i(h<=67108863,"Number is too big");var d=this.words[0]|0;l=d===h?0:d<h?-1:1}return this.negative!==0?-l|0:l},n.prototype.cmp=function(h){if(this.negative!==0&&h.negative===0)return-1;if(this.negative===0&&h.negative!==0)return 1;var o=this.ucmp(h);return this.negative!==0?-o|0:o},n.prototype.ucmp=function(h){if(this.length>h.length)return 1;if(this.length<h.length)return-1;for(var o=0,l=this.length-1;l>=0;l--){var d=this.words[l]|0,m=h.words[l]|0;if(d!==m){d<m?o=-1:d>m&&(o=1);break}}return o},n.prototype.gtn=function(h){return this.cmpn(h)===1},n.prototype.gt=function(h){return this.cmp(h)===1},n.prototype.gten=function(h){return this.cmpn(h)>=0},n.prototype.gte=function(h){return this.cmp(h)>=0},n.prototype.ltn=function(h){return this.cmpn(h)===-1},n.prototype.lt=function(h){return this.cmp(h)===-1},n.prototype.lten=function(h){return this.cmpn(h)<=0},n.prototype.lte=function(h){return this.cmp(h)<=0},n.prototype.eqn=function(h){return this.cmpn(h)===0},n.prototype.eq=function(h){return this.cmp(h)===0},n.red=function(h){return new R(h)},n.prototype.toRed=function(h){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),h.convertTo(this)._forceRed(h)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(h){return this.red=h,this},n.prototype.forceRed=function(h){return i(!this.red,"Already a number in reduction context"),this._forceRed(h)},n.prototype.redAdd=function(h){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,h)},n.prototype.redIAdd=function(h){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,h)},n.prototype.redSub=function(h){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,h)},n.prototype.redISub=function(h){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,h)},n.prototype.redShl=function(h){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,h)},n.prototype.redMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.mul(this,h)},n.prototype.redIMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.imul(this,h)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(h){return i(this.red&&!h.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,h)};var se={k256:null,p224:null,p192:null,p25519:null};function Y(S,h){this.name=S,this.p=new n(h,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Y.prototype._tmp=function(){var h=new n(null);return h.words=new Array(Math.ceil(this.n/13)),h},Y.prototype.ireduce=function(h){var o=h,l;do this.split(o,this.tmp),o=this.imulK(o),o=o.iadd(this.tmp),l=o.bitLength();while(l>this.n);var d=l<this.n?-1:o.ucmp(this.p);return d===0?(o.words[0]=0,o.length=1):d>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},Y.prototype.split=function(h,o){h.iushrn(this.n,0,o)},Y.prototype.imulK=function(h){return h.imul(this.k)};function ae(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(ae,Y),ae.prototype.split=function(h,o){for(var l=4194303,d=Math.min(h.length,9),m=0;m<d;m++)o.words[m]=h.words[m];if(o.length=d,h.length<=9){h.words[0]=0,h.length=1;return}var _=h.words[9];for(o.words[o.length++]=_&l,m=10;m<h.length;m++){var b=h.words[m]|0;h.words[m-10]=(b&l)<<4|_>>>22,_=b}_>>>=22,h.words[m-10]=_,_===0&&h.length>10?h.length-=10:h.length-=9},ae.prototype.imulK=function(h){h.words[h.length]=0,h.words[h.length+1]=0,h.length+=2;for(var o=0,l=0;l<h.length;l++){var d=h.words[l]|0;o+=d*977,h.words[l]=o&67108863,o=d*64+(o/67108864|0)}return h.words[h.length-1]===0&&(h.length--,h.words[h.length-1]===0&&h.length--),h};function E(){Y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(E,Y);function I(){Y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(I,Y);function O(){Y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(O,Y),O.prototype.imulK=function(h){for(var o=0,l=0;l<h.length;l++){var d=(h.words[l]|0)*19+o,m=d&67108863;d>>>=26,h.words[l]=m,o=d}return o!==0&&(h.words[h.length++]=o),h},n._prime=function(h){if(se[h])return se[h];var o;if(h==="k256")o=new ae;else if(h==="p224")o=new E;else if(h==="p192")o=new I;else if(h==="p25519")o=new O;else throw new Error("Unknown prime "+h);return se[h]=o,o};function R(S){if(typeof S=="string"){var h=n._prime(S);this.m=h.p,this.prime=h}else i(S.gtn(1),"modulus must be greater than 1"),this.m=S,this.prime=null}R.prototype._verify1=function(h){i(h.negative===0,"red works only with positives"),i(h.red,"red works only with red numbers")},R.prototype._verify2=function(h,o){i((h.negative|o.negative)===0,"red works only with positives"),i(h.red&&h.red===o.red,"red works only with red numbers")},R.prototype.imod=function(h){return this.prime?this.prime.ireduce(h)._forceRed(this):(g(h,h.umod(this.m)._forceRed(this)),h)},R.prototype.neg=function(h){return h.isZero()?h.clone():this.m.sub(h)._forceRed(this)},R.prototype.add=function(h,o){this._verify2(h,o);var l=h.add(o);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},R.prototype.iadd=function(h,o){this._verify2(h,o);var l=h.iadd(o);return l.cmp(this.m)>=0&&l.isub(this.m),l},R.prototype.sub=function(h,o){this._verify2(h,o);var l=h.sub(o);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},R.prototype.isub=function(h,o){this._verify2(h,o);var l=h.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},R.prototype.shl=function(h,o){return this._verify1(h),this.imod(h.ushln(o))},R.prototype.imul=function(h,o){return this._verify2(h,o),this.imod(h.imul(o))},R.prototype.mul=function(h,o){return this._verify2(h,o),this.imod(h.mul(o))},R.prototype.isqr=function(h){return this.imul(h,h.clone())},R.prototype.sqr=function(h){return this.mul(h,h)},R.prototype.sqrt=function(h){if(h.isZero())return h.clone();var o=this.m.andln(3);if(i(o%2===1),o===3){var l=this.m.add(new n(1)).iushrn(2);return this.pow(h,l)}for(var d=this.m.subn(1),m=0;!d.isZero()&&d.andln(1)===0;)m++,d.iushrn(1);i(!d.isZero());var _=new n(1).toRed(this),b=_.redNeg(),w=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new n(2*f*f).toRed(this);this.pow(f,w).cmp(b)!==0;)f.redIAdd(b);for(var u=this.pow(f,d),M=this.pow(h,d.addn(1).iushrn(1)),q=this.pow(h,d),$=m;q.cmp(_)!==0;){for(var z=q,ie=0;z.cmp(_)!==0;ie++)z=z.redSqr();i(ie<$);var C=this.pow(u,new n(1).iushln($-ie-1));M=M.redMul(C),u=C.redSqr(),q=q.redMul(u),$=ie}return M},R.prototype.invm=function(h){var o=h._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},R.prototype.pow=function(h,o){if(o.isZero())return new n(1).toRed(this);if(o.cmpn(1)===0)return h.clone();var l=4,d=new Array(1<<l);d[0]=new n(1).toRed(this),d[1]=h;for(var m=2;m<d.length;m++)d[m]=this.mul(d[m-1],h);var _=d[0],b=0,w=0,f=o.bitLength()%26;for(f===0&&(f=26),m=o.length-1;m>=0;m--){for(var u=o.words[m],M=f-1;M>=0;M--){var q=u>>M&1;if(_!==d[0]&&(_=this.sqr(_)),q===0&&b===0){w=0;continue}b<<=1,b|=q,w++,!(w!==l&&(m!==0||M!==0))&&(_=this.mul(_,d[b]),w=0,b=0)}f=26}return _},R.prototype.convertTo=function(h){var o=h.umod(this.m);return o===h?o.clone():o},R.prototype.convertFrom=function(h){var o=h.clone();return o.red=null,o},n.mont=function(h){return new N(h)};function N(S){R.call(this,S),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new n(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(N,R),N.prototype.convertTo=function(h){return this.imod(h.ushln(this.shift))},N.prototype.convertFrom=function(h){var o=this.imod(h.mul(this.rinv));return o.red=null,o},N.prototype.imul=function(h,o){if(h.isZero()||o.isZero())return h.words[0]=0,h.length=1,h;var l=h.imul(o),d=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(d).iushrn(this.shift),_=m;return m.cmp(this.m)>=0?_=m.isub(this.m):m.cmpn(0)<0&&(_=m.iadd(this.m)),_._forceRed(this)},N.prototype.mul=function(h,o){if(h.isZero()||o.isZero())return new n(0)._forceRed(this);var l=h.mul(o),d=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(d).iushrn(this.shift),_=m;return m.cmp(this.m)>=0?_=m.isub(this.m):m.cmpn(0)<0&&(_=m.iadd(this.m)),_._forceRed(this)},N.prototype.invm=function(h){var o=this.imod(h._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof Io>"u"||Io,wa)});var Po=dr((Ia,wn)=>{"use strict";(function(e){"use strict";var t,i=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,r=Math.ceil,n=Math.floor,s="[BigNumber Error] ",a=s+"Number primitive has more than 15 significant digits: ",c=1e14,p=14,g=9007199254740991,v=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],y=1e7,A=1e9;function k(se){var Y,ae,E,I=u.prototype={constructor:u,toString:null,valueOf:null},O=new u(1),R=20,N=4,S=-7,h=21,o=-1e7,l=1e7,d=!1,m=1,_=0,b={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},w="0123456789abcdefghijklmnopqrstuvwxyz",f=!0;function u(C,T){var x,F,L,G,B,D,Z,H,V=this;if(!(V instanceof u))return new u(C,T);if(T==null){if(C&&C._isBigNumber===!0){V.s=C.s,!C.c||C.e>l?V.c=V.e=null:C.e<o?V.c=[V.e=0]:(V.e=C.e,V.c=C.c.slice());return}if((D=typeof C=="number")&&C*0==0){if(V.s=1/C<0?(C=-C,-1):1,C===~~C){for(G=0,B=C;B>=10;B/=10,G++);G>l?V.c=V.e=null:(V.e=G,V.c=[C]);return}H=String(C)}else{if(!i.test(H=String(C)))return E(V,H,D);V.s=H.charCodeAt(0)==45?(H=H.slice(1),-1):1}(G=H.indexOf("."))>-1&&(H=H.replace(".","")),(B=H.search(/e/i))>0?(G<0&&(G=B),G+=+H.slice(B+1),H=H.substring(0,B)):G<0&&(G=H.length)}else{if(j(T,2,w.length,"Base"),T==10&&f)return V=new u(C),z(V,R+V.e+1,N);if(H=String(C),D=typeof C=="number"){if(C*0!=0)return E(V,H,D,T);if(V.s=1/C<0?(H=H.slice(1),-1):1,u.DEBUG&&H.replace(/^0\.0*|\./,"").length>15)throw Error(a+C)}else V.s=H.charCodeAt(0)===45?(H=H.slice(1),-1):1;for(x=w.slice(0,T),G=B=0,Z=H.length;B<Z;B++)if(x.indexOf(F=H.charAt(B))<0){if(F=="."){if(B>G){G=Z;continue}}else if(!L&&(H==H.toUpperCase()&&(H=H.toLowerCase())||H==H.toLowerCase()&&(H=H.toUpperCase()))){L=!0,B=-1,G=0;continue}return E(V,String(C),D,T)}D=!1,H=ae(H,T,10,V.s),(G=H.indexOf("."))>-1?H=H.replace(".",""):G=H.length}for(B=0;H.charCodeAt(B)===48;B++);for(Z=H.length;H.charCodeAt(--Z)===48;);if(H=H.slice(B,++Z)){if(Z-=B,D&&u.DEBUG&&Z>15&&(C>g||C!==n(C)))throw Error(a+V.s*C);if((G=G-B-1)>l)V.c=V.e=null;else if(G<o)V.c=[V.e=0];else{if(V.e=G,V.c=[],B=(G+1)%p,G<0&&(B+=p),B<Z){for(B&&V.c.push(+H.slice(0,B)),Z-=p;B<Z;)V.c.push(+H.slice(B,B+=p));B=p-(H=H.slice(B)).length}else B-=Z;for(;B--;H+="0");V.c.push(+H)}}else V.c=[V.e=0]}u.clone=k,u.ROUND_UP=0,u.ROUND_DOWN=1,u.ROUND_CEIL=2,u.ROUND_FLOOR=3,u.ROUND_HALF_UP=4,u.ROUND_HALF_DOWN=5,u.ROUND_HALF_EVEN=6,u.ROUND_HALF_CEIL=7,u.ROUND_HALF_FLOOR=8,u.EUCLID=9,u.config=u.set=function(C){var T,x;if(C!=null)if(typeof C=="object"){if(C.hasOwnProperty(T="DECIMAL_PLACES")&&(x=C[T],j(x,0,A,T),R=x),C.hasOwnProperty(T="ROUNDING_MODE")&&(x=C[T],j(x,0,8,T),N=x),C.hasOwnProperty(T="EXPONENTIAL_AT")&&(x=C[T],x&&x.pop?(j(x[0],-A,0,T),j(x[1],0,A,T),S=x[0],h=x[1]):(j(x,-A,A,T),S=-(h=x<0?-x:x))),C.hasOwnProperty(T="RANGE"))if(x=C[T],x&&x.pop)j(x[0],-A,-1,T),j(x[1],1,A,T),o=x[0],l=x[1];else if(j(x,-A,A,T),x)o=-(l=x<0?-x:x);else throw Error(s+T+" cannot be zero: "+x);if(C.hasOwnProperty(T="CRYPTO"))if(x=C[T],x===!!x)if(x)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))d=x;else throw d=!x,Error(s+"crypto unavailable");else d=x;else throw Error(s+T+" not true or false: "+x);if(C.hasOwnProperty(T="MODULO_MODE")&&(x=C[T],j(x,0,9,T),m=x),C.hasOwnProperty(T="POW_PRECISION")&&(x=C[T],j(x,0,A,T),_=x),C.hasOwnProperty(T="FORMAT"))if(x=C[T],typeof x=="object")b=x;else throw Error(s+T+" not an object: "+x);if(C.hasOwnProperty(T="ALPHABET"))if(x=C[T],typeof x=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(x))f=x.slice(0,10)=="0123456789",w=x;else throw Error(s+T+" invalid: "+x)}else throw Error(s+"Object expected: "+C);return{DECIMAL_PLACES:R,ROUNDING_MODE:N,EXPONENTIAL_AT:[S,h],RANGE:[o,l],CRYPTO:d,MODULO_MODE:m,POW_PRECISION:_,FORMAT:b,ALPHABET:w}},u.isBigNumber=function(C){if(!C||C._isBigNumber!==!0)return!1;if(!u.DEBUG)return!0;var T,x,F=C.c,L=C.e,G=C.s;e:if({}.toString.call(F)=="[object Array]"){if((G===1||G===-1)&&L>=-A&&L<=A&&L===n(L)){if(F[0]===0){if(L===0&&F.length===1)return!0;break e}if(T=(L+1)%p,T<1&&(T+=p),String(F[0]).length==T){for(T=0;T<F.length;T++)if(x=F[T],x<0||x>=c||x!==n(x))break e;if(x!==0)return!0}}}else if(F===null&&L===null&&(G===null||G===1||G===-1))return!0;throw Error(s+"Invalid BigNumber: "+C)},u.maximum=u.max=function(){return q(arguments,-1)},u.minimum=u.min=function(){return q(arguments,1)},u.random=(function(){var C=9007199254740992,T=Math.random()*C&2097151?function(){return n(Math.random()*C)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(x){var F,L,G,B,D,Z=0,H=[],V=new u(O);if(x==null?x=R:j(x,0,A),B=r(x/p),d)if(crypto.getRandomValues){for(F=crypto.getRandomValues(new Uint32Array(B*=2));Z<B;)D=F[Z]*131072+(F[Z+1]>>>11),D>=9e15?(L=crypto.getRandomValues(new Uint32Array(2)),F[Z]=L[0],F[Z+1]=L[1]):(H.push(D%1e14),Z+=2);Z=B/2}else if(crypto.randomBytes){for(F=crypto.randomBytes(B*=7);Z<B;)D=(F[Z]&31)*281474976710656+F[Z+1]*1099511627776+F[Z+2]*4294967296+F[Z+3]*16777216+(F[Z+4]<<16)+(F[Z+5]<<8)+F[Z+6],D>=9e15?crypto.randomBytes(7).copy(F,Z):(H.push(D%1e14),Z+=7);Z=B/7}else throw d=!1,Error(s+"crypto unavailable");if(!d)for(;Z<B;)D=T(),D<9e15&&(H[Z++]=D%1e14);for(B=H[--Z],x%=p,B&&x&&(D=v[p-x],H[Z]=n(B/D)*D);H[Z]===0;H.pop(),Z--);if(Z<0)H=[G=0];else{for(G=-1;H[0]===0;H.splice(0,1),G-=p);for(Z=1,D=H[0];D>=10;D/=10,Z++);Z<p&&(G-=p-Z)}return V.e=G,V.c=H,V}})(),u.sum=function(){for(var C=1,T=arguments,x=new u(T[0]);C<T.length;)x=x.plus(T[C++]);return x},ae=(function(){var C="0123456789";function T(x,F,L,G){for(var B,D=[0],Z,H=0,V=x.length;H<V;){for(Z=D.length;Z--;D[Z]*=F);for(D[0]+=G.indexOf(x.charAt(H++)),B=0;B<D.length;B++)D[B]>L-1&&(D[B+1]==null&&(D[B+1]=0),D[B+1]+=D[B]/L|0,D[B]%=L)}return D.reverse()}return function(x,F,L,G,B){var D,Z,H,V,ee,te,le,Ee,ce=x.indexOf("."),pe=R,Ce=N;for(ce>=0&&(V=_,_=0,x=x.replace(".",""),Ee=new u(F),te=Ee.pow(x.length-ce),_=V,Ee.c=T(Q(P(te.c),te.e,"0"),10,L,C),Ee.e=Ee.c.length),le=T(x,F,L,B?(D=w,C):(D=C,w)),H=V=le.length;le[--V]==0;le.pop());if(!le[0])return D.charAt(0);if(ce<0?--H:(te.c=le,te.e=H,te.s=G,te=Y(te,Ee,pe,Ce,L),le=te.c,ee=te.r,H=te.e),Z=H+pe+1,ce=le[Z],V=L/2,ee=ee||Z<0||le[Z+1]!=null,ee=Ce<4?(ce!=null||ee)&&(Ce==0||Ce==(te.s<0?3:2)):ce>V||ce==V&&(Ce==4||ee||Ce==6&&le[Z-1]&1||Ce==(te.s<0?8:7)),Z<1||!le[0])x=ee?Q(D.charAt(1),-pe,D.charAt(0)):D.charAt(0);else{if(le.length=Z,ee)for(--L;++le[--Z]>L;)le[Z]=0,Z||(++H,le=[1].concat(le));for(V=le.length;!le[--V];);for(ce=0,x="";ce<=V;x+=D.charAt(le[ce++]));x=Q(x,H,D.charAt(0))}return x}})(),Y=(function(){function C(F,L,G){var B,D,Z,H,V=0,ee=F.length,te=L%y,le=L/y|0;for(F=F.slice();ee--;)Z=F[ee]%y,H=F[ee]/y|0,B=le*Z+H*te,D=te*Z+B%y*y+V,V=(D/G|0)+(B/y|0)+le*H,F[ee]=D%G;return V&&(F=[V].concat(F)),F}function T(F,L,G,B){var D,Z;if(G!=B)Z=G>B?1:-1;else for(D=Z=0;D<G;D++)if(F[D]!=L[D]){Z=F[D]>L[D]?1:-1;break}return Z}function x(F,L,G,B){for(var D=0;G--;)F[G]-=D,D=F[G]<L[G]?1:0,F[G]=D*B+F[G]-L[G];for(;!F[0]&&F.length>1;F.splice(0,1));}return function(F,L,G,B,D){var Z,H,V,ee,te,le,Ee,ce,pe,Ce,ue,Se,et,fe,Re,Ye,he,Ie=F.s==L.s?1:-1,ze=F.c,de=L.c;if(!ze||!ze[0]||!de||!de[0])return new u(!F.s||!L.s||(ze?de&&ze[0]==de[0]:!de)?NaN:ze&&ze[0]==0||!de?Ie*0:Ie/0);for(ce=new u(Ie),pe=ce.c=[],H=F.e-L.e,Ie=G+H+1,D||(D=c,H=U(F.e/p)-U(L.e/p),Ie=Ie/p|0),V=0;de[V]==(ze[V]||0);V++);if(de[V]>(ze[V]||0)&&H--,Ie<0)pe.push(1),ee=!0;else{for(fe=ze.length,Ye=de.length,V=0,Ie+=2,te=n(D/(de[0]+1)),te>1&&(de=C(de,te,D),ze=C(ze,te,D),Ye=de.length,fe=ze.length),et=Ye,Ce=ze.slice(0,Ye),ue=Ce.length;ue<Ye;Ce[ue++]=0);he=de.slice(),he=[0].concat(he),Re=de[0],de[1]>=D/2&&Re++;do{if(te=0,Z=T(de,Ce,Ye,ue),Z<0){if(Se=Ce[0],Ye!=ue&&(Se=Se*D+(Ce[1]||0)),te=n(Se/Re),te>1)for(te>=D&&(te=D-1),le=C(de,te,D),Ee=le.length,ue=Ce.length;T(le,Ce,Ee,ue)==1;)te--,x(le,Ye<Ee?he:de,Ee,D),Ee=le.length,Z=1;else te==0&&(Z=te=1),le=de.slice(),Ee=le.length;if(Ee<ue&&(le=[0].concat(le)),x(Ce,le,ue,D),ue=Ce.length,Z==-1)for(;T(de,Ce,Ye,ue)<1;)te++,x(Ce,Ye<ue?he:de,ue,D),ue=Ce.length}else Z===0&&(te++,Ce=[0]);pe[V++]=te,Ce[0]?Ce[ue++]=ze[et]||0:(Ce=[ze[et]],ue=1)}while((et++<fe||Ce[0]!=null)&&Ie--);ee=Ce[0]!=null,pe[0]||pe.splice(0,1)}if(D==c){for(V=1,Ie=pe[0];Ie>=10;Ie/=10,V++);z(ce,G+(ce.e=V+H*p-1)+1,B,ee)}else ce.e=H,ce.r=+ee;return ce}})();function M(C,T,x,F){var L,G,B,D,Z;if(x==null?x=N:j(x,0,8),!C.c)return C.toString();if(L=C.c[0],B=C.e,T==null)Z=P(C.c),Z=F==1||F==2&&(B<=S||B>=h)?X(Z,B):Q(Z,B,"0");else if(C=z(new u(C),T,x),G=C.e,Z=P(C.c),D=Z.length,F==1||F==2&&(T<=G||G<=S)){for(;D<T;Z+="0",D++);Z=X(Z,G)}else if(T-=B+(F===2&&G>B),Z=Q(Z,G,"0"),G+1>D){if(--T>0)for(Z+=".";T--;Z+="0");}else if(T+=G-D,T>0)for(G+1==D&&(Z+=".");T--;Z+="0");return C.s<0&&L?"-"+Z:Z}function q(C,T){for(var x,F,L=1,G=new u(C[0]);L<C.length;L++)F=new u(C[L]),(!F.s||(x=W(G,F))===T||x===0&&G.s===T)&&(G=F);return G}function $(C,T,x){for(var F=1,L=T.length;!T[--L];T.pop());for(L=T[0];L>=10;L/=10,F++);return(x=F+x*p-1)>l?C.c=C.e=null:x<o?C.c=[C.e=0]:(C.e=x,C.c=T),C}E=(function(){var C=/^(-?)0([xbo])(?=\w[\w.]*$)/i,T=/^([^.]+)\.$/,x=/^\.([^.]+)$/,F=/^-?(Infinity|NaN)$/,L=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(G,B,D,Z){var H,V=D?B:B.replace(L,"");if(F.test(V))G.s=isNaN(V)?null:V<0?-1:1;else{if(!D&&(V=V.replace(C,function(ee,te,le){return H=(le=le.toLowerCase())=="x"?16:le=="b"?2:8,!Z||Z==H?te:ee}),Z&&(H=Z,V=V.replace(T,"$1").replace(x,"0.$1")),B!=V))return new u(V,H);if(u.DEBUG)throw Error(s+"Not a"+(Z?" base "+Z:"")+" number: "+B);G.s=null}G.c=G.e=null}})();function z(C,T,x,F){var L,G,B,D,Z,H,V,ee=C.c,te=v;if(ee){e:{for(L=1,D=ee[0];D>=10;D/=10,L++);if(G=T-L,G<0)G+=p,B=T,Z=ee[H=0],V=n(Z/te[L-B-1]%10);else if(H=r((G+1)/p),H>=ee.length)if(F){for(;ee.length<=H;ee.push(0));Z=V=0,L=1,G%=p,B=G-p+1}else break e;else{for(Z=D=ee[H],L=1;D>=10;D/=10,L++);G%=p,B=G-p+L,V=B<0?0:n(Z/te[L-B-1]%10)}if(F=F||T<0||ee[H+1]!=null||(B<0?Z:Z%te[L-B-1]),F=x<4?(V||F)&&(x==0||x==(C.s<0?3:2)):V>5||V==5&&(x==4||F||x==6&&(G>0?B>0?Z/te[L-B]:0:ee[H-1])%10&1||x==(C.s<0?8:7)),T<1||!ee[0])return ee.length=0,F?(T-=C.e+1,ee[0]=te[(p-T%p)%p],C.e=-T||0):ee[0]=C.e=0,C;if(G==0?(ee.length=H,D=1,H--):(ee.length=H+1,D=te[p-G],ee[H]=B>0?n(Z/te[L-B]%te[B])*D:0),F)for(;;)if(H==0){for(G=1,B=ee[0];B>=10;B/=10,G++);for(B=ee[0]+=D,D=1;B>=10;B/=10,D++);G!=D&&(C.e++,ee[0]==c&&(ee[0]=1));break}else{if(ee[H]+=D,ee[H]!=c)break;ee[H--]=0,D=1}for(G=ee.length;ee[--G]===0;ee.pop());}C.e>l?C.c=C.e=null:C.e<o&&(C.c=[C.e=0])}return C}function ie(C){var T,x=C.e;return x===null?C.toString():(T=P(C.c),T=x<=S||x>=h?X(T,x):Q(T,x,"0"),C.s<0?"-"+T:T)}return I.absoluteValue=I.abs=function(){var C=new u(this);return C.s<0&&(C.s=1),C},I.comparedTo=function(C,T){return W(this,new u(C,T))},I.decimalPlaces=I.dp=function(C,T){var x,F,L,G=this;if(C!=null)return j(C,0,A),T==null?T=N:j(T,0,8),z(new u(G),C+G.e+1,T);if(!(x=G.c))return null;if(F=((L=x.length-1)-U(this.e/p))*p,L=x[L])for(;L%10==0;L/=10,F--);return F<0&&(F=0),F},I.dividedBy=I.div=function(C,T){return Y(this,new u(C,T),R,N)},I.dividedToIntegerBy=I.idiv=function(C,T){return Y(this,new u(C,T),0,1)},I.exponentiatedBy=I.pow=function(C,T){var x,F,L,G,B,D,Z,H,V,ee=this;if(C=new u(C),C.c&&!C.isInteger())throw Error(s+"Exponent not an integer: "+ie(C));if(T!=null&&(T=new u(T)),D=C.e>14,!ee.c||!ee.c[0]||ee.c[0]==1&&!ee.e&&ee.c.length==1||!C.c||!C.c[0])return V=new u(Math.pow(+ie(ee),D?C.s*(2-K(C)):+ie(C))),T?V.mod(T):V;if(Z=C.s<0,T){if(T.c?!T.c[0]:!T.s)return new u(NaN);F=!Z&&ee.isInteger()&&T.isInteger(),F&&(ee=ee.mod(T))}else{if(C.e>9&&(ee.e>0||ee.e<-1||(ee.e==0?ee.c[0]>1||D&&ee.c[1]>=24e7:ee.c[0]<8e13||D&&ee.c[0]<=9999975e7)))return G=ee.s<0&&K(C)?-0:0,ee.e>-1&&(G=1/G),new u(Z?1/G:G);_&&(G=r(_/p+2))}for(D?(x=new u(.5),Z&&(C.s=1),H=K(C)):(L=Math.abs(+ie(C)),H=L%2),V=new u(O);;){if(H){if(V=V.times(ee),!V.c)break;G?V.c.length>G&&(V.c.length=G):F&&(V=V.mod(T))}if(L){if(L=n(L/2),L===0)break;H=L%2}else if(C=C.times(x),z(C,C.e+1,1),C.e>14)H=K(C);else{if(L=+ie(C),L===0)break;H=L%2}ee=ee.times(ee),G?ee.c&&ee.c.length>G&&(ee.c.length=G):F&&(ee=ee.mod(T))}return F?V:(Z&&(V=O.div(V)),T?V.mod(T):G?z(V,_,N,B):V)},I.integerValue=function(C){var T=new u(this);return C==null?C=N:j(C,0,8),z(T,T.e+1,C)},I.isEqualTo=I.eq=function(C,T){return W(this,new u(C,T))===0},I.isFinite=function(){return!!this.c},I.isGreaterThan=I.gt=function(C,T){return W(this,new u(C,T))>0},I.isGreaterThanOrEqualTo=I.gte=function(C,T){return(T=W(this,new u(C,T)))===1||T===0},I.isInteger=function(){return!!this.c&&U(this.e/p)>this.c.length-2},I.isLessThan=I.lt=function(C,T){return W(this,new u(C,T))<0},I.isLessThanOrEqualTo=I.lte=function(C,T){return(T=W(this,new u(C,T)))===-1||T===0},I.isNaN=function(){return!this.s},I.isNegative=function(){return this.s<0},I.isPositive=function(){return this.s>0},I.isZero=function(){return!!this.c&&this.c[0]==0},I.minus=function(C,T){var x,F,L,G,B=this,D=B.s;if(C=new u(C,T),T=C.s,!D||!T)return new u(NaN);if(D!=T)return C.s=-T,B.plus(C);var Z=B.e/p,H=C.e/p,V=B.c,ee=C.c;if(!Z||!H){if(!V||!ee)return V?(C.s=-T,C):new u(ee?B:NaN);if(!V[0]||!ee[0])return ee[0]?(C.s=-T,C):new u(V[0]?B:N==3?-0:0)}if(Z=U(Z),H=U(H),V=V.slice(),D=Z-H){for((G=D<0)?(D=-D,L=V):(H=Z,L=ee),L.reverse(),T=D;T--;L.push(0));L.reverse()}else for(F=(G=(D=V.length)<(T=ee.length))?D:T,D=T=0;T<F;T++)if(V[T]!=ee[T]){G=V[T]<ee[T];break}if(G&&(L=V,V=ee,ee=L,C.s=-C.s),T=(F=ee.length)-(x=V.length),T>0)for(;T--;V[x++]=0);for(T=c-1;F>D;){if(V[--F]<ee[F]){for(x=F;x&&!V[--x];V[x]=T);--V[x],V[F]+=c}V[F]-=ee[F]}for(;V[0]==0;V.splice(0,1),--H);return V[0]?$(C,V,H):(C.s=N==3?-1:1,C.c=[C.e=0],C)},I.modulo=I.mod=function(C,T){var x,F,L=this;return C=new u(C,T),!L.c||!C.s||C.c&&!C.c[0]?new u(NaN):!C.c||L.c&&!L.c[0]?new u(L):(m==9?(F=C.s,C.s=1,x=Y(L,C,0,3),C.s=F,x.s*=F):x=Y(L,C,0,m),C=L.minus(x.times(C)),!C.c[0]&&m==1&&(C.s=L.s),C)},I.multipliedBy=I.times=function(C,T){var x,F,L,G,B,D,Z,H,V,ee,te,le,Ee,ce,pe,Ce=this,ue=Ce.c,Se=(C=new u(C,T)).c;if(!ue||!Se||!ue[0]||!Se[0])return!Ce.s||!C.s||ue&&!ue[0]&&!Se||Se&&!Se[0]&&!ue?C.c=C.e=C.s=null:(C.s*=Ce.s,!ue||!Se?C.c=C.e=null:(C.c=[0],C.e=0)),C;for(F=U(Ce.e/p)+U(C.e/p),C.s*=Ce.s,Z=ue.length,ee=Se.length,Z<ee&&(Ee=ue,ue=Se,Se=Ee,L=Z,Z=ee,ee=L),L=Z+ee,Ee=[];L--;Ee.push(0));for(ce=c,pe=y,L=ee;--L>=0;){for(x=0,te=Se[L]%pe,le=Se[L]/pe|0,B=Z,G=L+B;G>L;)H=ue[--B]%pe,V=ue[B]/pe|0,D=le*H+V*te,H=te*H+D%pe*pe+Ee[G]+x,x=(H/ce|0)+(D/pe|0)+le*V,Ee[G--]=H%ce;Ee[G]=x}return x?++F:Ee.splice(0,1),$(C,Ee,F)},I.negated=function(){var C=new u(this);return C.s=-C.s||null,C},I.plus=function(C,T){var x,F=this,L=F.s;if(C=new u(C,T),T=C.s,!L||!T)return new u(NaN);if(L!=T)return C.s=-T,F.minus(C);var G=F.e/p,B=C.e/p,D=F.c,Z=C.c;if(!G||!B){if(!D||!Z)return new u(L/0);if(!D[0]||!Z[0])return Z[0]?C:new u(D[0]?F:L*0)}if(G=U(G),B=U(B),D=D.slice(),L=G-B){for(L>0?(B=G,x=Z):(L=-L,x=D),x.reverse();L--;x.push(0));x.reverse()}for(L=D.length,T=Z.length,L-T<0&&(x=Z,Z=D,D=x,T=L),L=0;T;)L=(D[--T]=D[T]+Z[T]+L)/c|0,D[T]=c===D[T]?0:D[T]%c;return L&&(D=[L].concat(D),++B),$(C,D,B)},I.precision=I.sd=function(C,T){var x,F,L,G=this;if(C!=null&&C!==!!C)return j(C,1,A),T==null?T=N:j(T,0,8),z(new u(G),C,T);if(!(x=G.c))return null;if(L=x.length-1,F=L*p+1,L=x[L]){for(;L%10==0;L/=10,F--);for(L=x[0];L>=10;L/=10,F++);}return C&&G.e+1>F&&(F=G.e+1),F},I.shiftedBy=function(C){return j(C,-g,g),this.times("1e"+C)},I.squareRoot=I.sqrt=function(){var C,T,x,F,L,G=this,B=G.c,D=G.s,Z=G.e,H=R+4,V=new u("0.5");if(D!==1||!B||!B[0])return new u(!D||D<0&&(!B||B[0])?NaN:B?G:1/0);if(D=Math.sqrt(+ie(G)),D==0||D==1/0?(T=P(B),(T.length+Z)%2==0&&(T+="0"),D=Math.sqrt(+T),Z=U((Z+1)/2)-(Z<0||Z%2),D==1/0?T="5e"+Z:(T=D.toExponential(),T=T.slice(0,T.indexOf("e")+1)+Z),x=new u(T)):x=new u(D+""),x.c[0]){for(Z=x.e,D=Z+H,D<3&&(D=0);;)if(L=x,x=V.times(L.plus(Y(G,L,H,1))),P(L.c).slice(0,D)===(T=P(x.c)).slice(0,D))if(x.e<Z&&--D,T=T.slice(D-3,D+1),T=="9999"||!F&&T=="4999"){if(!F&&(z(L,L.e+R+2,0),L.times(L).eq(G))){x=L;break}H+=4,D+=4,F=1}else{(!+T||!+T.slice(1)&&T.charAt(0)=="5")&&(z(x,x.e+R+2,1),C=!x.times(x).eq(G));break}}return z(x,x.e+R+1,N,C)},I.toExponential=function(C,T){return C!=null&&(j(C,0,A),C++),M(this,C,T,1)},I.toFixed=function(C,T){return C!=null&&(j(C,0,A),C=C+this.e+1),M(this,C,T)},I.toFormat=function(C,T,x){var F,L=this;if(x==null)C!=null&&T&&typeof T=="object"?(x=T,T=null):C&&typeof C=="object"?(x=C,C=T=null):x=b;else if(typeof x!="object")throw Error(s+"Argument not an object: "+x);if(F=L.toFixed(C,T),L.c){var G,B=F.split("."),D=+x.groupSize,Z=+x.secondaryGroupSize,H=x.groupSeparator||"",V=B[0],ee=B[1],te=L.s<0,le=te?V.slice(1):V,Ee=le.length;if(Z&&(G=D,D=Z,Z=G,Ee-=G),D>0&&Ee>0){for(G=Ee%D||D,V=le.substr(0,G);G<Ee;G+=D)V+=H+le.substr(G,D);Z>0&&(V+=H+le.slice(G)),te&&(V="-"+V)}F=ee?V+(x.decimalSeparator||"")+((Z=+x.fractionGroupSize)?ee.replace(new RegExp("\\d{"+Z+"}\\B","g"),"$&"+(x.fractionGroupSeparator||"")):ee):V}return(x.prefix||"")+F+(x.suffix||"")},I.toFraction=function(C){var T,x,F,L,G,B,D,Z,H,V,ee,te,le=this,Ee=le.c;if(C!=null&&(D=new u(C),!D.isInteger()&&(D.c||D.s!==1)||D.lt(O)))throw Error(s+"Argument "+(D.isInteger()?"out of range: ":"not an integer: ")+ie(D));if(!Ee)return new u(le);for(T=new u(O),H=x=new u(O),F=Z=new u(O),te=P(Ee),G=T.e=te.length-le.e-1,T.c[0]=v[(B=G%p)<0?p+B:B],C=!C||D.comparedTo(T)>0?G>0?T:H:D,B=l,l=1/0,D=new u(te),Z.c[0]=0;V=Y(D,T,0,1),L=x.plus(V.times(F)),L.comparedTo(C)!=1;)x=F,F=L,H=Z.plus(V.times(L=H)),Z=L,T=D.minus(V.times(L=T)),D=L;return L=Y(C.minus(x),F,0,1),Z=Z.plus(L.times(H)),x=x.plus(L.times(F)),Z.s=H.s=le.s,G=G*2,ee=Y(H,F,G,N).minus(le).abs().comparedTo(Y(Z,x,G,N).minus(le).abs())<1?[H,F]:[Z,x],l=B,ee},I.toNumber=function(){return+ie(this)},I.toPrecision=function(C,T){return C!=null&&j(C,1,A),M(this,C,T,2)},I.toString=function(C){var T,x=this,F=x.s,L=x.e;return L===null?F?(T="Infinity",F<0&&(T="-"+T)):T="NaN":(C==null?T=L<=S||L>=h?X(P(x.c),L):Q(P(x.c),L,"0"):C===10&&f?(x=z(new u(x),R+L+1,N),T=Q(P(x.c),x.e,"0")):(j(C,2,w.length,"Base"),T=ae(Q(P(x.c),L,"0"),10,C,F,!0)),F<0&&x.c[0]&&(T="-"+T)),T},I.valueOf=I.toJSON=function(){return ie(this)},I._isBigNumber=!0,se!=null&&u.set(se),u}function U(se){var Y=se|0;return se>0||se===Y?Y:Y-1}function P(se){for(var Y,ae,E=1,I=se.length,O=se[0]+"";E<I;){for(Y=se[E++]+"",ae=p-Y.length;ae--;Y="0"+Y);O+=Y}for(I=O.length;O.charCodeAt(--I)===48;);return O.slice(0,I+1||1)}function W(se,Y){var ae,E,I=se.c,O=Y.c,R=se.s,N=Y.s,S=se.e,h=Y.e;if(!R||!N)return null;if(ae=I&&!I[0],E=O&&!O[0],ae||E)return ae?E?0:-N:R;if(R!=N)return R;if(ae=R<0,E=S==h,!I||!O)return E?0:!I^ae?1:-1;if(!E)return S>h^ae?1:-1;for(N=(S=I.length)<(h=O.length)?S:h,R=0;R<N;R++)if(I[R]!=O[R])return I[R]>O[R]^ae?1:-1;return S==h?0:S>h^ae?1:-1}function j(se,Y,ae,E){if(se<Y||se>ae||se!==n(se))throw Error(s+(E||"Argument")+(typeof se=="number"?se<Y||se>ae?" out of range: ":" not an integer: ":" not a primitive number: ")+String(se))}function K(se){var Y=se.c.length-1;return U(se.e/p)==Y&&se.c[Y]%2!=0}function X(se,Y){return(se.length>1?se.charAt(0)+"."+se.slice(1):se)+(Y<0?"e":"e+")+Y}function Q(se,Y,ae){var E,I;if(Y<0){for(I=ae+".";++Y;I+=ae);se=I+se}else if(E=se.length,++Y>E){for(I=ae,Y-=E;--Y;I+=ae);se+=I}else Y<E&&(se=se.slice(0,Y)+"."+se.slice(Y));return se}t=k(),t.default=t.BigNumber=t,typeof define=="function"&&define.amd?define(function(){return t}):typeof wn<"u"&&wn.exports?wn.exports=t:(e||(e=typeof self<"u"&&self?self:window),e.BigNumber=t)})(Ia)});var Pa=dr((zg,Oa)=>{"use strict";var ka=Po(),Ta=Oa.exports;(function(){"use strict";function e(g){return g<10?"0"+g:g}var t=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,i=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,r,n,s={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},a;function c(g){return i.lastIndex=0,i.test(g)?'"'+g.replace(i,function(v){var y=s[v];return typeof y=="string"?y:"\\u"+("0000"+v.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+g+'"'}function p(g,v){var y,A,k,U,P=r,W,j=v[g],K=j!=null&&(j instanceof ka||ka.isBigNumber(j));switch(j&&typeof j=="object"&&typeof j.toJSON=="function"&&(j=j.toJSON(g)),typeof a=="function"&&(j=a.call(v,g,j)),typeof j){case"string":return K?j:c(j);case"number":return isFinite(j)?String(j):"null";case"boolean":case"null":case"bigint":return String(j);case"object":if(!j)return"null";if(r+=n,W=[],Object.prototype.toString.apply(j)==="[object Array]"){for(U=j.length,y=0;y<U;y+=1)W[y]=p(y,j)||"null";return k=W.length===0?"[]":r?`[
2
- `+r+W.join(`,
3
- `+r)+`
4
- `+P+"]":"["+W.join(",")+"]",r=P,k}if(a&&typeof a=="object")for(U=a.length,y=0;y<U;y+=1)typeof a[y]=="string"&&(A=a[y],k=p(A,j),k&&W.push(c(A)+(r?": ":":")+k));else Object.keys(j).forEach(function(X){var Q=p(X,j);Q&&W.push(c(X)+(r?": ":":")+Q)});return k=W.length===0?"{}":r?`{
5
- `+r+W.join(`,
6
- `+r)+`
7
- `+P+"}":"{"+W.join(",")+"}",r=P,k}}typeof Ta.stringify!="function"&&(Ta.stringify=function(g,v,y){var A;if(r="",n="",typeof y=="number")for(A=0;A<y;A+=1)n+=" ";else typeof y=="string"&&(n=y);if(a=v,v&&typeof v!="function"&&(typeof v!="object"||typeof v.length!="number"))throw new Error("JSON.stringify");return p("",{"":g})})})()});var Na=dr((Xg,xa)=>{"use strict";var bn=null,_c=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,vc=/(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/,wc=function(e){"use strict";var t={strict:!1,storeAsString:!1,alwaysParseAsBig:!1,useNativeBigInt:!1,protoAction:"error",constructorAction:"error"};if(e!=null){if(e.strict===!0&&(t.strict=!0),e.storeAsString===!0&&(t.storeAsString=!0),t.alwaysParseAsBig=e.alwaysParseAsBig===!0?e.alwaysParseAsBig:!1,t.useNativeBigInt=e.useNativeBigInt===!0?e.useNativeBigInt:!1,typeof e.constructorAction<"u")if(e.constructorAction==="error"||e.constructorAction==="ignore"||e.constructorAction==="preserve")t.constructorAction=e.constructorAction;else throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${e.constructorAction}`);if(typeof e.protoAction<"u")if(e.protoAction==="error"||e.protoAction==="ignore"||e.protoAction==="preserve")t.protoAction=e.protoAction;else throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${e.protoAction}`)}var i,r,n={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
8
- `,r:"\r",t:" "},s,a=function(P){throw{name:"SyntaxError",message:P,at:i,text:s}},c=function(P){return P&&P!==r&&a("Expected '"+P+"' instead of '"+r+"'"),r=s.charAt(i),i+=1,r},p=function(){var P,W="";for(r==="-"&&(W="-",c("-"));r>="0"&&r<="9";)W+=r,c();if(r===".")for(W+=".";c()&&r>="0"&&r<="9";)W+=r;if(r==="e"||r==="E")for(W+=r,c(),(r==="-"||r==="+")&&(W+=r,c());r>="0"&&r<="9";)W+=r,c();if(P=+W,!isFinite(P))a("Bad number");else return bn==null&&(bn=Po()),W.length>15?t.storeAsString?W:t.useNativeBigInt?BigInt(W):new bn(W):t.alwaysParseAsBig?t.useNativeBigInt?BigInt(P):new bn(P):P},g=function(){var P,W,j="",K;if(r==='"')for(var X=i;c();){if(r==='"')return i-1>X&&(j+=s.substring(X,i-1)),c(),j;if(r==="\\"){if(i-1>X&&(j+=s.substring(X,i-1)),c(),r==="u"){for(K=0,W=0;W<4&&(P=parseInt(c(),16),!!isFinite(P));W+=1)K=K*16+P;j+=String.fromCharCode(K)}else if(typeof n[r]=="string")j+=n[r];else break;X=i}}a("Bad string")},v=function(){for(;r&&r<=" ";)c()},y=function(){switch(r){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null}a("Unexpected '"+r+"'")},A,k=function(){var P=[];if(r==="["){if(c("["),v(),r==="]")return c("]"),P;for(;r;){if(P.push(A()),v(),r==="]")return c("]"),P;c(","),v()}}a("Bad array")},U=function(){var P,W=Object.create(null);if(r==="{"){if(c("{"),v(),r==="}")return c("}"),W;for(;r;){if(P=g(),v(),c(":"),t.strict===!0&&Object.hasOwnProperty.call(W,P)&&a('Duplicate key "'+P+'"'),_c.test(P)===!0?t.protoAction==="error"?a("Object contains forbidden prototype property"):t.protoAction==="ignore"?A():W[P]=A():vc.test(P)===!0?t.constructorAction==="error"?a("Object contains forbidden constructor property"):t.constructorAction==="ignore"?A():W[P]=A():W[P]=A(),v(),r==="}")return c("}"),W;c(","),v()}}a("Bad object")};return A=function(){switch(v(),r){case"{":return U();case"[":return k();case'"':return g();case"-":return p();default:return r>="0"&&r<="9"?p():y()}},function(P,W){var j;return s=P+"",i=0,r=" ",j=A(),v(),r&&a("Syntax error"),typeof W=="function"?(function K(X,Q){var se,Y,ae=X[Q];return ae&&typeof ae=="object"&&Object.keys(ae).forEach(function(E){Y=K(ae,E),Y!==void 0?ae[E]=Y:delete ae[E]}),W.call(X,Q,ae)})({"":j},""):j}};xa.exports=wc});var Fa=dr((Jg,yn)=>{"use strict";var Ra=Pa().stringify,La=Na();yn.exports=function(e){return{parse:La(e),stringify:Ra}};yn.exports.parse=La();yn.exports.stringify=Ra});var Bl=dr(J=>{"use strict";var xo=vt("@mysten/sui/transactions"),bc=Fa(),pt=vt("@mysten/sui/utils"),Da=vt("@mysten/sui/client"),Ba=vt("@pythnetwork/pyth-sui-js");function yc(e){return e&&e.__esModule?e:{default:e}}var Mc=yc(bc),Ac=Object.create,qo=Object.defineProperty,Sc=Object.defineProperties,Cc=Object.getOwnPropertyDescriptor,Ec=Object.getOwnPropertyDescriptors,Qa=Object.getOwnPropertyNames,Ua=Object.getOwnPropertySymbols,Ic=Object.getPrototypeOf,el=Object.prototype.hasOwnProperty,kc=Object.prototype.propertyIsEnumerable,ja=(e,t,i)=>t in e?qo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hr=(e,t)=>{for(var i in t||(t={}))el.call(t,i)&&ja(e,i,t[i]);if(Ua)for(var i of Ua(t))kc.call(t,i)&&ja(e,i,t[i]);return e},Sn=(e,t)=>Sc(e,Ec(t)),Tc=(e=>typeof vt<"u"?vt:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof vt<"u"?vt:t)[i]}):e)(function(e){if(typeof vt<"u")return vt.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),Oc=(e,t)=>function(){return t||(0,e[Qa(e)[0]])((t={exports:{}}).exports,t),t.exports},Pc=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Qa(t))!el.call(e,n)&&n!==i&&qo(e,n,{get:()=>t[n],enumerable:!(r=Cc(t,n))||r.enumerable});return e},wr=(e,t,i)=>(i=e!=null?Ac(Ic(e)):{},Pc(!e||!e.__esModule?qo(i,"default",{value:e,enumerable:!0}):i,e)),It=(e,t,i)=>new Promise((r,n)=>{var s=p=>{try{c(i.next(p))}catch(g){n(g)}},a=p=>{try{c(i.throw(p))}catch(g){n(g)}},c=p=>p.done?r(p.value):Promise.resolve(p.value).then(s,a);c((i=i.apply(e,t)).next())}),br=Oc({"node_modules/bn.js/lib/bn.js"(e,t){(function(i,r){function n(h,o){if(!h)throw new Error(o||"Assertion failed")}function s(h,o){h.super_=o;var l=function(){};l.prototype=o.prototype,h.prototype=new l,h.prototype.constructor=h}function a(h,o,l){if(a.isBN(h))return h;this.negative=0,this.words=null,this.length=0,this.red=null,h!==null&&((o==="le"||o==="be")&&(l=o,o=10),this._init(h||0,o||10,l||"be"))}typeof i=="object"?i.exports=a:r.BN=a,a.BN=a,a.wordSize=26;var c;try{typeof window<"u"&&typeof window.Buffer<"u"?c=window.Buffer:c=Tc("buffer").Buffer}catch{}a.isBN=function(o){return o instanceof a?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===a.wordSize&&Array.isArray(o.words)},a.max=function(o,l){return o.cmp(l)>0?o:l},a.min=function(o,l){return o.cmp(l)<0?o:l},a.prototype._init=function(o,l,d){if(typeof o=="number")return this._initNumber(o,l,d);if(typeof o=="object")return this._initArray(o,l,d);l==="hex"&&(l=16),n(l===(l|0)&&l>=2&&l<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(l===16?this._parseHex(o,m,d):(this._parseBase(o,l,m),d==="le"&&this._initArray(this.toArray(),l,d)))},a.prototype._initNumber=function(o,l,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(n(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),l,d)},a.prototype._initArray=function(o,l,d){if(n(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _,b,w=0;if(d==="be")for(m=o.length-1,_=0;m>=0;m-=3)b=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);else if(d==="le")for(m=0,_=0;m<o.length;m+=3)b=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);return this._strip()};function p(h,o){var l=h.charCodeAt(o);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;n(!1,"Invalid character in "+h)}function g(h,o,l){var d=p(h,l);return l-1>=o&&(d|=p(h,l-1)<<4),d}a.prototype._parseHex=function(o,l,d){this.length=Math.ceil((o.length-l)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _=0,b=0,w;if(d==="be")for(m=o.length-1;m>=l;m-=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8;else{var f=o.length-l;for(m=f%2===0?l+1:l;m<o.length;m+=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8}this._strip()};function v(h,o,l,d){for(var m=0,_=0,b=Math.min(h.length,l),w=o;w<b;w++){var f=h.charCodeAt(w)-48;m*=d,f>=49?_=f-49+10:f>=17?_=f-17+10:_=f,n(f>=0&&_<d,"Invalid character"),m+=_}return m}a.prototype._parseBase=function(o,l,d){this.words=[0],this.length=1;for(var m=0,_=1;_<=67108863;_*=l)m++;m--,_=_/l|0;for(var b=o.length-d,w=b%m,f=Math.min(b,b-w)+d,u=0,M=d;M<f;M+=m)u=v(o,M,M+m,l),this.imuln(_),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(w!==0){var q=1;for(u=v(o,M,o.length,l),M=0;M<w;M++)q*=l;this.imuln(q),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},a.prototype.copy=function(o){o.words=new Array(this.length);for(var l=0;l<this.length;l++)o.words[l]=this.words[l];o.length=this.length,o.negative=this.negative,o.red=this.red};function y(h,o){h.words=o.words,h.length=o.length,h.negative=o.negative,h.red=o.red}if(a.prototype._move=function(o){y(o,this)},a.prototype.clone=function(){var o=new a(null);return this.copy(o),o},a.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{a.prototype.inspect=A}else a.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var k=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],U=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(o,l){o=o||10,l=l|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,_=0,b=0;b<this.length;b++){var w=this.words[b],f=((w<<m|_)&16777215).toString(16);_=w>>>24-m&16777215,m+=2,m>=26&&(m-=26,b--),_!==0||b!==this.length-1?d=k[6-f.length]+f+d:d=f+d}for(_!==0&&(d=_.toString(16)+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var u=U[o],M=P[o];d="";var q=this.clone();for(q.negative=0;!q.isZero();){var $=q.modrn(M).toString(o);q=q.idivn(M),q.isZero()?d=$+d:d=k[u-$.length]+$+d}for(this.isZero()&&(d="0"+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},a.prototype.toJSON=function(){return this.toString(16,2)},c&&(a.prototype.toBuffer=function(o,l){return this.toArrayLike(c,o,l)}),a.prototype.toArray=function(o,l){return this.toArrayLike(Array,o,l)};var W=function(o,l){return o.allocUnsafe?o.allocUnsafe(l):new o(l)};a.prototype.toArrayLike=function(o,l,d){this._strip();var m=this.byteLength(),_=d||Math.max(1,m);n(m<=_,"byte array longer than desired length"),n(_>0,"Requested array length <= 0");var b=W(o,_),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](b,m),b},a.prototype._toArrayLikeLE=function(o,l){for(var d=0,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d++]=w&255,d<o.length&&(o[d++]=w>>8&255),d<o.length&&(o[d++]=w>>16&255),b===6?(d<o.length&&(o[d++]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},a.prototype._toArrayLikeBE=function(o,l){for(var d=o.length-1,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d--]=w&255,d>=0&&(o[d--]=w>>8&255),d>=0&&(o[d--]=w>>16&255),b===6?(d>=0&&(o[d--]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?a.prototype._countBits=function(o){return 32-Math.clz32(o)}:a.prototype._countBits=function(o){var l=o,d=0;return l>=4096&&(d+=13,l>>>=13),l>=64&&(d+=7,l>>>=7),l>=8&&(d+=4,l>>>=4),l>=2&&(d+=2,l>>>=2),d+l},a.prototype._zeroBits=function(o){if(o===0)return 26;var l=o,d=0;return(l&8191)===0&&(d+=13,l>>>=13),(l&127)===0&&(d+=7,l>>>=7),(l&15)===0&&(d+=4,l>>>=4),(l&3)===0&&(d+=2,l>>>=2),(l&1)===0&&d++,d},a.prototype.bitLength=function(){var o=this.words[this.length-1],l=this._countBits(o);return(this.length-1)*26+l};function j(h){for(var o=new Array(h.bitLength()),l=0;l<o.length;l++){var d=l/26|0,m=l%26;o[l]=h.words[d]>>>m&1}return o}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,l=0;l<this.length;l++){var d=this._zeroBits(this.words[l]);if(o+=d,d!==26)break}return o},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},a.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]|o.words[l];return this._strip()},a.prototype.ior=function(o){return n((this.negative|o.negative)===0),this.iuor(o)},a.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},a.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},a.prototype.iuand=function(o){var l;this.length>o.length?l=o:l=this;for(var d=0;d<l.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=l.length,this._strip()},a.prototype.iand=function(o){return n((this.negative|o.negative)===0),this.iuand(o)},a.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},a.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},a.prototype.iuxor=function(o){var l,d;this.length>o.length?(l=this,d=o):(l=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=l.words[m]^d.words[m];if(this!==l)for(;m<l.length;m++)this.words[m]=l.words[m];return this.length=l.length,this._strip()},a.prototype.ixor=function(o){return n((this.negative|o.negative)===0),this.iuxor(o)},a.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},a.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},a.prototype.inotn=function(o){n(typeof o=="number"&&o>=0);var l=Math.ceil(o/26)|0,d=o%26;this._expand(l),d>0&&l--;for(var m=0;m<l;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},a.prototype.notn=function(o){return this.clone().inotn(o)},a.prototype.setn=function(o,l){n(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),l?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},a.prototype.iadd=function(o){var l;if(this.negative!==0&&o.negative===0)return this.negative=0,l=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,l=this.isub(o),o.negative=1,l._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var _=0,b=0;b<m.length;b++)l=(d.words[b]|0)+(m.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;for(;_!==0&&b<d.length;b++)l=(d.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;if(this.length=d.length,_!==0)this.words[this.length]=_,this.length++;else if(d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this},a.prototype.add=function(o){var l;return o.negative!==0&&this.negative===0?(o.negative=0,l=this.sub(o),o.negative^=1,l):o.negative===0&&this.negative!==0?(this.negative=0,l=o.sub(this),this.negative=1,l):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},a.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var l=this.iadd(o);return o.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,_;d>0?(m=this,_=o):(m=o,_=this);for(var b=0,w=0;w<_.length;w++)l=(m.words[w]|0)-(_.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;for(;b!==0&&w<m.length;w++)l=(m.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;if(b===0&&w<m.length&&m!==this)for(;w<m.length;w++)this.words[w]=m.words[w];return this.length=Math.max(this.length,w),m!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(o){return this.clone().isub(o)};function K(h,o,l){l.negative=o.negative^h.negative;var d=h.length+o.length|0;l.length=d,d=d-1|0;var m=h.words[0]|0,_=o.words[0]|0,b=m*_,w=b&67108863,f=b/67108864|0;l.words[0]=w;for(var u=1;u<d;u++){for(var M=f>>>26,q=f&67108863,$=Math.min(u,o.length-1),z=Math.max(0,u-h.length+1);z<=$;z++){var ie=u-z|0;m=h.words[ie]|0,_=o.words[z]|0,b=m*_+q,M+=b/67108864|0,q=b&67108863}l.words[u]=q|0,f=M|0}return f!==0?l.words[u]=f|0:l.length--,l._strip()}var X=function(o,l,d){var m=o.words,_=l.words,b=d.words,w=0,f,u,M,q=m[0]|0,$=q&8191,z=q>>>13,ie=m[1]|0,C=ie&8191,T=ie>>>13,x=m[2]|0,F=x&8191,L=x>>>13,G=m[3]|0,B=G&8191,D=G>>>13,Z=m[4]|0,H=Z&8191,V=Z>>>13,ee=m[5]|0,te=ee&8191,le=ee>>>13,Ee=m[6]|0,ce=Ee&8191,pe=Ee>>>13,Ce=m[7]|0,ue=Ce&8191,Se=Ce>>>13,et=m[8]|0,fe=et&8191,Re=et>>>13,Ye=m[9]|0,he=Ye&8191,Ie=Ye>>>13,ze=_[0]|0,de=ze&8191,Ue=ze>>>13,ot=_[1]|0,me=ot&8191,je=ot>>>13,st=_[2]|0,ge=st&8191,qe=st>>>13,at=_[3]|0,_e=at&8191,$e=at>>>13,lt=_[4]|0,ve=lt&8191,He=lt>>>13,ut=_[5]|0,we=ut&8191,Ge=ut>>>13,ct=_[6]|0,be=ct&8191,Ve=ct>>>13,dt=_[7]|0,ye=dt&8191,Ze=dt>>>13,ht=_[8]|0,Me=ht&8191,Ke=ht>>>13,ft=_[9]|0,Ae=ft&8191,Be=ft>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,de),u=Math.imul($,Ue),u=u+Math.imul(z,de)|0,M=Math.imul(z,Ue);var Gt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,f=Math.imul(C,de),u=Math.imul(C,Ue),u=u+Math.imul(T,de)|0,M=Math.imul(T,Ue),f=f+Math.imul($,me)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(z,me)|0,M=M+Math.imul(z,je)|0;var Vt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,f=Math.imul(F,de),u=Math.imul(F,Ue),u=u+Math.imul(L,de)|0,M=Math.imul(L,Ue),f=f+Math.imul(C,me)|0,u=u+Math.imul(C,je)|0,u=u+Math.imul(T,me)|0,M=M+Math.imul(T,je)|0,f=f+Math.imul($,ge)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(z,ge)|0,M=M+Math.imul(z,qe)|0;var Zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,f=Math.imul(B,de),u=Math.imul(B,Ue),u=u+Math.imul(D,de)|0,M=Math.imul(D,Ue),f=f+Math.imul(F,me)|0,u=u+Math.imul(F,je)|0,u=u+Math.imul(L,me)|0,M=M+Math.imul(L,je)|0,f=f+Math.imul(C,ge)|0,u=u+Math.imul(C,qe)|0,u=u+Math.imul(T,ge)|0,M=M+Math.imul(T,qe)|0,f=f+Math.imul($,_e)|0,u=u+Math.imul($,$e)|0,u=u+Math.imul(z,_e)|0,M=M+Math.imul(z,$e)|0;var Kt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,f=Math.imul(H,de),u=Math.imul(H,Ue),u=u+Math.imul(V,de)|0,M=Math.imul(V,Ue),f=f+Math.imul(B,me)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(D,me)|0,M=M+Math.imul(D,je)|0,f=f+Math.imul(F,ge)|0,u=u+Math.imul(F,qe)|0,u=u+Math.imul(L,ge)|0,M=M+Math.imul(L,qe)|0,f=f+Math.imul(C,_e)|0,u=u+Math.imul(C,$e)|0,u=u+Math.imul(T,_e)|0,M=M+Math.imul(T,$e)|0,f=f+Math.imul($,ve)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,He)|0;var Wt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,f=Math.imul(te,de),u=Math.imul(te,Ue),u=u+Math.imul(le,de)|0,M=Math.imul(le,Ue),f=f+Math.imul(H,me)|0,u=u+Math.imul(H,je)|0,u=u+Math.imul(V,me)|0,M=M+Math.imul(V,je)|0,f=f+Math.imul(B,ge)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(D,ge)|0,M=M+Math.imul(D,qe)|0,f=f+Math.imul(F,_e)|0,u=u+Math.imul(F,$e)|0,u=u+Math.imul(L,_e)|0,M=M+Math.imul(L,$e)|0,f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,He)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ge)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ge)|0;var zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(zt>>>26)|0,zt&=67108863,f=Math.imul(ce,de),u=Math.imul(ce,Ue),u=u+Math.imul(pe,de)|0,M=Math.imul(pe,Ue),f=f+Math.imul(te,me)|0,u=u+Math.imul(te,je)|0,u=u+Math.imul(le,me)|0,M=M+Math.imul(le,je)|0,f=f+Math.imul(H,ge)|0,u=u+Math.imul(H,qe)|0,u=u+Math.imul(V,ge)|0,M=M+Math.imul(V,qe)|0,f=f+Math.imul(B,_e)|0,u=u+Math.imul(B,$e)|0,u=u+Math.imul(D,_e)|0,M=M+Math.imul(D,$e)|0,f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,He)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ge)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ge)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ve)|0;var Xt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,f=Math.imul(ue,de),u=Math.imul(ue,Ue),u=u+Math.imul(Se,de)|0,M=Math.imul(Se,Ue),f=f+Math.imul(ce,me)|0,u=u+Math.imul(ce,je)|0,u=u+Math.imul(pe,me)|0,M=M+Math.imul(pe,je)|0,f=f+Math.imul(te,ge)|0,u=u+Math.imul(te,qe)|0,u=u+Math.imul(le,ge)|0,M=M+Math.imul(le,qe)|0,f=f+Math.imul(H,_e)|0,u=u+Math.imul(H,$e)|0,u=u+Math.imul(V,_e)|0,M=M+Math.imul(V,$e)|0,f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,He)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ge)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ge)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,Ze)|0;var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(fe,de),u=Math.imul(fe,Ue),u=u+Math.imul(Re,de)|0,M=Math.imul(Re,Ue),f=f+Math.imul(ue,me)|0,u=u+Math.imul(ue,je)|0,u=u+Math.imul(Se,me)|0,M=M+Math.imul(Se,je)|0,f=f+Math.imul(ce,ge)|0,u=u+Math.imul(ce,qe)|0,u=u+Math.imul(pe,ge)|0,M=M+Math.imul(pe,qe)|0,f=f+Math.imul(te,_e)|0,u=u+Math.imul(te,$e)|0,u=u+Math.imul(le,_e)|0,M=M+Math.imul(le,$e)|0,f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,He)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ge)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ge)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,Ke)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(he,de),u=Math.imul(he,Ue),u=u+Math.imul(Ie,de)|0,M=Math.imul(Ie,Ue),f=f+Math.imul(fe,me)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(Re,me)|0,M=M+Math.imul(Re,je)|0,f=f+Math.imul(ue,ge)|0,u=u+Math.imul(ue,qe)|0,u=u+Math.imul(Se,ge)|0,M=M+Math.imul(Se,qe)|0,f=f+Math.imul(ce,_e)|0,u=u+Math.imul(ce,$e)|0,u=u+Math.imul(pe,_e)|0,M=M+Math.imul(pe,$e)|0,f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(le,ve)|0,M=M+Math.imul(le,He)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ge)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ge)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Be)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Be)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(he,me),u=Math.imul(he,je),u=u+Math.imul(Ie,me)|0,M=Math.imul(Ie,je),f=f+Math.imul(fe,ge)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(Re,ge)|0,M=M+Math.imul(Re,qe)|0,f=f+Math.imul(ue,_e)|0,u=u+Math.imul(ue,$e)|0,u=u+Math.imul(Se,_e)|0,M=M+Math.imul(Se,$e)|0,f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(pe,ve)|0,M=M+Math.imul(pe,He)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ge)|0,u=u+Math.imul(le,we)|0,M=M+Math.imul(le,Ge)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Be)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Be)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(he,ge),u=Math.imul(he,qe),u=u+Math.imul(Ie,ge)|0,M=Math.imul(Ie,qe),f=f+Math.imul(fe,_e)|0,u=u+Math.imul(fe,$e)|0,u=u+Math.imul(Re,_e)|0,M=M+Math.imul(Re,$e)|0,f=f+Math.imul(ue,ve)|0,u=u+Math.imul(ue,He)|0,u=u+Math.imul(Se,ve)|0,M=M+Math.imul(Se,He)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ge)|0,u=u+Math.imul(pe,we)|0,M=M+Math.imul(pe,Ge)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(le,be)|0,M=M+Math.imul(le,Ve)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Be)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Be)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(he,_e),u=Math.imul(he,$e),u=u+Math.imul(Ie,_e)|0,M=Math.imul(Ie,$e),f=f+Math.imul(fe,ve)|0,u=u+Math.imul(fe,He)|0,u=u+Math.imul(Re,ve)|0,M=M+Math.imul(Re,He)|0,f=f+Math.imul(ue,we)|0,u=u+Math.imul(ue,Ge)|0,u=u+Math.imul(Se,we)|0,M=M+Math.imul(Se,Ge)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(pe,be)|0,M=M+Math.imul(pe,Ve)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(le,ye)|0,M=M+Math.imul(le,Ze)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Be)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Be)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,ve),u=Math.imul(he,He),u=u+Math.imul(Ie,ve)|0,M=Math.imul(Ie,He),f=f+Math.imul(fe,we)|0,u=u+Math.imul(fe,Ge)|0,u=u+Math.imul(Re,we)|0,M=M+Math.imul(Re,Ge)|0,f=f+Math.imul(ue,be)|0,u=u+Math.imul(ue,Ve)|0,u=u+Math.imul(Se,be)|0,M=M+Math.imul(Se,Ve)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(pe,ye)|0,M=M+Math.imul(pe,Ze)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(le,Me)|0,M=M+Math.imul(le,Ke)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Be)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Be)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(he,we),u=Math.imul(he,Ge),u=u+Math.imul(Ie,we)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(fe,be)|0,u=u+Math.imul(fe,Ve)|0,u=u+Math.imul(Re,be)|0,M=M+Math.imul(Re,Ve)|0,f=f+Math.imul(ue,ye)|0,u=u+Math.imul(ue,Ze)|0,u=u+Math.imul(Se,ye)|0,M=M+Math.imul(Se,Ze)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(pe,Me)|0,M=M+Math.imul(pe,Ke)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Be)|0,u=u+Math.imul(le,Ae)|0,M=M+Math.imul(le,Be)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(he,be),u=Math.imul(he,Ve),u=u+Math.imul(Ie,be)|0,M=Math.imul(Ie,Ve),f=f+Math.imul(fe,ye)|0,u=u+Math.imul(fe,Ze)|0,u=u+Math.imul(Re,ye)|0,M=M+Math.imul(Re,Ze)|0,f=f+Math.imul(ue,Me)|0,u=u+Math.imul(ue,Ke)|0,u=u+Math.imul(Se,Me)|0,M=M+Math.imul(Se,Ke)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Be)|0,u=u+Math.imul(pe,Ae)|0,M=M+Math.imul(pe,Be)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(he,ye),u=Math.imul(he,Ze),u=u+Math.imul(Ie,ye)|0,M=Math.imul(Ie,Ze),f=f+Math.imul(fe,Me)|0,u=u+Math.imul(fe,Ke)|0,u=u+Math.imul(Re,Me)|0,M=M+Math.imul(Re,Ke)|0,f=f+Math.imul(ue,Ae)|0,u=u+Math.imul(ue,Be)|0,u=u+Math.imul(Se,Ae)|0,M=M+Math.imul(Se,Be)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(he,Me),u=Math.imul(he,Ke),u=u+Math.imul(Ie,Me)|0,M=Math.imul(Ie,Ke),f=f+Math.imul(fe,Ae)|0,u=u+Math.imul(fe,Be)|0,u=u+Math.imul(Re,Ae)|0,M=M+Math.imul(Re,Be)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(he,Ae),u=Math.imul(he,Be),u=u+Math.imul(Ie,Ae)|0,M=Math.imul(Ie,Be);var rr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(rr>>>26)|0,rr&=67108863,b[0]=Gt,b[1]=Vt,b[2]=Zt,b[3]=Kt,b[4]=Wt,b[5]=zt,b[6]=Xt,b[7]=Jt,b[8]=Yt,b[9]=Qt,b[10]=ei,b[11]=ti,b[12]=ii,b[13]=ri,b[14]=ni,b[15]=oi,b[16]=si,b[17]=ai,b[18]=rr,w!==0&&(b[19]=w,d.length++),d};Math.imul||(X=K);function Q(h,o,l){l.negative=o.negative^h.negative,l.length=h.length+o.length;for(var d=0,m=0,_=0;_<l.length-1;_++){var b=m;m=0;for(var w=d&67108863,f=Math.min(_,o.length-1),u=Math.max(0,_-h.length+1);u<=f;u++){var M=_-u,q=h.words[M]|0,$=o.words[u]|0,z=q*$,ie=z&67108863;b=b+(z/67108864|0)|0,ie=ie+w|0,w=ie&67108863,b=b+(ie>>>26)|0,m+=b>>>26,b&=67108863}l.words[_]=w,d=b,b=m}return d!==0?l.words[_]=d:l.length--,l._strip()}function se(h,o,l){return Q(h,o,l)}a.prototype.mulTo=function(o,l){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=X(this,o,l):m<63?d=K(this,o,l):m<1024?d=Q(this,o,l):d=se(this,o,l),d},a.prototype.mul=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),this.mulTo(o,l)},a.prototype.mulf=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),se(this,o,l)},a.prototype.imul=function(o){return this.clone().mulTo(o,this)},a.prototype.imuln=function(o){var l=o<0;l&&(o=-o),n(typeof o=="number"),n(o<67108864);for(var d=0,m=0;m<this.length;m++){var _=(this.words[m]|0)*o,b=(_&67108863)+(d&67108863);d>>=26,d+=_/67108864|0,d+=b>>>26,this.words[m]=b&67108863}return d!==0&&(this.words[m]=d,this.length++),l?this.ineg():this},a.prototype.muln=function(o){return this.clone().imuln(o)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(o){var l=j(o);if(l.length===0)return new a(1);for(var d=this,m=0;m<l.length&&l[m]===0;m++,d=d.sqr());if(++m<l.length)for(var _=d.sqr();m<l.length;m++,_=_.sqr())l[m]!==0&&(d=d.mul(_));return d},a.prototype.iushln=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=67108863>>>26-l<<26-l,_;if(l!==0){var b=0;for(_=0;_<this.length;_++){var w=this.words[_]&m,f=(this.words[_]|0)-w<<l;this.words[_]=f|b,b=w>>>26-l}b&&(this.words[_]=b,this.length++)}if(d!==0){for(_=this.length-1;_>=0;_--)this.words[_+d]=this.words[_];for(_=0;_<d;_++)this.words[_]=0;this.length+=d}return this._strip()},a.prototype.ishln=function(o){return n(this.negative===0),this.iushln(o)},a.prototype.iushrn=function(o,l,d){n(typeof o=="number"&&o>=0);var m;l?m=(l-l%26)/26:m=0;var _=o%26,b=Math.min((o-_)/26,this.length),w=67108863^67108863>>>_<<_,f=d;if(m-=b,m=Math.max(0,m),f){for(var u=0;u<b;u++)f.words[u]=this.words[u];f.length=b}if(b!==0)if(this.length>b)for(this.length-=b,u=0;u<this.length;u++)this.words[u]=this.words[u+b];else this.words[0]=0,this.length=1;var M=0;for(u=this.length-1;u>=0&&(M!==0||u>=m);u--){var q=this.words[u]|0;this.words[u]=M<<26-_|q>>>_,M=q&w}return f&&M!==0&&(f.words[f.length++]=M),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(o,l,d){return n(this.negative===0),this.iushrn(o,l,d)},a.prototype.shln=function(o){return this.clone().ishln(o)},a.prototype.ushln=function(o){return this.clone().iushln(o)},a.prototype.shrn=function(o){return this.clone().ishrn(o)},a.prototype.ushrn=function(o){return this.clone().iushrn(o)},a.prototype.testn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return!1;var _=this.words[d];return!!(_&m)},a.prototype.imaskn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(l!==0&&d++,this.length=Math.min(d,this.length),l!==0){var m=67108863^67108863>>>l<<l;this.words[this.length-1]&=m}return this._strip()},a.prototype.maskn=function(o){return this.clone().imaskn(o)},a.prototype.iaddn=function(o){return n(typeof o=="number"),n(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},a.prototype._iaddn=function(o){this.words[0]+=o;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},a.prototype.isubn=function(o){if(n(typeof o=="number"),n(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},a.prototype.addn=function(o){return this.clone().iaddn(o)},a.prototype.subn=function(o){return this.clone().isubn(o)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(o,l,d){var m=o.length+d,_;this._expand(m);var b,w=0;for(_=0;_<o.length;_++){b=(this.words[_+d]|0)+w;var f=(o.words[_]|0)*l;b-=f&67108863,w=(b>>26)-(f/67108864|0),this.words[_+d]=b&67108863}for(;_<this.length-d;_++)b=(this.words[_+d]|0)+w,w=b>>26,this.words[_+d]=b&67108863;if(w===0)return this._strip();for(n(w===-1),w=0,_=0;_<this.length;_++)b=-(this.words[_]|0)+w,w=b>>26,this.words[_]=b&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(o,l){var d=this.length-o.length,m=this.clone(),_=o,b=_.words[_.length-1]|0,w=this._countBits(b);d=26-w,d!==0&&(_=_.ushln(d),m.iushln(d),b=_.words[_.length-1]|0);var f=m.length-_.length,u;if(l!=="mod"){u=new a(null),u.length=f+1,u.words=new Array(u.length);for(var M=0;M<u.length;M++)u.words[M]=0}var q=m.clone()._ishlnsubmul(_,1,f);q.negative===0&&(m=q,u&&(u.words[f]=1));for(var $=f-1;$>=0;$--){var z=(m.words[_.length+$]|0)*67108864+(m.words[_.length+$-1]|0);for(z=Math.min(z/b|0,67108863),m._ishlnsubmul(_,z,$);m.negative!==0;)z--,m.negative=0,m._ishlnsubmul(_,1,$),m.isZero()||(m.negative^=1);u&&(u.words[$]=z)}return u&&u._strip(),m._strip(),l!=="div"&&d!==0&&m.iushrn(d),{div:u||null,mod:m}},a.prototype.divmod=function(o,l,d){if(n(!o.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var m,_,b;return this.negative!==0&&o.negative===0?(b=this.neg().divmod(o,l),l!=="mod"&&(m=b.div.neg()),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.iadd(o)),{div:m,mod:_}):this.negative===0&&o.negative!==0?(b=this.divmod(o.neg(),l),l!=="mod"&&(m=b.div.neg()),{div:m,mod:b.mod}):(this.negative&o.negative)!==0?(b=this.neg().divmod(o.neg(),l),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.isub(o)),{div:b.div,mod:_}):o.length>this.length||this.cmp(o)<0?{div:new a(0),mod:this}:o.length===1?l==="div"?{div:this.divn(o.words[0]),mod:null}:l==="mod"?{div:null,mod:new a(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new a(this.modrn(o.words[0]))}:this._wordDiv(o,l)},a.prototype.div=function(o){return this.divmod(o,"div",!1).div},a.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},a.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},a.prototype.divRound=function(o){var l=this.divmod(o);if(l.mod.isZero())return l.div;var d=l.div.negative!==0?l.mod.isub(o):l.mod,m=o.ushrn(1),_=o.andln(1),b=d.cmp(m);return b<0||_===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},a.prototype.modrn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=(1<<26)%o,m=0,_=this.length-1;_>=0;_--)m=(d*m+(this.words[_]|0))%o;return l?-m:m},a.prototype.modn=function(o){return this.modrn(o)},a.prototype.idivn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var _=(this.words[m]|0)+d*67108864;this.words[m]=_/o|0,d=_%o}return this._strip(),l?this.ineg():this},a.prototype.divn=function(o){return this.clone().idivn(o)},a.prototype.egcd=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=new a(0),w=new a(1),f=0;l.isEven()&&d.isEven();)l.iushrn(1),d.iushrn(1),++f;for(var u=d.clone(),M=l.clone();!l.isZero();){for(var q=0,$=1;(l.words[0]&$)===0&&q<26;++q,$<<=1);if(q>0)for(l.iushrn(q);q-- >0;)(m.isOdd()||_.isOdd())&&(m.iadd(u),_.isub(M)),m.iushrn(1),_.iushrn(1);for(var z=0,ie=1;(d.words[0]&ie)===0&&z<26;++z,ie<<=1);if(z>0)for(d.iushrn(z);z-- >0;)(b.isOdd()||w.isOdd())&&(b.iadd(u),w.isub(M)),b.iushrn(1),w.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(b),_.isub(w)):(d.isub(l),b.isub(m),w.isub(_))}return{a:b,b:w,gcd:d.iushln(f)}},a.prototype._invmp=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=d.clone();l.cmpn(1)>0&&d.cmpn(1)>0;){for(var w=0,f=1;(l.words[0]&f)===0&&w<26;++w,f<<=1);if(w>0)for(l.iushrn(w);w-- >0;)m.isOdd()&&m.iadd(b),m.iushrn(1);for(var u=0,M=1;(d.words[0]&M)===0&&u<26;++u,M<<=1);if(u>0)for(d.iushrn(u);u-- >0;)_.isOdd()&&_.iadd(b),_.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(_)):(d.isub(l),_.isub(m))}var q;return l.cmpn(1)===0?q=m:q=_,q.cmpn(0)<0&&q.iadd(o),q},a.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var l=this.clone(),d=o.clone();l.negative=0,d.negative=0;for(var m=0;l.isEven()&&d.isEven();m++)l.iushrn(1),d.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;d.isEven();)d.iushrn(1);var _=l.cmp(d);if(_<0){var b=l;l=d,d=b}else if(_===0||d.cmpn(1)===0)break;l.isub(d)}while(!0);return d.iushln(m)},a.prototype.invm=function(o){return this.egcd(o).a.umod(o)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(o){return this.words[0]&o},a.prototype.bincn=function(o){n(typeof o=="number");var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var _=m,b=d;_!==0&&b<this.length;b++){var w=this.words[b]|0;w+=_,_=w>>>26,w&=67108863,this.words[b]=w}return _!==0&&(this.words[b]=_,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(o){var l=o<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var d;if(this.length>1)d=1;else{l&&(o=-o),n(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},a.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var l=this.ucmp(o);return this.negative!==0?-l|0:l},a.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var l=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,_=o.words[d]|0;if(m!==_){m<_?l=-1:m>_&&(l=1);break}}return l},a.prototype.gtn=function(o){return this.cmpn(o)===1},a.prototype.gt=function(o){return this.cmp(o)===1},a.prototype.gten=function(o){return this.cmpn(o)>=0},a.prototype.gte=function(o){return this.cmp(o)>=0},a.prototype.ltn=function(o){return this.cmpn(o)===-1},a.prototype.lt=function(o){return this.cmp(o)===-1},a.prototype.lten=function(o){return this.cmpn(o)<=0},a.prototype.lte=function(o){return this.cmp(o)<=0},a.prototype.eqn=function(o){return this.cmpn(o)===0},a.prototype.eq=function(o){return this.cmp(o)===0},a.red=function(o){return new N(o)},a.prototype.toRed=function(o){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},a.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(o){return this.red=o,this},a.prototype.forceRed=function(o){return n(!this.red,"Already a number in reduction context"),this._forceRed(o)},a.prototype.redAdd=function(o){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},a.prototype.redIAdd=function(o){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},a.prototype.redSub=function(o){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},a.prototype.redISub=function(o){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},a.prototype.redShl=function(o){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},a.prototype.redMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},a.prototype.redIMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},a.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(o){return n(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var Y={k256:null,p224:null,p192:null,p25519:null};function ae(h,o){this.name=h,this.p=new a(o,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}ae.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},ae.prototype.ireduce=function(o){var l=o,d;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),d=l.bitLength();while(d>this.n);var m=d<this.n?-1:l.ucmp(this.p);return m===0?(l.words[0]=0,l.length=1):m>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},ae.prototype.split=function(o,l){o.iushrn(this.n,0,l)},ae.prototype.imulK=function(o){return o.imul(this.k)};function E(){ae.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(E,ae),E.prototype.split=function(o,l){for(var d=4194303,m=Math.min(o.length,9),_=0;_<m;_++)l.words[_]=o.words[_];if(l.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var b=o.words[9];for(l.words[l.length++]=b&d,_=10;_<o.length;_++){var w=o.words[_]|0;o.words[_-10]=(w&d)<<4|b>>>22,b=w}b>>>=22,o.words[_-10]=b,b===0&&o.length>10?o.length-=10:o.length-=9},E.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var l=0,d=0;d<o.length;d++){var m=o.words[d]|0;l+=m*977,o.words[d]=l&67108863,l=m*64+(l/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function I(){ae.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,ae);function O(){ae.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(O,ae);function R(){ae.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(R,ae),R.prototype.imulK=function(o){for(var l=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+l,_=m&67108863;m>>>=26,o.words[d]=_,l=m}return l!==0&&(o.words[o.length++]=l),o},a._prime=function(o){if(Y[o])return Y[o];var l;if(o==="k256")l=new E;else if(o==="p224")l=new I;else if(o==="p192")l=new O;else if(o==="p25519")l=new R;else throw new Error("Unknown prime "+o);return Y[o]=l,l};function N(h){if(typeof h=="string"){var o=a._prime(h);this.m=o.p,this.prime=o}else n(h.gtn(1),"modulus must be greater than 1"),this.m=h,this.prime=null}N.prototype._verify1=function(o){n(o.negative===0,"red works only with positives"),n(o.red,"red works only with red numbers")},N.prototype._verify2=function(o,l){n((o.negative|l.negative)===0,"red works only with positives"),n(o.red&&o.red===l.red,"red works only with red numbers")},N.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(y(o,o.umod(this.m)._forceRed(this)),o)},N.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},N.prototype.add=function(o,l){this._verify2(o,l);var d=o.add(l);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},N.prototype.iadd=function(o,l){this._verify2(o,l);var d=o.iadd(l);return d.cmp(this.m)>=0&&d.isub(this.m),d},N.prototype.sub=function(o,l){this._verify2(o,l);var d=o.sub(l);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},N.prototype.isub=function(o,l){this._verify2(o,l);var d=o.isub(l);return d.cmpn(0)<0&&d.iadd(this.m),d},N.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},N.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},N.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},N.prototype.isqr=function(o){return this.imul(o,o.clone())},N.prototype.sqr=function(o){return this.mul(o,o)},N.prototype.sqrt=function(o){if(o.isZero())return o.clone();var l=this.m.andln(3);if(n(l%2===1),l===3){var d=this.m.add(new a(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),_=0;!m.isZero()&&m.andln(1)===0;)_++,m.iushrn(1);n(!m.isZero());var b=new a(1).toRed(this),w=b.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new a(2*u*u).toRed(this);this.pow(u,f).cmp(w)!==0;)u.redIAdd(w);for(var M=this.pow(u,m),q=this.pow(o,m.addn(1).iushrn(1)),$=this.pow(o,m),z=_;$.cmp(b)!==0;){for(var ie=$,C=0;ie.cmp(b)!==0;C++)ie=ie.redSqr();n(C<z);var T=this.pow(M,new a(1).iushln(z-C-1));q=q.redMul(T),M=T.redSqr(),$=$.redMul(M),z=C}return q},N.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},N.prototype.pow=function(o,l){if(l.isZero())return new a(1).toRed(this);if(l.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new a(1).toRed(this),m[1]=o;for(var _=2;_<m.length;_++)m[_]=this.mul(m[_-1],o);var b=m[0],w=0,f=0,u=l.bitLength()%26;for(u===0&&(u=26),_=l.length-1;_>=0;_--){for(var M=l.words[_],q=u-1;q>=0;q--){var $=M>>q&1;if(b!==m[0]&&(b=this.sqr(b)),$===0&&w===0){f=0;continue}w<<=1,w|=$,f++,!(f!==d&&(_!==0||q!==0))&&(b=this.mul(b,m[w]),f=0,w=0)}u=26}return b},N.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},N.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},a.mont=function(o){return new S(o)};function S(h){N.call(this,h),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(S,N),S.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},S.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},S.prototype.imul=function(o,l){if(o.isZero()||l.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},S.prototype.mul=function(o,l){if(o.isZero()||l.isZero())return new a(0)._forceRed(this);var d=o.mul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},S.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,e)}}),gt=wr(br()),mr=wr(br()),tl=(e=>(e.InvalidType="InvalidType",e))(tl||{}),il=(e=>(e.MissAggregatorPackage="MissAggregatorPackage",e.MissGlobalConfig="MissGlobalConfig",e.InvalidWallet="InvalidWallet",e.SimulateError="SimulateError",e))(il||{}),rl=(e=>(e.InsufficientBalance="InsufficientBalance",e.SimulateEventError="simulateEventError",e.CannotGetDecimals="CannotGetDecimals",e.MissCoinA="MissCoinA",e.MissCoinB="MissCoinB",e.MissTurbosFeeType="MissTurbosFeeType",e.MissAftermathLpSupplyType="MissAftermathLpSupplyType",e))(rl||{}),nl=(e=>(e[e.NumberTooLarge=1e3]="NumberTooLarge",e[e.RateLimitExceeded=1001]="RateLimitExceeded",e[e.InsufficientLiquidity=1002]="InsufficientLiquidity",e[e.HoneyPot=1003]="HoneyPot",e))(nl||{});function Mn(e){switch(e){case 1e3:return"Number too large";case 1001:return"Rate limit exceeded";case 1002:return"Insufficient liquidity";case 1003:return"HoneyPot scam detected";default:return"Unknown error"}}var xc=class ol extends Error{constructor(t,i){super(t),this.message=t,this.errorCode=i}static isAggregatorErrorCode(t,i){return t instanceof ol&&t.errorCode===i}},Nc=0,sl=1,Rc=2;function qa(e,t){return e===t?Nc:e<t?sl:Rc}function Lc(e,t){let i=0,r=e.length<=t.length?e.length:t.length,n=qa(e.length,t.length);for(;i<r;){let s=qa(e.charCodeAt(i),t.charCodeAt(i));if(i+=1,s!==0)return s}return n}function Fc(e,t){return Lc(e,t)===sl}function No(e,...t){let i=Array.isArray(t[t.length-1])?t.pop():[],n=[e,...t].filter(Boolean).join("::");return i&&i.length&&(n+=`<${i.join(", ")}>`),n}function Dc(e){return e.split("::")[0]}function _r(e){var t;try{let i=e.replace(/\s/g,""),r=i.match(/(<.+>)$/),n=(t=r?.[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(n){i=i.slice(0,i.indexOf("<"));let p=_r(i),g=Sn(Hr({},p),{type_arguments:n.map(v=>_r(v).source_address)});return g.type_arguments=g.type_arguments.map(v=>ci.isSuiCoin(v)?v:_r(v).source_address),g.source_address=No(g.full_address,g.type_arguments),g}let s=i.split("::"),c={full_address:i,address:i===$o||i===ul?"0x2":pt.normalizeSuiObjectId(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return c.full_address=`${c.address}::${c.module}::${c.name}`,c.source_address=No(c.full_address,c.type_arguments),c}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function Ro(e){return _r(e).source_address}function al(e){return e.toLowerCase().startsWith("0x")?pt.normalizeSuiObjectId(e):e}function ll(e){for(let t in e){let i=typeof e[t];if(i==="object")ll(e[t]);else if(i==="string"){let r=e[t];e[t]=al(r)}}}function Bc(e,t,i){return`${e}::${t}::${i}`}var Uc="0x2::coin::Coin",jc=/^0x2::coin::Coin<(.+)>$/,qc=1e3,$c=500,Hc=100,Gc=100,Vc=1e3,$o="0x2::sui::SUI",ul="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Zc="SUI",Kc=450,Wc="0x0000000000000000000000000000000000000005",ci=class Gi{static getCoinTypeArg(t){let i=t.type.match(jc);return i?i[1]:null}static isSUI(t){let i=Gi.getCoinTypeArg(t);return i?Gi.getCoinSymbol(i)==="SUI":!1}static getCoinSymbol(t){return t.substring(t.lastIndexOf(":")+1)}static getBalance(t){return BigInt(t.fields.balance)}static totalBalance(t,i){let r=BigInt(0);return t.forEach(n=>{i===n.coinAddress&&(r+=BigInt(n.balance))}),r}static getID(t){return t.fields.id.id}static getCoinTypeFromArg(t){return`${Uc}<${t}>`}static getCoinAssets(t,i){let r=[];return i.forEach(n=>{Ro(n.coinAddress)===Ro(t)&&r.push(n)}),r}static isSuiCoin(t){return _r(t).full_address===$o}static selectCoinObjectIdGreaterThanOrEqual(t,i,r=[]){let n=Gi.selectCoinAssetGreaterThanOrEqual(t,i,r),s=n.selectedCoins.map(p=>p.coinObjectId),a=n.remainingCoins,c=n.selectedCoins.map(p=>p.balance.toString());return{objectArray:s,remainCoins:a,amountArray:c}}static selectCoinAssetGreaterThanOrEqual(t,i,r=[]){let n=Gi.sortByBalance(t.filter(g=>!r.includes(g.coinObjectId))),s=Gi.calculateTotalBalance(n);if(s<i)return{selectedCoins:[],remainingCoins:n};if(s===i)return{selectedCoins:n,remainingCoins:[]};let a=BigInt(0),c=[],p=[...n];for(;a<s;){let g=i-a,v=p.findIndex(A=>A.balance>=g);if(v!==-1){c.push(p[v]),p.splice(v,1);break}let y=p.pop();y.balance>0&&(c.push(y),a+=y.balance)}return{selectedCoins:Gi.sortByBalance(c),remainingCoins:Gi.sortByBalance(p)}}static sortByBalance(t){return t.sort((i,r)=>i.balance<r.balance?-1:i.balance>r.balance?1:0)}static sortByBalanceDes(t){return t.sort((i,r)=>i.balance>r.balance?-1:i.balance<r.balance?0:1)}static calculateTotalBalance(t){return t.reduce((i,r)=>i+r.balance,BigInt(0))}};function Oi(e){let t=e.indexOf("::");if(t===-1)return e;let i=e.substring(0,t),r=e.substring(t);if(!i.startsWith("0x"))return e;let n=i.substring(2);return n.length>64?e:`0x${n.padStart(64,"0")}${r}`}function cl(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t],arguments:[]})}function dl(e,t){e=Oi(e),t=Oi(t);let i=Math.min(e.length,t.length);for(let r=0;r<i;r++){if(e[r]>t[r])return!0;if(e[r]<t[r])return!1}return!0}function zc(e){let t=/,([^,>]*>)/g,i=[...e.matchAll(t)];if(i.length>0){let r=i[i.length-1][1];return r.substring(0,r.length-1).trim()}return null}function Xc(e){let t=/<([^>]*)>/,i=e.match(t);if(i)return i[1]}function Jc(e,t,i,r){let n=ci.getCoinAssets(r,t);if(i===BigInt(0))return ci.isSuiCoin(r)||n.length===0&&!ci.isSuiCoin(r)?{targetCoin:cl(e,r),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(n[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(n[0].balance.toString())};if(ci.calculateTotalBalance(n)<i)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+r,"InsufficientBalance"+r);if(ci.isSuiCoin(r))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(i.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(i.toString())};let a=ci.sortByBalance(n);a.slice(0,3).reduce((A,k)=>A+k.balance,BigInt(0))<BigInt(i)&&(a=ci.sortByBalanceDes(n));let p=ci.selectCoinObjectIdGreaterThanOrEqual(a,i),[g,...v]=p.objectArray;return v.length>0&&e.mergeCoins(g,v.map(A=>e.object(A))),{targetCoin:e.splitCoins(e.object(g),[e.pure.u64(i.toString())]),isMintZeroCoin:!1,targetCoinAmount:Number(i.toString())}}var Kr=wr(br()),sr=new Kr.default(0),Yc=new Kr.default(1),hl=new Kr.default(2),Qc=hl.pow(new Kr.default(128)),ed=new Kr.default("18446744073709551615"),Cn="18446744073709551615",td=1e9,id="aggregator",rd="CETUS",nd="DEEPBOOK",od="KRIYA",sd="FLOWX",ad="TURBOS",ld="AFTERMATH",ud="integrate",cd="cetus",dd="deepbook",hd="kriya",fd="utils",pd="pool",md="pay",gd="flowx_amm",_d="turbos",vd="aftermath",fl="custodian_v2",pl="clob_v2",wd="flash_swap",bd="flash_swap_with_partner",yd="repay_flash_swap",Md="repay_flash_swap_with_partner",Ad="flash_swap_a2b",Sd="flash_swap_b2a",Cd="flash_swap_with_partner_a2b",Ed="flash_swap_with_partner_b2a",Id="repay_flash_swap_a2b",kd="repay_flash_swap_b2a",Td="repay_flash_swap_with_partner_a2b",Od="repay_flash_swap_with_partner_b2a",Pd="swap_a2b",xd="swap_b2a",Nd="transfer_or_destroy_coin",Rd="check_coins_threshold",Ld="join_vec",Fd="transfer_account_cap",Dd="0x0000000000000000000000000000000000000000000000000000000000000006",Bd="0x1::coin::CoinInfo",Ud="0x1::coin::CoinStore",jd="0x2::coin::zero",ml="0x000000000000000000000000000000000000000000000000000000000000dee9",gl="0x000000000000000000000000000000000000000000000000000000000000dee9",qd="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",_l="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",$d="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",Hd="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",Gd="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",Vd="",Zd="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",Kd="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",Wd="",zd="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",Xd="",Jd="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",Yd="",Qd="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",eh="",th="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",ih="",Gr={AGGREGATOR_V3:"aggregator_v3"},rh="https://api-sui.cetus.zone/router_v3",nh="https://api-sui.cetus.zone/router_v2",oh={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},Pn={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},Vr={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},ki={DEFAULT_PYTH_URL:"https://hermes.pyth.network",PYTH_TIMEOUT:3e3,MAX_OVERLAY_FEE_RATE:.1,FEE_RATE_MULTIPLIER:1e6,DEFAULT_OVERLAY_FEE_RECEIVER:"0x0",ERRORS:{SIGNER_REQUIRED:"Signer is required, but not provided.",INVALID_OVERLAY_FEE_RATE:"Overlay fee rate must be between 0 and 0.1",INVALID_SLIPPAGE:"Invalid slippage value. Must be between 0 and 1 (e.g., 0.01 represents 1% slippage)",NO_ROUTER_FOUND:"No router found",EMPTY_PATH:"Empty path",UNSUPPORTED_DEX:"Unsupported dex",PYTH_UNAVAILABLE:"All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",QUOTE_ID_REQUIRED:"Quote ID is required",AGGREGATOR_V3_PACKAGE_REQUIRED:"Aggregator V3 package is required",PACKAGES_REQUIRED:"Packages are required"}},Qe={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:Cn,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},vl=1010102;function sh(e,t){let i=new Map;return e.packages&&(e.packages instanceof Map?i=e.packages:typeof e.packages=="object"&&Object.entries(e.packages).forEach(([r,n])=>{i.set(r,n)})),{quoteID:e.request_id||"",amountIn:new mr.default(e.amount_in.toString()),amountOut:new mr.default(e.amount_out.toString()),byAmountIn:t,insufficientLiquidity:!1,packages:i,paths:e.paths.map(r=>({id:r.id,direction:r.direction,provider:r.provider,from:r.from,target:r.target,feeRate:r.fee_rate,amountIn:r.amount_in.toString(),amountOut:r.amount_out.toString(),version:r.version,publishedAt:r.published_at,extendedDetails:r.extended_details}))}}function wl(e,t,i,r,n){return It(this,null,function*(){let s;if(i.liquidityChanges&&i.liquidityChanges.length>0?s=yield lh(e,i):s=yield ah(e,t,i),!s)return null;if(!s.ok){let p=1e3;return s.status===429&&(p=1001),{quoteID:"",amountIn:sr,amountOut:sr,paths:[],byAmountIn:i.byAmountIn,insufficientLiquidity:!1,deviationRatio:0,error:{code:p,msg:Mn(p)}}}let a=Mc.default.parse(yield s.text()),c=a.msg==="liquidity is not enough";if(a.msg&&a.msg.indexOf("HoneyPot scam")>-1)return{quoteID:"",amountIn:sr,amountOut:sr,paths:[],byAmountIn:i.byAmountIn,insufficientLiquidity:c,deviationRatio:0,error:{code:1003,msg:Mn(1003)}};if(a.data!=null){let p=sh(a.data,i.byAmountIn);if(r>0&&n!=="0x0")if(i.byAmountIn){let g=p.amountOut.mul(new mr.default(r)).div(new mr.default(1e6));p.overlayFee=Number(g.toString()),p.amountOut=p.amountOut.sub(g)}else{let g=p.amountIn.mul(new mr.default(r)).div(new mr.default(1e6));p.overlayFee=Number(g.toString()),p.amountIn=p.amountIn.add(g)}return p.packages||(p.packages=new Map),p.packages.has("aggregator_v3")||p.packages.set("aggregator_v3","0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"),p}return{quoteID:"",amountIn:sr,amountOut:sr,paths:[],insufficientLiquidity:c,byAmountIn:i.byAmountIn,deviationRatio:0,error:{code:1002,msg:Mn(1002)}}})}function ah(e,t,i){return It(this,null,function*(){try{let{from:r,target:n,amount:s,byAmountIn:a,depth:c,splitAlgorithm:p,splitFactor:g,splitCount:v,providers:y}=i,A=Oi(r),k=Oi(n),U=`${e}/find_routes?from=${A}&target=${k}&amount=${s.toString()}&by_amount_in=${a}`;return c&&(U+=`&depth=${c}`),p&&(U+=`&split_algorithm=${p}`),g&&(U+=`&split_factor=${g}`),v&&(U+=`&split_count=${v}`),y&&y.length>0&&(U+=`&providers=${y.join(",")}`),t.length>0&&(U+=`&apiKey=${t}`),U+=`&v=${vl}`,console.log("url",U),yield fetch(U)}catch(r){return console.error(r),null}})}function lh(e,t){return It(this,null,function*(){let{from:i,target:r,amount:n,byAmountIn:s,depth:a,splitAlgorithm:c,splitFactor:p,splitCount:g,providers:v,liquidityChanges:y}=t,A=Oi(i),k=Oi(r),U=`${e}/find_routes`,P=v?.join(","),W={from:A,target:k,amount:Number(n.toString()),by_amount_in:s,depth:a,split_algorithm:c,split_factor:p,split_count:g,providers:P,liquidity_changes:y.map(j=>({pool:j.poolID,tick_lower:j.ticklower,tick_upper:j.tickUpper,delta_liquidity:j.deltaLiquidity})),v:vl};try{return yield fetch(U,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W)})}catch(j){return console.error("Error:",j),null}})}function uh(e){return It(this,null,function*(){let t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(i){return console.error("Error:",i),null}})}function Lo(e){let t=e.paths,i=t[0].from,r=t[t.length-1].target,n=[];for(let a of t)n.push({path:a,isLastUseOfIntermediateToken:!1});let s=new Map;for(let a=n.length-1;a>=0;a--){let{from:c}=n[a].path;s.has(c)||(s.set(c,!0),n[a].isLastUseOfIntermediateToken=!0)}return console.log("flattenedPaths",n),{quoteID:e.quoteID||"",amountIn:e.amountIn,amountOut:e.amountOut,byAmountIn:e.byAmountIn,flattenedPaths:n,fromCoinType:i,targetCoinType:r,packages:e.packages,totalDeepFee:e.totalDeepFee,error:e.error,overlayFee:e.overlayFee}}var bl=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(bl||{}),ch=class{constructor(e,t,i,r){this.endpoint=e,this.fullNodeUrl=t,this.signer=i,this.env=r}getAggregatorUrl(){return this.endpoint}getFullNodeUrl(){return this.fullNodeUrl}getWallet(){return this.signer}getENV(){return this.env}},dh=wr(br()),gr=9e15,Wi=1e9,Fo="0123456789abcdef",En="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",In="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Do={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-gr,maxE:gr,crypto:!1},yl,Ti,Fe=!0,xn="[DecimalError] ",Ki=xn+"Invalid argument: ",Ml=xn+"Precision limit exceeded",Al=xn+"crypto unavailable",Sl="[object Decimal]",xt=Math.floor,yt=Math.pow,hh=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,fh=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,ph=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Cl=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,hi=1e7,xe=7,mh=9007199254740991,gh=En.length-1,Bo=In.length-1,ne={toStringTag:Sl};ne.absoluteValue=ne.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Te(e)};ne.ceil=function(){return Te(new this.constructor(this),this.e+1,2)};ne.clampedTo=ne.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(Ki+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};ne.comparedTo=ne.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};ne.cosine=ne.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+xe,r.rounding=1,i=_h(r,Ol(r,i)),r.precision=e,r.rounding=t,Te(Ti==2||Ti==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};ne.cubeRoot=ne.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for(Fe=!1,s=v.s*yt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=kt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=yt(i,1/3),e=xt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=it(g.plus(v).times(c),g.plus(p),a+2,1),kt(c.d).slice(0,a)===(i=kt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Te(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(Te(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return Fe=!0,Te(r,e,y.rounding,t)};ne.decimalPlaces=ne.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-xt(this.e/xe))*xe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};ne.dividedBy=ne.div=function(e){return it(this,new this.constructor(e))};ne.dividedToIntegerBy=ne.divToInt=function(e){var t=this,i=t.constructor;return Te(it(t,new i(e),0,1,1),i.precision,i.rounding)};ne.equals=ne.eq=function(e){return this.cmp(e)===0};ne.floor=function(){return Te(new this.constructor(this),this.e+1,3)};ne.greaterThan=ne.gt=function(e){return this.cmp(e)>0};ne.greaterThanOrEqualTo=ne.gte=function(e){var t=this.cmp(e);return t==1||t===0};ne.hyperbolicCosine=ne.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/Rn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=vr(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return Te(s,a.precision=i,a.rounding=r,!0)};ne.hyperbolicSine=ne.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=vr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Rn(5,e)),n=vr(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,Te(n,t,i,!0)};ne.hyperbolicTangent=ne.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,it(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};ne.inverseCosine=ne.acos=function(){var e,t=this,i=t.constructor,r=t.abs().cmp(1),n=i.precision,s=i.rounding;return r!==-1?r===0?t.isNeg()?di(i,n,s):new i(0):new i(NaN):t.isZero()?di(i,n+4,s).times(.5):(i.precision=n+6,i.rounding=1,t=t.asin(),e=di(i,n+4,s).times(.5),i.precision=n,i.rounding=s,e.minus(t))};ne.inverseHyperbolicCosine=ne.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,Fe=!1,i=i.times(i).minus(1).sqrt().plus(i),Fe=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};ne.inverseHyperbolicSine=ne.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,Fe=!1,i=i.times(i).plus(1).sqrt().plus(i),Fe=!0,r.precision=e,r.rounding=t,i.ln())};ne.inverseHyperbolicTangent=ne.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?Te(new s(n),e,t,!0):(s.precision=i=r-n.e,n=it(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};ne.inverseSine=ne.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=di(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};ne.inverseTangent=ne.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=Bo)return a=di(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=Bo)return a=di(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/xe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Fe=!1,t=Math.ceil(c/xe),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),Fe=!0,Te(a,v.precision=y,v.rounding=A,!0)};ne.isFinite=function(){return!!this.d};ne.isInteger=ne.isInt=function(){return!!this.d&&xt(this.e/xe)>this.d.length-2};ne.isNaN=function(){return!this.s};ne.isNegative=ne.isNeg=function(){return this.s<0};ne.isPositive=ne.isPos=function(){return this.s>0};ne.isZero=function(){return!!this.d&&this.d[0]===0};ne.lessThan=ne.lt=function(e){return this.cmp(e)<0};ne.lessThanOrEqualTo=ne.lte=function(e){return this.cmp(e)<1};ne.logarithm=ne.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if(Fe=!1,c=y+k,a=Zi(g,c),r=t?kn(v,c+10):Zi(e,c),p=it(a,r,c,1),Zr(p.d,n=y,A))do if(c+=10,a=Zi(g,c),r=t?kn(v,c+10):Zi(e,c),p=it(a,r,c,1),!s){+kt(p.d).slice(n+1,n+15)+1==1e14&&(p=Te(p,y+1,0));break}while(Zr(p.d,n+=10,A));return Fe=!0,Te(p,y,A)};ne.minus=ne.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return Fe?Te(e,c,p):e}if(i=xt(e.e/xe),v=xt(k.e/xe),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/xe),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=hi-1;--g[n],g[r]+=hi}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=Nn(g,i),Fe?Te(e,c,p):e):new U(p===3?-0:0)};ne.modulo=ne.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?Te(new r(i),r.precision,r.rounding):(Fe=!1,r.modulo==9?(t=it(i,e.abs(),0,3,1),t.s*=e.s):t=it(i,e,0,r.modulo,1),t=t.times(e),Fe=!0,i.minus(t))};ne.naturalExponential=ne.exp=function(){return Uo(this)};ne.naturalLogarithm=ne.ln=function(){return Zi(this)};ne.negated=ne.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Te(e)};ne.plus=ne.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),Fe?Te(e,c,p):e;if(s=xt(y.e/xe),r=xt(e.e/xe),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/xe),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/hi|0,g[n]%=hi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=Nn(g,r),Fe?Te(e,c,p):e};ne.precision=ne.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Ki+e);return i.d?(t=El(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};ne.round=function(){var e=this,t=e.constructor;return Te(new t(e),e.e+1,t.rounding)};ne.sine=ne.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+xe,r.rounding=1,i=wh(r,Ol(r,i)),r.precision=e,r.rounding=t,Te(Ti>2?i.neg():i,e,t,!0)):new r(NaN)};ne.squareRoot=ne.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for(Fe=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=kt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=xt((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(it(a,s,i+2,1)).times(.5),kt(s.d).slice(0,i)===(t=kt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Te(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Te(r,p+1,1),e=!r.times(r).eq(a));break}return Fe=!0,Te(r,p,v.rounding,e)};ne.tangent=ne.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=it(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Te(Ti==2||Ti==4?i.neg():i,e,t,!0)):new r(NaN)};ne.times=ne.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=xt(v.e/xe)+xt(e.e/xe),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%hi|0,t=c/hi|0;s[n]=(s[n]+t)%hi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=Nn(s,i),Fe?Te(e,y.precision,y.rounding):e};ne.toBinary=function(e,t){return Ho(this,2,e,t)};ne.toDecimalPlaces=ne.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Ft(e,0,Wi),t===void 0?t=r.rounding:Ft(t,0,8),Te(i,e+i.e+1,t))};ne.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=yi(r,!0):(Ft(e,0,Wi),t===void 0?t=n.rounding:Ft(t,0,8),r=Te(new n(r),e+1,t),i=yi(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};ne.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=yi(n):(Ft(e,0,Wi),t===void 0?t=s.rounding:Ft(t,0,8),r=Te(new s(n),e+n.e+1,t),i=yi(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};ne.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=El(U)-k.e-1,a=s%xe,t.d[0]=yt(10,a<0?xe+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(Ki+c);e=c.gt(t)?s>0?t:g:c}for(Fe=!1,c=new P(kt(U)),v=P.precision,P.precision=s=U.length*xe*2;y=it(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=it(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=it(g,r,s,1).minus(k).abs().cmp(it(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,Fe=!0,A};ne.toHexadecimal=ne.toHex=function(e,t){return Ho(this,16,e,t)};ne.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Ft(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(Fe=!1,i=it(i,e,0,t,1).times(e),Fe=!0,Te(i)):(e.s=i.s,i=e),i};ne.toNumber=function(){return+this};ne.toOctal=function(e,t){return Ho(this,8,e,t)};ne.toPower=ne.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(yt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Te(c,r,s);if(t=xt(e.e/xe),t>=e.d.length-1&&(i=g<0?-g:g)<=mh)return n=Il(p,c,i,r),e.s<0?new p(1).div(n):Te(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=yt(+c,g),t=i==0||!isFinite(i)?xt(g*(Math.log("0."+kt(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):(Fe=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Uo(e.times(Zi(c,r+i)),r),n.d&&(n=Te(n,r+5,1),Zr(n.d,r,s)&&(t=r+10,n=Te(Uo(e.times(Zi(c,t+i)),t),t+5,1),+kt(n.d).slice(r+1,r+15)+1==1e14&&(n=Te(n,r+1,0)))),n.s=a,Fe=!0,p.rounding=s,Te(n,r,s))};ne.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=yi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Ft(e,1,Wi),t===void 0?t=n.rounding:Ft(t,0,8),r=Te(new n(r),e,t),i=yi(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};ne.toSignificantDigits=ne.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Ft(e,1,Wi),t===void 0?t=r.rounding:Ft(t,0,8)),Te(new r(i),e,t)};ne.toString=function(){var e=this,t=e.constructor,i=yi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};ne.truncated=ne.trunc=function(){return Te(new this.constructor(this),this.e+1,1)};ne.valueOf=ne.toJSON=function(){var e=this,t=e.constructor,i=yi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function kt(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=xe-r.length,i&&(s+=Vi(i)),s+=r;a=e[t],r=a+"",i=xe-r.length,i&&(s+=Vi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Ft(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Ki+e)}function Zr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=xe,n=0):(n=Math.ceil((t+1)/xe),t%=xe),s=yt(10,xe-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==yt(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==yt(10,t-3)-1,a}function An(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=Fo.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function _h(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Rn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=vr(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var it=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,ae,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=hi,k=xe,v=xt(r.e/k)-xt(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,yl=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Te(j,c?s+j.e+1:s,a,U)}return j}})();function Te(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=xe,a=t,v=y[A=0],p=v/yt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/xe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=xe,a=s-xe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=xe,a=s-xe+n,p=a<0?0:v/yt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%yt(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/yt(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=yt(10,(xe-t%xe)%xe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=yt(10,xe-s),y[A]=a>0?(v/yt(10,n-a)%yt(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==hi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=hi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return Fe&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function yi(e,t,i){if(!e.isFinite())return Tl(e);var r,n=e.e,s=kt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Vi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Vi(-n-1)+s,i&&(r=i-a)>0&&(s+=Vi(r))):n>=a?(s+=Vi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Vi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Vi(r))),s}function Nn(e,t){var i=e[0];for(t*=xe;i>=10;i/=10)t++;return t}function kn(e,t,i){if(t>gh)throw Fe=!0,i&&(e.precision=i),Error(Ml);return Te(new e(En),t,1,!0)}function di(e,t,i){if(t>Bo)throw Error(Ml);return Te(new e(In),t,i,!0)}function El(e){var t=e.length-1,i=t*xe+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function Vi(e){for(var t="";e--;)t+="0";return t}function Il(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/xe+4);for(Fe=!1;;){if(i%2&&(s=s.times(t),Ha(s.d,a)&&(n=!0)),i=xt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),Ha(t.d,a)}return Fe=!0,s}function $a(e){return e.d[e.d.length-1]&1}function kl(e,t,i){for(var r,n=new e(t[0]),s=0;++s<t.length;)if(r=new e(t[s]),r.s)n[i](r)&&(n=r);else{n=r;break}return n}function Uo(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(Fe=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(yt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Te(s.times(e),p,1),i=i.times(++v),c=a.plus(it(s,i,p,1)),kt(c.d).slice(0,p)===kt(a.d).slice(0,p)){for(n=y;n--;)a=Te(a.times(a),p,1);if(t==null)if(g<3&&Zr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Te(a,A.precision=U,k,Fe=!0);else return A.precision=U,a}a=c}}function Zi(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?(Fe=!1,v=X):v=t,j.precision=v+=U,i=kt(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=kt(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=kn(j,v+2,X).times(s+""),P=Zi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Te(P,X,K,Fe=!0):P;for(y=P,p=a=P=it(P.minus(1),P.plus(1),v,1),A=Te(P.times(P),v,1),n=3;;){if(a=Te(a.times(A),v,1),g=p.plus(it(a,new j(n),v,1)),kt(g.d).slice(0,v)===kt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(kn(j,v+2,X).times(s+""))),p=it(p,new j(k),v,1),t==null)if(Zr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=it(y.minus(1),y.plus(1),v,1),A=Te(P.times(P),v,1),n=c=1;else return Te(p,j.precision=X,K,Fe=!0);else return j.precision=X,p;p=g,n+=2}}function Tl(e){return String(e.s*e.s/0)}function jo(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%xe,i<0&&(r+=xe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=xe;r<n;)e.d.push(+t.slice(r,r+=xe));t=t.slice(r),r=xe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),Fe&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function vh(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Cl.test(t))return jo(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(fh.test(t))i=16,t=t.toLowerCase();else if(hh.test(t))i=2;else if(ph.test(t))i=8;else throw Error(Ki+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=Il(r,new r(i),s,s*2)),g=An(t,i,hi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=Nn(g,v),e.d=g,Fe=!1,a&&(e=it(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?yt(2,p):Wr.pow(2,p))),Fe=!0,e)}function wh(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:vr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Rn(5,i)),t=vr(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function vr(e,t,i,r,n){var s,a,c,p,g=e.precision,v=Math.ceil(g/xe);for(Fe=!1,p=i.times(i),c=new e(r);;){if(a=it(c.times(p),new e(t++*t++),g,1),c=n?r.plus(a):r.minus(a),r=it(a.times(p),new e(t++*t++),g,1),a=c.plus(r),a.d[v]!==void 0){for(s=v;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s}return Fe=!0,a.d.length=v+1,a}function Rn(e,t){for(var i=e;--t;)i*=e;return i}function Ol(e,t){var i,r=t.s<0,n=di(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ti=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ti=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ti=$a(i)?r?2:3:r?4:1,t;Ti=$a(i)?r?1:4:r?3:2}return t.minus(n).abs()}function Ho(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Ft(i,1,Wi),r===void 0?r=k.rounding:Ft(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Tl(e);else{for(v=yi(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=An(yi(A),10,n),A.e=A.d.length),y=An(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=it(e,A,i,r,0,n),y=e.d,s=e.e,g=yl),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=Fo.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=An(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=Fo.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function Ha(e,t){if(e.length>t)return e.length=t,!0}function bh(e){return new this(e).abs()}function yh(e){return new this(e).acos()}function Mh(e){return new this(e).acosh()}function Ah(e,t){return new this(e).plus(t)}function Sh(e){return new this(e).asin()}function Ch(e){return new this(e).asinh()}function Eh(e){return new this(e).atan()}function Ih(e){return new this(e).atanh()}function kh(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=di(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?di(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=di(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(it(e,t,s,1)),t=di(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(it(e,t,s,1)),i}function Th(e){return new this(e).cbrt()}function Oh(e){return Te(e=new this(e),e.e+1,2)}function Ph(e,t,i){return new this(e).clamp(t,i)}function xh(e){if(!e||typeof e!="object")throw Error(xn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Wi,"rounding",0,8,"toExpNeg",-gr,0,"toExpPos",0,gr,"maxE",0,gr,"minE",-gr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=Do[i]),(r=e[i])!==void 0)if(xt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(Ki+i+": "+r);if(i="crypto",n&&(this[i]=Do[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(Al);else this[i]=!1;else throw Error(Ki+i+": "+r);return this}function Nh(e){return new this(e).cos()}function Rh(e){return new this(e).cosh()}function Pl(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,Ga(s)){g.s=s.s,Fe?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;Fe?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}else if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return jo(g,s.toString())}else if(p!=="string")throw Error(Ki+s);return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Cl.test(s)?jo(g,s):vh(g,s)}if(n.prototype=ne,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=xh,n.clone=Pl,n.isDecimal=Ga,n.abs=bh,n.acos=yh,n.acosh=Mh,n.add=Ah,n.asin=Sh,n.asinh=Ch,n.atan=Eh,n.atanh=Ih,n.atan2=kh,n.cbrt=Th,n.ceil=Oh,n.clamp=Ph,n.cos=Nh,n.cosh=Rh,n.div=Lh,n.exp=Fh,n.floor=Dh,n.hypot=Bh,n.ln=Uh,n.log=jh,n.log10=$h,n.log2=qh,n.max=Hh,n.min=Gh,n.mod=Vh,n.mul=Zh,n.pow=Kh,n.random=Wh,n.round=zh,n.sign=Xh,n.sin=Jh,n.sinh=Yh,n.sqrt=Qh,n.sub=ef,n.sum=tf,n.tan=rf,n.tanh=nf,n.trunc=of,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function Lh(e,t){return new this(e).div(t)}function Fh(e){return new this(e).exp()}function Dh(e){return Te(e=new this(e),e.e+1,3)}function Bh(){var e,t,i=new this(0);for(Fe=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return Fe=!0,new this(1/0);i=t}return Fe=!0,i.sqrt()}function Ga(e){return e instanceof Wr||e&&e.toStringTag===Sl||!1}function Uh(e){return new this(e).ln()}function jh(e,t){return new this(e).log(t)}function qh(e){return new this(e).log(2)}function $h(e){return new this(e).log(10)}function Hh(){return kl(this,arguments,"lt")}function Gh(){return kl(this,arguments,"gt")}function Vh(e,t){return new this(e).mod(t)}function Zh(e,t){return new this(e).mul(t)}function Kh(e,t){return new this(e).pow(t)}function Wh(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Ft(e,1,Wi),r=Math.ceil(e/xe),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(Al);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=xe,r&&e&&(n=yt(10,xe-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=xe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<xe&&(i-=xe-r)}return a.e=i,a.d=c,a}function zh(e){return Te(e=new this(e),e.e+1,this.rounding)}function Xh(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Jh(e){return new this(e).sin()}function Yh(e){return new this(e).sinh()}function Qh(e){return new this(e).sqrt()}function ef(e,t){return new this(e).sub(t)}function tf(){var e=0,t=arguments,i=new this(t[e]);for(Fe=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return Fe=!0,Te(i,this.precision,this.rounding)}function rf(e){return new this(e).tan()}function nf(e){return new this(e).tanh()}function of(e){return Te(e=new this(e),e.e+1,1)}ne[Symbol.for("nodejs.util.inspect.custom")]=ne.toString;ne[Symbol.toStringTag]="Decimal";var Wr=ne.constructor=Pl(Do);En=new Wr(En);In=new Wr(In);var Tn=Wr;function sf(e,t,i){return Number(xl(new Tn(e.toString()),t,i).toFixed(0))}function Va(e,t,i){let r=xl(new Tn(e.toString()),t,i);return new dh.default(r.toFixed(0))}function xl(e,t,i){return t?e.mul(1-i):e.mul(1+i)}var Za=class{constructor(e,t){if(e!==0)throw new Error("CetusRouter only supported on mainnet");this.globalConfig=e===0?"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f":"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",this.partner=t??(e===0?"0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b":"0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Cetus not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.object(this.partner),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::cetus::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}flashSwapFixedOutput(e,t,i,r){let n=[r,e.object(this.globalConfig),e.object(t.id),e.object(this.partner),i,e.pure.bool(t.direction),e.pure.bool(!1),e.object(pt.SUI_CLOCK_OBJECT_ID)],[s,a]=t.direction?[t.from,t.target]:[t.target,t.from],[c,p]=e.moveCall({target:`${t.publishedAt}::cetus::flash_swap_fixed_output`,typeArguments:[s,a],arguments:n});return{flashReceipt:c,repayAmount:p}}repayFlashSwapFixedOutput(e,t,i,r){let n=[i,e.object(this.globalConfig),e.object(t.id),e.object(this.partner),e.pure.bool(t.direction),r],[s,a]=t.direction?[t.from,t.target]:[t.target,t.from];e.moveCall({target:`${t.publishedAt}::cetus::repay_flash_swap_fixed_output`,typeArguments:[s,a],arguments:n})}add(e,t,i,r){let n=[t,i];return e.moveCall({target:`${r}::cetus::add`,typeArguments:[],arguments:n})}sub(e,t,i,r){let n=[t,i];return e.moveCall({target:`${r}::cetus::sub`,typeArguments:[],arguments:n})}},af=class{constructor(e){if(e!==0)throw new Error("Kriya V3 only supported on mainnet");this.version="0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Kriya V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.version),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::kriya_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},lf=class{constructor(e){if(e!==0)throw new Error("FlowX V3 only supported on mainnet");this.poolRegistry="0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc",this.versioned="0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("FlowX V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,s=t.feeRate*1e6;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id,feeRate:s}}executeSwapContract(e,t,i){let r=[i,e.object(this.poolRegistry),e.object(this.versioned),e.pure.u64(t.feeRate),e.pure.u64(t.amountIn),e.pure.bool(t.direction),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::flowx_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},uf=class{constructor(e){if(e!==0)throw new Error("Turbos only supported on mainnet");this.versioned="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Turbos not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;if(t.extendedDetails==null)throw new Error("Extended details not supported");if(t.extendedDetails.turbos_fee_type==null)throw new Error("Turbos fee type not supported");let s=t.extendedDetails.turbos_fee_type;return{coinAType:i,coinBType:r,feeType:s,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.versioned),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::turbos::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},cf=class{constructor(e){if(e!==0)throw new Error("Bluefin only supported on mainnet");this.globalConfig="0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Bluefin not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::bluefin::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},df=class{constructor(e){if(e!==0)throw new Error("Momentum only supported on mainnet");this.version="0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Momentum not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(this.version),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::momentum::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},hf=class{constructor(e){if(e!==0)throw new Error("Magma only supported on mainnet");this.globalConfig="0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Magma not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::magma::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ff=class{constructor(e){if(e!==0)throw new Error("Kriya V2 only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Kriya V2 not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::kriya_amm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},pf=class{constructor(e){if(e!==0)throw new Error("FlowX V2 only supported on mainnet");this.container="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("FlowX V2 not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.container),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::flowx_amm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},mf=class{constructor(e){if(e!==0)throw new Error("BlueMove only supported on mainnet");this.dexInfo="0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("BlueMove not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.dexInfo),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::bluemove::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},gf=class{constructor(e){if(e!==0)throw new Error("DeepBook V3 only supported on mainnet");this.env=e,this.globalConfig="0x699d455ab8c5e02075b4345ea1f91be55bf46064ae6026cc2528e701ce3ac135"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i,r)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("DeepBook V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i,r){let n=r?.deepbookv3DeepFee||e.moveCall({target:"0x2::coin::zero",typeArguments:[this.getDeepFeeType()]}),s=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.u64(t.amountIn),e.pure.bool(t.direction),n,e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::deepbookv3::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?Vr.Mainnet:Vr.Testnet}},_f=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet");this.poolRegistry="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",this.protocolFeeVault="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",this.treasury="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",this.insuranceFund="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",this.referralVault="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){var t,i;if(e.path.publishedAt==null)throw new Error("Aftermath not set publishedAt");let r=e.path,[n,s]=r.direction?[r.from,r.target]:[r.target,r.from],a=e.isLastUseOfIntermediateToken?"18446744073709551615":r.amountIn;return{coinAType:n,coinBType:s,feeType:((t=r.extendedDetails)==null?void 0:t.aftermath_lp_supply_type)||((i=r.extendedDetails)==null?void 0:i.aftermath_lp_supply_type)||"0x2::sui::SUI",direction:r.direction,amountIn:a,expectAmountOut:r.amountOut,publishedAt:r.publishedAt,poolId:r.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.poolRegistry),e.object(this.protocolFeeVault),e.object(this.treasury),e.object(this.insuranceFund),e.object(this.referralVault),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.pure.u64(t.expectAmountOut)];e.moveCall({target:`${t.publishedAt}::aftermath::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},vf=class{constructor(e){if(e!==0)throw new Error("Steamm CPMM only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type"];for(let i of t)if(e[i]==null)throw new Error(`Steamm CPMM ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm CPMM not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Steamm CPMM");this.validateExtendedDetails(t.extendedDetails);let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],c=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:s,coinBType:a,direction:i,amountIn:c,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.extendedDetails.steamm_bank_a),e.object(t.extendedDetails.steamm_bank_b),e.object(t.extendedDetails.steamm_lending_market),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_cpmm::swap`,typeArguments:[t.extendedDetails.steamm_lending_market_type,t.coinAType,t.coinBType,t.extendedDetails.steamm_btoken_a_type,t.extendedDetails.steamm_btoken_b_type,t.extendedDetails.steamm_lp_token_type],arguments:r})}},wf=class{constructor(e){if(e!==0)throw new Error("Scallop only supported on mainnet");this.version="0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",this.marketData="0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Scallop not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.from,t.target],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;if(t.extendedDetails==null)throw new Error("Extended details not supported");let s=t.extendedDetails.scallopScoinTreasury||t.extendedDetails.scallop_scoin_treasury;if(s==null)throw new Error("Scallop scoin treasury not supported");return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id,scallopScoinTreasury:s}}executeSwapContract(e,t,i){let r=[i,e.object(this.version),e.object(this.marketData),e.object(t.scallopScoinTreasury),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)],n=t.direction?"swap_a2b":"swap_b2a";e.moveCall({target:`${t.publishedAt}::scallop::${n}`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Ka=class{constructor(e){if(e!==0)throw new Error("Springsui only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Springsui not set publishedAt");let i=t.direction?t.target:t.from,r=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{springSUICoinType:i,direction:t.direction,amountIn:r,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object("0x5"),e.pure.u64(t.amountIn),e.pure.bool(t.direction)];e.moveCall({target:`${t.publishedAt}::springsui::swap`,typeArguments:[t.springSUICoinType],arguments:r})}},bf=class{constructor(e,t){if(e!==0)throw new Error("Haedal PMM only supported on mainnet");this.pythPriceIDs=t}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Haedal PMM");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){if(!e.haedal_pmm_base_price_seed)throw new Error("Haedal PMM base price seed not supported");if(!e.haedal_pmm_quote_price_seed)throw new Error("Haedal PMM quote price seed not supported")}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal PMM not set publishedAt");let i=t.extendedDetails,[r,n]=t.direction?[t.from,t.target]:[t.target,t.from],s=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,a=i.haedal_pmm_base_price_seed,c=i.haedal_pmm_quote_price_seed,p=this.pythPriceIDs.get(a),g=this.pythPriceIDs.get(c);if(!p||!g)throw new Error("Haedal HMM requires oracle price IDs for both coins");return{coinAType:r,coinBType:n,basePriceId:p,quotePriceId:g,a2b:t.direction,amountIn:s,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.basePriceId),e.object(t.quotePriceId),e.pure.u64(t.amountIn),e.pure.bool(t.a2b),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},yf=class{constructor(e,t){if(e===1)throw new Error("Obric is not supported on testnet");this.pythStateObjectId="0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Obric not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not supported in obric");let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],c=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,p,g;if(t.extendedDetails.obric_coin_a_price_seed&&t.extendedDetails.obric_coin_b_price_seed)p=this.pythPriceIDs.get(t.extendedDetails.obric_coin_a_price_seed),g=this.pythPriceIDs.get(t.extendedDetails.obric_coin_b_price_seed);else if(t.extendedDetails.obric_coin_a_price_id&&t.extendedDetails.obric_coin_b_price_id)p=t.extendedDetails.obric_coin_a_price_id,g=t.extendedDetails.obric_coin_b_price_id;else throw new Error("Base price id or quote price id not supported");return{coinAType:s,coinBType:a,coinAPriceInfoObjectId:p,coinBPriceInfoObjectId:g,direction:i,amountIn:c,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i){if(!t.coinAPriceInfoObjectId||!t.coinBPriceInfoObjectId)throw new Error("Base price info object id or quote price info object id not found");let r=[i,e.object(t.poolId),e.pure.u64(t.amountIn),e.pure.bool(t.direction),e.object(this.pythStateObjectId),e.object(t.coinAPriceInfoObjectId),e.object(t.coinBPriceInfoObjectId),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::obric::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Mf=class{constructor(e,t){if(e!==0)throw new Error("Sevenk only supported on mainnet");this.oraclePublishedAt="0x8c36ea167c5e6da8c3d60b4fc897416105dcb986471bd81cfbfd38720a4487c0",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i,r)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Sevenk not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Sevenk");let{direction:i,from:r,target:n}=t,[s,a,c]=i?["swap_a2b",r,n]:["swap_b2a",n,r],p=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,g=t.extendedDetails;if(!g.sevenk_coin_a_price_seed||!g.sevenk_coin_b_price_seed||!g.sevenk_oracle_config_a||!g.sevenk_oracle_config_b||!g.sevenk_lp_cap_type)throw new Error("Required Sevenk extended details not found");let v=g.sevenk_coin_a_price_seed,y=g.sevenk_coin_b_price_seed,A=g.sevenk_oracle_config_a,k=g.sevenk_oracle_config_b,U=g.sevenk_lp_cap_type,P=this.pythPriceIDs.get(v),W=this.pythPriceIDs.get(y);if(!P||!W)throw new Error("Sevenk price info object IDs not found");return{func:s,coinAType:a,coinBType:c,coinAPriceId:P,coinBPriceId:W,coinAOracleId:A,coinBOracleId:k,lpCapType:U,direction:i,amountIn:p,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i,r){let n=e.moveCall({target:`${this.oraclePublishedAt}::oracle::new_holder`,typeArguments:[],arguments:[]});e.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[e.object(t.coinAOracleId),n,e.object(t.coinAPriceId),e.object(pt.SUI_CLOCK_OBJECT_ID)]}),e.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[e.object(t.coinBOracleId),n,e.object(t.coinBPriceId),e.object(pt.SUI_CLOCK_OBJECT_ID)]});let s=[i,e.object(t.poolId),n,e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::sevenk::${t.func}`,typeArguments:[t.coinAType,t.coinBType,t.lpCapType],arguments:s})}},Af=class{constructor(e,t){if(e!==0)throw new Error("Steamm OMM only supported on mainnet");this.pythPriceIDs=t,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Steamm OMM");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steammOracleRegistryId","steammOracleIndexA","steammOracleIndexB","steammOraclePythPriceSeedA","steammOraclePythPriceSeedB"];for(let i of t)if(e[i]==null)throw new Error(`Steamm ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm OMM not set publishedAt");let i=t.extendedDetails,{direction:r,from:n,target:s}=t,[a,c,p]=r?["swap_a2b_v2",n,s]:["swap_b2a_v2",s,n],g=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,v=i.steamm_oracle_pyth_price_seed_a,y=i.steamm_oracle_pyth_price_seed_b;if(!v||!y)throw new Error("Steamm oracle price seeds not found");let A=this.pythPriceIDs.get(v),k=this.pythPriceIDs.get(y);if(!A||!k)throw new Error("Base price info object id or quote price info object id not found");return{func:a,coinAType:c,coinBType:p,direction:r,amountIn:g,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:i,priceInfoObjectIdA:A,priceInfoObjectIdB:k}}executeSwapContract(e,t,i){let r=t.extendedDetails,n=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steammOracleRegistryId),e.object(t.priceInfoObjectIdA),e.pure.u64(r.steammOracleIndexA),e.object(pt.SUI_CLOCK_OBJECT_ID)]}),s=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steammOracleRegistryId),e.object(t.priceInfoObjectIdB),e.pure.u64(r.steammOracleIndexB),e.object(pt.SUI_CLOCK_OBJECT_ID)]}),a=[i,e.object(t.poolId),e.object(r.steamm_bank_a),e.object(r.steamm_bank_b),e.object(r.steamm_lending_market),n,s,e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_omm::${t.func}`,typeArguments:[r.steamm_lending_market_type,t.coinAType,t.coinBType,r.steamm_btoken_a_type,r.steamm_btoken_b_type,r.steamm_lp_token_type],arguments:a})}},Sf=class{constructor(e,t){if(e!==0)throw new Error("Steamm OMM V2 only supported on mainnet");this.pythPriceIDs=t,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Steamm OMM V2");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steamm_oracle_registry_id","steamm_oracle_index_a","steamm_oracle_index_b","steamm_oracle_pyth_price_seed_a","steamm_oracle_pyth_price_seed_b"];for(let i of t)if(e[i]==null)throw new Error(`Steamm OMM V2 ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm OMM V2 not set publishedAt");let i=t.extendedDetails,{direction:r,from:n,target:s}=t,[a,c]=r?[n,s]:[s,n],p=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,g=i.steamm_oracle_pyth_price_seed_a,v=i.steamm_oracle_pyth_price_seed_b;if(!g||!v)throw new Error("Steamm OMM V2 oracle price seeds not found");let y=this.pythPriceIDs.get(g),A=this.pythPriceIDs.get(v);if(!y||!A)throw new Error("Base price info object id or quote price info object id not found");return{coinAType:a,coinBType:c,direction:r,amountIn:p,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:i,priceInfoObjectIdA:y,priceInfoObjectIdB:A}}executeSwapContract(e,t,i){let r=t.extendedDetails,n=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steamm_oracle_registry_id),e.object(t.priceInfoObjectIdA),e.pure.u64(r.steamm_oracle_index_a),e.object(pt.SUI_CLOCK_OBJECT_ID)]}),s=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steamm_oracle_registry_id),e.object(t.priceInfoObjectIdB),e.pure.u64(r.steamm_oracle_index_b),e.object(pt.SUI_CLOCK_OBJECT_ID)]}),a=[i,e.object(t.poolId),e.object(r.steamm_bank_a),e.object(r.steamm_bank_b),e.object(r.steamm_lending_market),n,s,e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_omm_v2::swap`,typeArguments:[r.steamm_lending_market_type,t.coinAType,t.coinBType,r.steamm_btoken_a_type,r.steamm_btoken_b_type,r.steamm_lp_token_type],arguments:a})}},Cf="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",Ef="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",If="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",kf=class{constructor(e,t){if(e!==0)throw new Error("Metastable only supported on mainnet");this.versionID="0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t),s=this.createDepositCap(e,n);this.executeSwapContract(e,n,i,s)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Metastable not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Metastable");let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],[c,p]=i?["swap_a2b","create_deposit_cap"]:["swap_b2a","create_withdraw_cap"];if(!t.extendedDetails.metastable_create_cap_pkg_id||!t.extendedDetails.metastable_create_cap_module||!t.extendedDetails.metastable_whitelisted_app_id)throw new Error("CreateCapPkgId or CreateCapModule or WhitelistedAppId not found in extended details");let g=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinType:s,metaCoinType:a,func:c,createCapFunc:p,direction:i,amountIn:g,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}createDepositCap(e,t){let i=[t.metaCoinType];t.extendedDetails.metastable_create_cap_all_type_params&&i.push(t.coinType);let r=[e.object(t.extendedDetails.metastable_whitelisted_app_id),e.object(t.poolId)];switch(t.metaCoinType){case Cf:{if(!t.extendedDetails.metastable_registry_id)throw new Error("Not found registry id for super sui");r.push(e.object(t.extendedDetails.metastable_registry_id));break}case Ef:case If:{if(t.extendedDetails.metastable_price_seed!=null){let n=this.pythPriceIDs.get(t.extendedDetails.metastable_price_seed);if(n==null)throw new Error("Invalid Pyth price feed: "+t.extendedDetails.metastable_price_seed);r.push(e.object(n))}if(t.extendedDetails.metastable_eth_price_seed!=null){let n=this.pythPriceIDs.get(t.extendedDetails.metastable_eth_price_seed);if(n==null)throw new Error("Invalid Pyth price feed: "+t.extendedDetails.metastable_eth_price_seed);r.push(e.object(n))}r.push(e.object(pt.SUI_CLOCK_OBJECT_ID));break}default:throw new Error("Invalid Metacoin: "+t.metaCoinType)}return e.moveCall({target:`${t.extendedDetails.metastable_create_cap_pkg_id}::${t.extendedDetails.metastable_create_cap_module}::${t.createCapFunc}`,typeArguments:i,arguments:r})}executeSwapContract(e,t,i,r){let n=[i,e.object(t.poolId),e.object(this.versionID),r,e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::metastable::${t.func}`,typeArguments:[t.coinType,t.metaCoinType],arguments:n})}},Tf=class{constructor(e){if(e!==0)throw new Error("Alphafi only supported on mainnet");this.suiSystemState="0x0000000000000000000000000000000000000000000000000000000000000005"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Alphafi not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.suiSystemState),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::alphafi::swap`,typeArguments:[t.coinBType],arguments:r})}},Of=class{constructor(e){if(e!==0)throw new Error("Volo only supported on mainnet");this.stakePool="0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",this.metadata="0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Volo not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.stakePool),e.object(this.metadata),e.object("0x5"),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::volo::swap`,typeArguments:[],arguments:r})}},Pf=class{constructor(e){if(e!==0)throw new Error("afSUI only supported on mainnet");this.stakedSuiVault="0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",this.safe="0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",this.referVault="0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",this.validator="0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("AFSUI not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){if(!t.direction)throw new Error("AFSUI not support b2a swap");let r=[i,e.object(this.stakedSuiVault),e.object(this.safe),e.object("0x5"),e.object(this.referVault),e.object(this.validator),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::afsui::swap`,typeArguments:[],arguments:r})}},xf=class{constructor(e){if(e!==0)throw new Error("Haedal only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object("0x5"),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::hasui::swap`,typeArguments:[],arguments:r})}},Nf=class{constructor(e){if(e!==0)throw new Error("Hawal only supported on mainnet");this.staking="0x10b9d30c28448939ce6c4d6c6e0ffce4a7f8a4ada8248bdad09ef8b70e4a3904",this.validator="0x7b3ba6de2ae58283f60d5b8dc04bb9e90e4796b3b2e0dea75569f491275242e7"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Hawal not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.staking),e.object(t.poolId),e.object(this.validator),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::hawal::swap`,typeArguments:[],arguments:r})}},Rf=Qe.DEFAULT_PUBLISHED_AT.Mainnet;function zr(e,t){return e&&e.has(Gr.AGGREGATOR_V3)?e.get(Gr.AGGREGATOR_V3):t||Rf}function Wa(e,t){let{quoteID:i,fromCoinType:r,targetCoinType:n,expectAmountOut:s,amountOutLimit:a,inputCoin:c,feeRate:p,feeRecipient:g,aggregatorPublishedAt:v,packages:y}=e,A=zr(y,v),k=[t.pure.string(i),t.pure.u64(s.toString()),t.pure.u64(a.toString()),c,t.pure.u32(Number(p.toString())),t.pure.address(g)];return t.moveCall({target:`${A}::router::new_swap_context`,typeArguments:[r,n],arguments:k})}function za(e,t){let{swapContext:i,targetCoinType:r,aggregatorPublishedAt:n,packages:s}=e,a=zr(s,n);return t.moveCall({target:`${a}::router::confirm_swap`,typeArguments:[r],arguments:[i]})}function Lf(e,t){let{coinType:i,amount:r,swapCtx:n,aggregatorPublishedAt:s,packages:a}=e,c=zr(a,s),p=[n,t.pure.u64(r.toString())];return t.moveCall({target:`${c}::router::take_balance`,typeArguments:[i],arguments:p})}function Ff(e,t){let{balance:i,coinType:r,recipient:n,aggregatorPublishedAt:s,packages:a}=e,c=zr(a,s),p=[i,t.pure.address(n)];t.moveCall({target:`${c}::router::transfer_balance`,typeArguments:[r],arguments:p})}function Df(e,t){let{coin:i,coinType:r,aggregatorPublishedAt:n,packages:s}=e,a=zr(s,n);t.moveCall({target:`${a}::router::transfer_or_destroy_coin`,typeArguments:[r],arguments:[i]})}function Bf(){let t=Date.now().toString(16).padStart(12,"0"),i=t.substring(0,8),r=t.substring(8,12),n=Math.floor(Math.random()*16383).toString(16).padStart(4,"0"),s=Math.floor(Math.random()*0xffffffffffff).toString(16).padStart(12,"0"),c=(parseInt(i,16)&268435455|1610612736).toString(16).padStart(8,"0"),g=(parseInt(n,16)&16383|32768).toString(16).padStart(4,"0");return`downgrade_${[c,r,"6"+Math.floor(Math.random()*4095).toString(16).padStart(3,"0"),g,s].join("-")}`}function Uf(){let e=Date.now(),t=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${e.toString(16)}_${t}`}function Nl(e){if(!e.startsWith("downgrade_"))return!1;let t=e.substring(10),i=/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,r=/^[0-9a-f]+_[0-9a-f]{6}$/i;return i.test(t)||r.test(t)}function jf(e){if(!Nl(e))return null;let t=e.substring(10);if(t.includes("_")){let r=t.split("_");if(r.length===2){let n=parseInt(r[0],16);return isNaN(n)?null:n}}let i=t.split("-");if(i.length===5)try{let r=(parseInt(i[0],16)&268435455).toString(16).padStart(8,"0"),n=i[1],s=r+n,a=parseInt(s,16);return isNaN(a)?null:a}catch{return null}return null}function Rl(e){return e.endsWith("/find_routes")?e.replace("/find_routes",""):e}function qf(e,t,i){return It(this,null,function*(){let r=yield $f(t,i);return r!==null?{accountCap:e.object(r),isCreate:!1}:{accountCap:e.moveCall({target:`${gl}::${pl}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function $f(e,t){return It(this,null,function*(){let i=50,r=null;for(;;){let n=e.getOwnedObjects({owner:t,cursor:r,limit:i,filter:{MoveModule:{package:ml,module:fl}}});if(n!=null&&n.data!=null){if(n.data.length!==0)return n.data[0].data.objectId;if(n.data.length<50)break}else break}return null})}function Hf(e,t){return t?.has("aggregator_v2")?t.get("aggregator_v2"):e||Pn.V2.Mainnet}function Gf(e,t){return t?.has("aggregator_v2_extend")?t.get("aggregator_v2_extend"):e||Pn.V2_EXTEND.Mainnet}function Vf(e,t){return t?.has("aggregator_v2_extend2")?t.get("aggregator_v2_extend2"):e||Pn.V2_EXTEND2.Mainnet}var Bt=wr(br());function Zf(e){let t=e.effects;if(!(t.status.status==="success"))return{computationCost:"0",storageCost:"0",storageRebate:"0",nonRefundableStorageFee:"0",totalGasCost:"0",gasUsed:"0",gasPrice:"0",success:!1,error:t.status.error||"Unknown error"};let r=t.gasUsed;return{computationCost:r.computationCost||"0",storageCost:r.storageCost||"0",storageRebate:r.storageRebate||"0",nonRefundableStorageFee:r.nonRefundableStorageFee||"0",totalGasCost:Kf(r),gasUsed:r.computationCost||"0",gasPrice:"1000",success:!0}}function Kf(e){let t=new Bt.default(e.computationCost||"0"),i=new Bt.default(e.storageCost||"0"),r=new Bt.default(e.storageRebate||"0"),n=new Bt.default(e.nonRefundableStorageFee||"0");return t.add(i).sub(r).add(n).toString()}function Wf(e,t){let i=new Bt.default(t);return i.isZero()?0:e.div(i).toNumber()}function zf(e,t,i=1){let r=e.mul(new Bt.default(Math.floor(i*1e6))).div(new Bt.default(1e6));return r.isZero()?0:r.sub(t).mul(new Bt.default(1e4)).div(r).toNumber()/100}function Xf(e,t){let i=e.filter(c=>c.gasMetrics.success),r=t.filter(c=>c.gasMetrics.success),n=Xa(i),s=Xa(r),a=n.isZero()?0:n.sub(s).mul(new Bt.default(1e4)).div(n).toNumber()/100;return{v2:e,v3:t,summary:{v2AverageGas:n.toString(),v3AverageGas:s.toString(),gasSavingsPercent:a,v2SuccessRate:i.length/e.length*100,v3SuccessRate:r.length/t.length*100,totalTests:e.length+t.length}}}function Xa(e){return e.length===0?new Bt.default(0):e.reduce((i,r)=>i.add(new Bt.default(r.gasMetrics.totalGasCost)),new Bt.default(0)).div(new Bt.default(e.length))}function Jf(e,t){if(!e.success)return`\u274C Failed: ${e.error}`;let i=Number(e.totalGasCost),r=i/1e9,n=t?" (estimated)":"";return`\u2705 Gas: ${i.toString()} MIST (${r.toString()} SUI)${n}`}function Yf(e){return JSON.stringify(e,null,2)}function Qf(e){let i=[["Version","Provider","Success","AmountIn","AmountOut","TotalGasCost","ComputationCost","GasEfficiency","PriceImpact","OriginalPaths","MergedPaths","PathReduction%","Timestamp"].join(",")];return e.v2.forEach(r=>{let n=r.originalPathCount&&r.mergedPathCount?((r.originalPathCount-r.mergedPathCount)/r.originalPathCount*100).toFixed(1):"0";i.push(["V2",r.provider,r.gasMetrics.success,r.amountIn.toString(),r.amountOut.toString(),r.gasMetrics.totalGasCost,r.gasMetrics.computationCost,r.gasEfficiency.toString(),r.priceImpact.toString(),r.originalPathCount||0,r.mergedPathCount||0,n,r.timestamp.toString()].join(","))}),e.v3.forEach(r=>{let n=r.originalPathCount&&r.mergedPathCount?((r.originalPathCount-r.mergedPathCount)/r.originalPathCount*100).toFixed(1):"0";i.push(["V3",r.provider,r.gasMetrics.success,r.amountIn.toString(),r.amountOut.toString(),r.gasMetrics.totalGasCost,r.gasMetrics.computationCost,r.gasEfficiency.toString(),r.priceImpact.toString(),r.originalPathCount||0,r.mergedPathCount||0,n,r.timestamp.toString()].join(","))}),i.join(`
9
- `)}var Ja=wr(br()),ep=e=>{var t,i,r;return Sn(Hr({},e),{amountIn:(t=e?.amountIn)==null?void 0:t.toString(),amountOut:(i=e?.amountIn)==null?void 0:i.toString(),paths:(r=e?.paths)==null?void 0:r.map(s=>{var a,c,p,g,v,y;let A=Sn(Hr({},s),{amountIn:(a=s?.amountIn)==null?void 0:a.toString(),amountOut:(c=s?.amountOut)==null?void 0:c.toString()});return s?.initialPrice&&(A.initialPrice=(p=s?.initialPrice)==null?void 0:p.toString()),(g=s?.extendedDetails)!=null&&g.after_sqrt_price&&(A.extendedDetails={after_sqrt_price:(y=(v=s?.extendedDetails)==null?void 0:v.afterSqrtPrice)==null?void 0:y.toString()}),A})})},tp=e=>{var t;return Sn(Hr({},e),{amountIn:new Ja.default(e?.amountIn),amountOut:new Ja.default(e?.amountIn),paths:(t=e?.paths)==null?void 0:t.map(r=>{var n,s,a,c;let p=Hr({},r);return r?.initialPrice&&(p.initialPrice=new Tn((n=r?.initialPrice)==null?void 0:n.toString())),(s=r?.extendedDetails)!=null&&s.after_sqrt_price&&(p.extendedDetails={after_sqrt_price:new Tn((c=(a=r?.extendedDetails)==null?void 0:a.after_sqrt_price)==null?void 0:c.toString())}),p})})};function ip(e,t=!0){return It(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((i,r)=>{t&&console.log(`transaction ${r}: `,JSON.stringify(i,rp,2))})})}function rp(e,t){return typeof t=="bigint"?t.toString():t}function np(e){return!(!e.startsWith("0x")||e.length!==66)}var op=class{constructor(e,t){if(e!==0)throw new Error("Haedal HMM V2 only supported on mainnet");this.pythPriceIDs=t}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Haedal HMM V2");console.log("path.extendedDetails",n.extendedDetails),this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){if(!e.haedalhmmv2_base_price_seed)throw new Error("Haedal HMM V2 base price seed not supported")}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal HMM V2 not set publishedAt");let i=t.extendedDetails,[r,n]=t.direction?[t.from,t.target]:[t.target,t.from],s=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn,a=i.haedalhmmv2_base_price_seed,c=this.pythPriceIDs.get(a);if(!c)throw new Error("Haedal HMM V2 requires oracle price IDs for base coin");return{coinAType:r,coinBType:n,basePriceId:c,a2b:t.direction,amountIn:s,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.basePriceId),e.pure.u64(t.amountIn),e.pure.bool(t.a2b),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},sp=class{constructor(e){if(e!==0)throw new Error("Fullsail only supported on mainnet");this.globalConfig="0xe93baa80cb570b3a494cbf0621b2ba96bc993926d34dc92508c9446f9a05d615",this.vault="0xfb971d3a2fb98bde74e1c30ba15a3d8bef60a02789e59ae0b91660aeed3e64e1",this.stats="0x6822a33d1d971e040c32f7cc74507010d1fe786f7d06ab89135083ddb07d2dc2",this.price_provider="0x854b2d2c0381bb656ec962f8b443eb082654384cf97885359d1956c7d76e33c9"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Fullsail not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?Qe.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(this.vault),e.object(this.stats),e.object(this.price_provider),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::fullsail::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},On="CETUS",ap="DEEPBOOK",Go="KRIYA",Vo="FLOWX",Zo="FLOWXV3",Ko="KRIYAV3",Wo="TURBOS",zo="AFTERMATH",Xo="HAEDAL",Jo="VOLO",Yo="AFSUI",Qo="BLUEMOVE",es="DEEPBOOKV3",ts="SCALLOP",is="SUILEND",rs="BLUEFIN",Ln="HAEDALPMM",ns="ALPHAFI",os="SPRINGSUI",ss="STEAMM",Fn="METASTABLE",Dn="OBRIC",as="HAWAL",Bn="STEAMM_OMM",ls="MOMENTUM",Un="STEAMM_OMM_V2",us="MAGMA",jn="SEVENK",qn="HAEDALHMMV2",cs="FULLSAIL",Ll="https://api-sui.cetus.zone/router_v3",$n=[On,Go,Vo,Zo,Ko,Wo,zo,Xo,Jo,Yo,Qo,es,ts,is,rs,Ln,ns,os,ss,Fn,Dn,as,ls,Bn,Un,us,jn,qn,cs];function lp(){return $n}function up(e){return $n.filter(t=>!e.includes(t))}function cp(e){return $n.filter(t=>e.includes(t))}function Ya(e){let t=new Set;for(let i of e){if(i.provider===Ln&&i.extendedDetails&&i.extendedDetails.haedal_pmm_base_price_seed&&i.extendedDetails.haedal_pmm_quote_price_seed&&(t.add(i.extendedDetails.haedal_pmm_base_price_seed),t.add(i.extendedDetails.haedal_pmm_quote_price_seed)),i.provider===Fn&&(i.extendedDetails&&i.extendedDetails.metastable_price_seed&&t.add(i.extendedDetails.metastable_price_seed),i.extendedDetails&&i.extendedDetails.metastable_eth_price_seed&&t.add(i.extendedDetails.metastable_eth_price_seed)),i.provider===Dn&&(i.extendedDetails&&i.extendedDetails.obric_coin_a_price_seed&&t.add(i.extendedDetails.obric_coin_a_price_seed),i.extendedDetails&&i.extendedDetails.obric_coin_b_price_seed&&t.add(i.extendedDetails.obric_coin_b_price_seed)),(i.provider===Bn||i.provider===Un)&&(i.extendedDetails&&i.extendedDetails.steamm_oracle_pyth_price_seed_a&&t.add(i.extendedDetails.steamm_oracle_pyth_price_seed_a),i.extendedDetails&&i.extendedDetails.steamm_oracle_pyth_price_seed_b&&t.add(i.extendedDetails.steamm_oracle_pyth_price_seed_b)),i.provider===jn&&i.extendedDetails){let r=i.extendedDetails;r.sevenk_coin_a_price_seed&&t.add(r.sevenk_coin_a_price_seed),r.sevenk_coin_b_price_seed&&t.add(r.sevenk_coin_b_price_seed)}i.provider===qn&&i.extendedDetails&&i.extendedDetails.haedalhmmv2_base_price_seed&&t.add(i.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(t)}var Fl=class Dl{constructor(t){var i,r;this.endpoint=t.endpoint?Rl(t.endpoint):Ll,this.client=t.client||new Da.SuiClient({url:Da.getFullnodeUrl("mainnet")}),this.signer=t.signer||"",this.env=t.env||0;let n=Dl.CONFIG[this.env];if(this.pythConnections=this.newPythClients((i=t.pythUrls)!=null?i:[]),this.pythClient=new Ba.SuiPythClient(this.client,n.pythStateId,n.wormholeStateId),this.apiKey=t.apiKey||"",this.partner=t.partner,t.overlayFeeRate)if(t.overlayFeeRate>0&&t.overlayFeeRate<=ki.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=t.overlayFeeRate*Qe.FEE_DENOMINATOR,this.overlayFeeRate>Qe.MAX_FEE_RATE)throw new Error(ki.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(ki.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(r=t.overlayFeeReceiver)!=null?r:ki.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(t){return t.includes("https://hermes.pyth.network")||t.push("https://hermes.pyth.network"),t.map(r=>new Ba.SuiPriceServiceConnection(r,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?Vr.Mainnet:Vr.Testnet}getOneCoinUsedToMerge(t){return It(this,null,function*(){try{let i=yield this.client.getCoins({owner:this.signer,coinType:t,limit:1});return i.data.length===1?i.data[0].coinObjectId:null}catch{return null}})}findRouters(t){return It(this,null,function*(){return wl(this.endpoint,this.apiKey,t,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(t,i,r,n,s,a,c,p,g){return It(this,null,function*(){})}newDexRouterV3(t,i,r){switch(t){case On:return new Za(this.env,r);case Ko:return new af(this.env);case Zo:return new lf(this.env);case Wo:return new uf(this.env);case rs:return new cf(this.env);case ls:return new df(this.env);case us:return new hf(this.env);case Go:return new ff(this.env);case Vo:return new pf(this.env);case Qo:return new mf(this.env);case es:return new gf(this.env);case zo:return new _f(this.env);case ss:return new vf(this.env);case ts:return new wf(this.env);case is:return new Ka(this.env);case os:return new Ka(this.env);case Ln:return new bf(this.env,i);case Dn:return new yf(this.env,i);case jn:return new Mf(this.env,i);case Bn:return new Af(this.env,i);case Un:return new Sf(this.env,i);case Fn:return new kf(this.env,i);case ns:return new Tf(this.env);case Jo:return new Of(this.env);case Yo:return new Pf(this.env);case Xo:return new xf(this.env);case as:return new Nf(this.env);case qn:return new op(this.env,i);case cs:return new sp(this.env);default:throw new Error(`${ki.ERRORS.UNSUPPORTED_DEX} ${t}`)}}expectInputSwapV3(t,i,r,n,s,a,c){if(r.quoteID==null)throw new Error(ki.ERRORS.QUOTE_ID_REQUIRED);let p=Lo(r),g=Wa({quoteID:p.quoteID,fromCoinType:p.fromCoinType,targetCoinType:p.targetCoinType,expectAmountOut:n,amountOutLimit:s,inputCoin:i,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:p.packages},t),v=new Map;for(let A of p.flattenedPaths){let k=A.path;v.has(k.provider)||v.set(k.provider,this.newDexRouterV3(k.provider,a,c)),v.get(k.provider).swap(t,A,g,{pythPriceIDs:a})}return za({swapContext:g,targetCoinType:p.targetCoinType,packages:p.packages},t)}expectOutputSwapV3(t,i,r,n,s,a){let c=[],p=new Za(this.env,a),g=Lo(r),v=Wa({quoteID:g.quoteID,fromCoinType:g.fromCoinType,targetCoinType:g.targetCoinType,expectAmountOut:n,amountOutLimit:n,inputCoin:i,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:g.packages},t),y=fp(r.paths),A=new Map,k=new Map;for(let W=r.paths.length-1;W>=0;W--){let j=r.paths[W],K=y.get(j.from),X;if(W!==K||j.target===g.targetCoinType){if(j.target!==g.targetCoinType){let se=BigInt(j.amountOut);k.has(j.target)&&(se=k.get(j.target)+se),k.set(j.target,se)}X=t.pure.u64(j.amountOut.toString())}else{if(!A.has(j.target))throw Error("no need repay record");if(k.has(j.target)){let se=k.get(j.target),Y=A.get(j.target);X=p.sub(t,Y,t.pure.u64(se),j.publishedAt)}else X=A.get(j.target)}let Q=p.flashSwapFixedOutput(t,j,X,v);if(c.unshift(Q.flashReceipt),A.has(j.from)){let se=A.get(j.from);A.set(j.from,p.add(t,se,Q.repayAmount,j.publishedAt))}else A.set(j.from,Q.repayAmount)}for(let W=0;W<r.paths.length;W++){let j=r.paths[W];p.repayFlashSwapFixedOutput(t,j,v,c[W])}let U=Lf({coinType:g.fromCoinType,amount:Cn,swapCtx:v,packages:g.packages},t);return Ff({balance:U,coinType:g.fromCoinType,recipient:this.signer,packages:g.packages},t),za({swapContext:v,targetCoinType:g.targetCoinType,packages:g.packages},t)}routerSwap(t){return It(this,null,function*(){let{router:i,inputCoin:r,slippage:n,txb:s,fixable:a,partner:c}=t;if(n>1||n<0)throw new Error(ki.ERRORS.INVALID_SLIPPAGE);let p=t.router.byAmountIn,g=i.amountIn,v=i.amountOut,y=new gt.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(p?y=v.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)):y=g.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)));let A=p?v.sub(y):v,k=p?g:g.add(y),U=Va(p?A:k,p,n);if(!t.router.packages||!t.router.packages.get(Gr.AGGREGATOR_V3))throw new Error(ki.ERRORS.PACKAGES_REQUIRED);let P=Ya(i.paths),W=P.length>0?yield this.updatePythPriceIDs(P,s):new Map;return p?this.expectInputSwapV3(s,r,i,v.toString(),U.toString(),W,c??this.partner):this.expectOutputSwapV3(s,r,i,v.toString(),U.toString(),c??this.partner)})}fastRouterSwap(t){return It(this,null,function*(){let{router:i,slippage:r,txb:n,partner:s,payDeepFeeAmount:a}=t,c=i.paths[0].from,p=i.paths[i.paths.length-1].target,g=i.byAmountIn,v=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(g?v=Number(i.amountOut.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()):v=Number(i.amountIn.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()));let y=g?i.amountOut.sub(new gt.default(v)):i.amountOut,A=g?i.amountIn:i.amountIn.add(new gt.default(v)),k=sf(g?y:A,g,r),U=g?A:k,P=xo.coinWithBalance({balance:BigInt(U.toString()),useGasCoin:!0,type:c}),W;a&&a>0&&(W=xo.coinWithBalance({balance:BigInt(a),type:this.deepbookv3DeepFeeType()}));let j={router:i,inputCoin:P,slippage:r,txb:n,partner:s??this.partner,deepbookv3DeepFee:W},K=yield this.routerSwap(j);if(ci.isSuiCoin(p))n.mergeCoins(n.gas,[K]);else{let X=yield this.getOneCoinUsedToMerge(p);X!=null?n.mergeCoins(n.object(X),[K]):Df({coin:K,coinType:p,packages:i.packages},n)}})}fixableRouterSwapV3(t){return It(this,null,function*(){let{router:i,inputCoin:r,slippage:n,txb:s,deepbookv3DeepFee:a,partner:c}=t,p=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(i.byAmountIn?p=Number(i.amountOut.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()):p=Number(i.amountIn.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()));let g=i.byAmountIn?i.amountOut.sub(new gt.default(p)):i.amountOut,v=i.byAmountIn?i.amountIn:i.amountIn.add(new gt.default(p)),y=Va(i.byAmountIn?g:v,i.byAmountIn,n),A=Ya(i.paths),k=A.length>0?yield this.updatePythPriceIDs(A,s):new Map;return i.byAmountIn?this.expectInputSwapV3(s,r,i,g.toString(),y.toString(),k,c??this.partner):this.expectOutputSwapV3(s,r,i,g.toString(),y.toString(),c??this.partner)})}swapInPools(t){return It(this,null,function*(){var i,r,n,s;let{from:a,target:c,amount:p,byAmountIn:g,pools:v}=t,y=Oi(a),A=Oi(c),k=new xo.Transaction,U=dl(y,A),P=U?y:A,W=U?A:y,j=[P,W],K=this.env===0?"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d":"0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";for(let l=0;l<v.length;l++){let d=[k.object(v[l]),k.pure.bool(U),k.pure.bool(g),k.pure.u64(p.toString())];k.moveCall({target:`${K}::fetcher_script::calculate_swap_result`,arguments:d,typeArguments:j})}this.signer||(this.signer="0x0");let X=yield this.client.devInspectTransactionBlock({transactionBlock:k,sender:this.signer});if(X.error!=null)throw new Error("Simulation error: "+X.error);let Q=(i=X.events)==null?void 0:i.filter(l=>l.type.includes("CalculatedSwapResultEvent"));if(Q.length===0||Q.length!==v.length)throw new Error("Simulate event result error");let se=g?new gt.default(0):new gt.default(Cn),Y=0;for(let l=0;l<Q.length;l+=1)if(!Q[l].parsedJson.data.is_exceed)if(t.byAmountIn){let d=new gt.default(Q[l].parsedJson.data.amount_out);d.gt(se)&&(Y=l,se=d)}else{let d=new gt.default(Q[l].parsedJson.data.amount_out);d.lt(se)&&(Y=l,se=d)}let ae=Q[Y].parsedJson.data,[E,I]=yield Promise.all([this.client.getCoinMetadata({coinType:P}).then(l=>l?.decimals),this.client.getCoinMetadata({coinType:W}).then(l=>l?.decimals)]);if(E==null||I==null)throw new Error("Cannot get coin decimals");let O=Number(ae.fee_rate)/1e6,R=new gt.default((r=ae.amount_in)!=null?r:0),N=new gt.default((n=ae.fee_amount)!=null?n:0),S=R.add(N),h={amountIn:S,amountOut:new gt.default((s=ae.amount_out)!=null?s:0),paths:[{id:v[Y],direction:U,provider:On,from:y,target:A,feeRate:O,amountIn:S.toString(),amountOut:ae.amount_out,publishedAt:_l,extendedDetails:{afterSqrtPrice:ae.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn,quoteID:`degraded-${hp()}`,packages:new Map([[Gr.AGGREGATOR_V3,Qe.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:ae.is_exceed,routeData:h}})}updatePythPriceIDs(t,i){return It(this,null,function*(){let r=null,n=null;for(let c of this.pythConnections)try{r=yield c.getPriceFeedsUpdateData(t);break}catch(p){n=p,console.log("Error: ",p);continue}if(r==null)throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes. Detailed error: ${n?.message}`);let s=[];try{s=yield this.pythClient.updatePriceFeeds(i,r,t)}catch(c){throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes in the pythUrls parameter when initializing AggregatorClient, for example: new AggregatorClient({ pythUrls: ["https://your-pyth-node-url"] }). Detailed error: ${c}`)}let a=new Map;for(let c=0;c<t.length;c++)a.set(t[c],s[c]);return a})}devInspectTransactionBlock(t){return It(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:t,sender:this.signer})})}sendTransaction(t,i){return It(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:t,signer:i})})}};Fl.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var dp=Fl;function hp(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function fp(e){let t=new Map;for(let i=0;i<e.length;i++)t.has(e[i].from)||t.set(e[i].from,i);return t}var pp=e=>{if(typeof e=="string"&&e.startsWith("0x"))return"object";if(typeof e=="number"||typeof e=="bigint")return"u64";if(typeof e=="boolean")return"bool";throw new AggregateError(`Unknown type for value: ${e}`,"InvalidType")};J.AFSUI=Yo;J.AFTERMATH=zo;J.AFTERMATH_AMM=ld;J.AFTERMATH_MODULE=vd;J.AGGREGATOR=id;J.AGGREGATOR_V3_CONFIG=Qe;J.ALL_DEXES=$n;J.ALPHAFI=ns;J.AggregatorClient=dp;J.AggregatorConfig=ch;J.AggregatorError=xc;J.AggregatorServerErrorCode=nl;J.BLUEFIN=rs;J.BLUEMOVE=Qo;J.CETUS=On;J.CETUS_DEX=rd;J.CETUS_MODULE=cd;J.CETUS_PUBLISHED_AT=qd;J.CETUS_V3_PUBLISHED_AT=_l;J.CHECK_COINS_THRESHOLD_FUNC=Rd;J.CLIENT_CONFIG=ki;J.CLOCK_ADDRESS=Dd;J.CoinInfoAddress=Bd;J.CoinStoreAddress=Ud;J.CoinUtils=ci;J.ConfigErrorCode=il;J.DEEPBOOKV2=ap;J.DEEPBOOKV3=es;J.DEEPBOOK_CLOB_V2_MODULE=pl;J.DEEPBOOK_CUSTODIAN_V2_MODULE=fl;J.DEEPBOOK_DEX=nd;J.DEEPBOOK_MODULE=dd;J.DEEPBOOK_PACKAGE_ID=ml;J.DEEPBOOK_PUBLISHED_AT=gl;J.DEEPBOOK_V3_DEEP_FEE_TYPES=Vr;J.DEFAULT_AGG_V2_ENDPOINT=nh;J.DEFAULT_AGG_V3_ENDPOINT=rh;J.DEFAULT_ENDPOINT=Ll;J.DEFAULT_GAS_BUDGET_FOR_MERGE=$c;J.DEFAULT_GAS_BUDGET_FOR_SPLIT=qc;J.DEFAULT_GAS_BUDGET_FOR_STAKE=Vc;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER=Hc;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=Gc;J.DEFAULT_NFT_TRANSFER_GAS_FEE=Kc;J.Env=bl;J.FLOWXV2=Vo;J.FLOWXV3=Zo;J.FLOWX_AMM=sd;J.FLOWX_AMM_MODULE=gd;J.FULLSAIL=cs;J.FlashSwapA2BFunc=Ad;J.FlashSwapB2AFunc=Sd;J.FlashSwapFunc=wd;J.FlashSwapWithPartnerA2BFunc=Cd;J.FlashSwapWithPartnerB2AFunc=Ed;J.FlashSwapWithPartnerFunc=bd;J.GAS_SYMBOL=Zc;J.GAS_TYPE_ARG=$o;J.GAS_TYPE_ARG_LONG=ul;J.HAEDAL=Xo;J.HAEDALHMMV2=qn;J.HAEDALPMM=Ln;J.HAWAL=as;J.INTEGRATE=ud;J.JOIN_FUNC=Ld;J.KRIYA=Go;J.KRIYAV3=Ko;J.KRIYA_DEX=od;J.KRIYA_MODULE=hd;J.MAGMA=us;J.MAINNET_AFTERMATH_INSURANCE_FUND_ID=Qd;J.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=zd;J.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=th;J.MAINNET_AFTERMATH_REGISTRY_ID=Kd;J.MAINNET_AFTERMATH_TREASURY_ID=Jd;J.MAINNET_CETUS_GLOBAL_CONFIG_ID=$d;J.MAINNET_FLOWX_AMM_CONTAINER_ID=Gd;J.METASTABLE=Fn;J.MOMENTUM=ls;J.OBRIC=Dn;J.ONE=Yc;J.PACKAGE_NAMES=Gr;J.PAY_MODULE=md;J.POOL_MODULT=pd;J.PUBLISHED_ADDRESSES=Pn;J.PYTH_CONFIG=oh;J.REPAY_FLASH_SWAP_A2B_FUNC=Id;J.REPAY_FLASH_SWAP_B2A_FUNC=kd;J.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=Td;J.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=Od;J.RepayFalshSwapFunc=yd;J.RepayFlashSwapWithPartnerFunc=Md;J.SCALLOP=ts;J.SEVENK=jn;J.SPRINGSUI=os;J.STEAMM=ss;J.STEAMM_OMM=Bn;J.STEAMM_OMM_V2=Un;J.SUILEND=is;J.SUI_SYSTEM_STATE_OBJECT_ID=Wc;J.SWAP_A2B_FUNC=Pd;J.SWAP_B2A_FUNC=xd;J.SuiZeroCoinFn=jd;J.TEN_POW_NINE=td;J.TESTNET_AFTERMATH_INSURANCE_FUND_ID=eh;J.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=Xd;J.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=ih;J.TESTNET_AFTERMATH_REGISTRY_ID=Wd;J.TESTNET_AFTERMATH_TREASURY_ID=Yd;J.TESTNET_CETUS_GLOBAL_CONFIG_ID=Hd;J.TESTNET_FLOWX_AMM_CONTAINER_ID=Vd;J.TRANSFER_ACCOUNT_CAP=Fd;J.TRANSFER_OR_DESTORY_COIN_FUNC=Nd;J.TURBOS=Wo;J.TURBOS_DEX=ad;J.TURBOS_MODULE=_d;J.TURBOS_VERSIONED=Zd;J.TWO=hl;J.TransactionErrorCode=rl;J.TypesErrorCode=tl;J.U128=Qc;J.U64_MAX=Cn;J.U64_MAX_BN=ed;J.UTILS_MODULE=fd;J.VOLO=Jo;J.ZERO=sr;J.buildInputCoin=Jc;J.calculateGasEfficiency=Wf;J.calculatePriceImpact=zf;J.checkInvalidSuiAddress=np;J.compareCoins=dl;J.compareGasMetrics=Xf;J.completionCoin=Oi;J.composeType=No;J.createTarget=Bc;J.dealWithFastRouterSwapParamsForMsafe=ep;J.exportToCSV=Qf;J.exportToJSON=Yf;J.extractAddressFromType=Dc;J.extractGasMetrics=Zf;J.extractStructTagFromType=_r;J.extractTimestampFromDowngradeUuid6=jf;J.fixSuiObjectId=al;J.formatGasMetrics=Jf;J.generateDowngradeUuid6=Bf;J.generateSimpleDowngradeUuid6=Uf;J.getAggregatorServerErrorMessage=Mn;J.getAggregatorV2Extend2PublishedAt=Vf;J.getAggregatorV2ExtendPublishedAt=Gf;J.getAggregatorV2PublishedAt=Hf;J.getAllProviders=lp;J.getDeepbookV3Config=uh;J.getDefaultSuiInputType=pp;J.getOrCreateAccountCap=qf;J.getProvidersExcluding=up;J.getProvidersIncluding=cp;J.getRouterResult=wl;J.isSortedSymbols=Fc;J.isValidDowngradeUuid6=Nl;J.mintZeroCoin=cl;J.normalizeCoinType=Ro;J.parseAftermathFeeType=Xc;J.parseTurbosPoolFeeType=zc;J.patchFixSuiObjectId=ll;J.printTransaction=ip;J.processEndpoint=Rl;J.processFlattenRoutes=Lo;J.restituteMsafeFastRouterSwapParams=tp});import{SdkWrapper as Y1}from"@cetusprotocol/common-sdk";import{DefaultProviders as Qu,FullRpcUrlMainnet as e0}from"@cetusprotocol/common-sdk";var Vs={full_rpc_url:e0,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Qu,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};import{SuilendClient as d0}from"@suilend/sdk/client";import{initializeSuilend as h0,initializeSuilendRewards as f0,initializeObligations as p0,formatRewards as m0,Side as ia,getFilteredRewards as g0,getStakingYieldAprPercent as _0,getDedupedPerDayRewards as v0,getDedupedAprRewards as w0,getTotalAprPercent as ra,getNetAprPercent as b0}from"@suilend/sdk";var t0=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,mo=Math.ceil,$t=Math.floor,Rt="[BigNumber Error] ",Zs=Rt+"Number primitive has more than 15 significant digits: ",li=1e14,We=14,go=9007199254740991,_o=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Di=1e7,At=1e9;function Ks(e){var t,i,r,n=K.prototype={constructor:K,toString:null,valueOf:null},s=new K(1),a=20,c=4,p=-7,g=21,v=-1e7,y=1e7,A=!1,k=1,U=0,P={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},W="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function K(E,I){var O,R,N,S,h,o,l,d,m=this;if(!(m instanceof K))return new K(E,I);if(I==null){if(E&&E._isBigNumber===!0){m.s=E.s,!E.c||E.e>y?m.c=m.e=null:E.e<v?m.c=[m.e=0]:(m.e=E.e,m.c=E.c.slice());return}if((o=typeof E=="number")&&E*0==0){if(m.s=1/E<0?(E=-E,-1):1,E===~~E){for(S=0,h=E;h>=10;h/=10,S++);S>y?m.c=m.e=null:(m.e=S,m.c=[E]);return}d=String(E)}else{if(!t0.test(d=String(E)))return r(m,d,o);m.s=d.charCodeAt(0)==45?(d=d.slice(1),-1):1}(S=d.indexOf("."))>-1&&(d=d.replace(".","")),(h=d.search(/e/i))>0?(S<0&&(S=h),S+=+d.slice(h+1),d=d.substring(0,h)):S<0&&(S=d.length)}else{if(_t(I,2,W.length,"Base"),I==10&&j)return m=new K(E),Y(m,a+m.e+1,c);if(d=String(E),o=typeof E=="number"){if(E*0!=0)return r(m,d,o,I);if(m.s=1/E<0?(d=d.slice(1),-1):1,K.DEBUG&&d.replace(/^0\.0*|\./,"").length>15)throw Error(Zs+E)}else m.s=d.charCodeAt(0)===45?(d=d.slice(1),-1):1;for(O=W.slice(0,I),S=h=0,l=d.length;h<l;h++)if(O.indexOf(R=d.charAt(h))<0){if(R=="."){if(h>S){S=l;continue}}else if(!N&&(d==d.toUpperCase()&&(d=d.toLowerCase())||d==d.toLowerCase()&&(d=d.toUpperCase()))){N=!0,h=-1,S=0;continue}return r(m,String(E),o,I)}o=!1,d=i(d,I,10,m.s),(S=d.indexOf("."))>-1?d=d.replace(".",""):S=d.length}for(h=0;d.charCodeAt(h)===48;h++);for(l=d.length;d.charCodeAt(--l)===48;);if(d=d.slice(h,++l)){if(l-=h,o&&K.DEBUG&&l>15&&(E>go||E!==$t(E)))throw Error(Zs+m.s*E);if((S=S-h-1)>y)m.c=m.e=null;else if(S<v)m.c=[m.e=0];else{if(m.e=S,m.c=[],h=(S+1)%We,S<0&&(h+=We),h<l){for(h&&m.c.push(+d.slice(0,h)),l-=We;h<l;)m.c.push(+d.slice(h,h+=We));h=We-(d=d.slice(h)).length}else h-=l;for(;h--;d+="0");m.c.push(+d)}}else m.c=[m.e=0]}K.clone=Ks,K.ROUND_UP=0,K.ROUND_DOWN=1,K.ROUND_CEIL=2,K.ROUND_FLOOR=3,K.ROUND_HALF_UP=4,K.ROUND_HALF_DOWN=5,K.ROUND_HALF_EVEN=6,K.ROUND_HALF_CEIL=7,K.ROUND_HALF_FLOOR=8,K.EUCLID=9,K.config=K.set=function(E){var I,O;if(E!=null)if(typeof E=="object"){if(E.hasOwnProperty(I="DECIMAL_PLACES")&&(O=E[I],_t(O,0,At,I),a=O),E.hasOwnProperty(I="ROUNDING_MODE")&&(O=E[I],_t(O,0,8,I),c=O),E.hasOwnProperty(I="EXPONENTIAL_AT")&&(O=E[I],O&&O.pop?(_t(O[0],-At,0,I),_t(O[1],0,At,I),p=O[0],g=O[1]):(_t(O,-At,At,I),p=-(g=O<0?-O:O))),E.hasOwnProperty(I="RANGE"))if(O=E[I],O&&O.pop)_t(O[0],-At,-1,I),_t(O[1],1,At,I),v=O[0],y=O[1];else if(_t(O,-At,At,I),O)v=-(y=O<0?-O:O);else throw Error(Rt+I+" cannot be zero: "+O);if(E.hasOwnProperty(I="CRYPTO"))if(O=E[I],O===!!O)if(O)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=O;else throw A=!O,Error(Rt+"crypto unavailable");else A=O;else throw Error(Rt+I+" not true or false: "+O);if(E.hasOwnProperty(I="MODULO_MODE")&&(O=E[I],_t(O,0,9,I),k=O),E.hasOwnProperty(I="POW_PRECISION")&&(O=E[I],_t(O,0,At,I),U=O),E.hasOwnProperty(I="FORMAT"))if(O=E[I],typeof O=="object")P=O;else throw Error(Rt+I+" not an object: "+O);if(E.hasOwnProperty(I="ALPHABET"))if(O=E[I],typeof O=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(O))j=O.slice(0,10)=="0123456789",W=O;else throw Error(Rt+I+" invalid: "+O)}else throw Error(Rt+"Object expected: "+E);return{DECIMAL_PLACES:a,ROUNDING_MODE:c,EXPONENTIAL_AT:[p,g],RANGE:[v,y],CRYPTO:A,MODULO_MODE:k,POW_PRECISION:U,FORMAT:P,ALPHABET:W}},K.isBigNumber=function(E){if(!E||E._isBigNumber!==!0)return!1;if(!K.DEBUG)return!0;var I,O,R=E.c,N=E.e,S=E.s;e:if({}.toString.call(R)=="[object Array]"){if((S===1||S===-1)&&N>=-At&&N<=At&&N===$t(N)){if(R[0]===0){if(N===0&&R.length===1)return!0;break e}if(I=(N+1)%We,I<1&&(I+=We),String(R[0]).length==I){for(I=0;I<R.length;I++)if(O=R[I],O<0||O>=li||O!==$t(O))break e;if(O!==0)return!0}}}else if(R===null&&N===null&&(S===null||S===1||S===-1))return!0;throw Error(Rt+"Invalid BigNumber: "+E)},K.maximum=K.max=function(){return Q(arguments,-1)},K.minimum=K.min=function(){return Q(arguments,1)},K.random=(function(){var E=9007199254740992,I=Math.random()*E&2097151?function(){return $t(Math.random()*E)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(O){var R,N,S,h,o,l=0,d=[],m=new K(s);if(O==null?O=a:_t(O,0,At),h=mo(O/We),A)if(crypto.getRandomValues){for(R=crypto.getRandomValues(new Uint32Array(h*=2));l<h;)o=R[l]*131072+(R[l+1]>>>11),o>=9e15?(N=crypto.getRandomValues(new Uint32Array(2)),R[l]=N[0],R[l+1]=N[1]):(d.push(o%1e14),l+=2);l=h/2}else if(crypto.randomBytes){for(R=crypto.randomBytes(h*=7);l<h;)o=(R[l]&31)*281474976710656+R[l+1]*1099511627776+R[l+2]*4294967296+R[l+3]*16777216+(R[l+4]<<16)+(R[l+5]<<8)+R[l+6],o>=9e15?crypto.randomBytes(7).copy(R,l):(d.push(o%1e14),l+=7);l=h/7}else throw A=!1,Error(Rt+"crypto unavailable");if(!A)for(;l<h;)o=I(),o<9e15&&(d[l++]=o%1e14);for(h=d[--l],O%=We,h&&O&&(o=_o[We-O],d[l]=$t(h/o)*o);d[l]===0;d.pop(),l--);if(l<0)d=[S=0];else{for(S=-1;d[0]===0;d.splice(0,1),S-=We);for(l=1,o=d[0];o>=10;o/=10,l++);l<We&&(S-=We-l)}return m.e=S,m.c=d,m}})(),K.sum=function(){for(var E=1,I=arguments,O=new K(I[0]);E<I.length;)O=O.plus(I[E++]);return O},i=(function(){var E="0123456789";function I(O,R,N,S){for(var h,o=[0],l,d=0,m=O.length;d<m;){for(l=o.length;l--;o[l]*=R);for(o[0]+=S.indexOf(O.charAt(d++)),h=0;h<o.length;h++)o[h]>N-1&&(o[h+1]==null&&(o[h+1]=0),o[h+1]+=o[h]/N|0,o[h]%=N)}return o.reverse()}return function(O,R,N,S,h){var o,l,d,m,_,b,w,f,u=O.indexOf("."),M=a,q=c;for(u>=0&&(m=U,U=0,O=O.replace(".",""),f=new K(R),b=f.pow(O.length-u),U=m,f.c=I(Ei(qt(b.c),b.e,"0"),10,N,E),f.e=f.c.length),w=I(O,R,N,h?(o=W,E):(o=E,W)),d=m=w.length;w[--m]==0;w.pop());if(!w[0])return o.charAt(0);if(u<0?--d:(b.c=w,b.e=d,b.s=S,b=t(b,f,M,q,N),w=b.c,_=b.r,d=b.e),l=d+M+1,u=w[l],m=N/2,_=_||l<0||w[l+1]!=null,_=q<4?(u!=null||_)&&(q==0||q==(b.s<0?3:2)):u>m||u==m&&(q==4||_||q==6&&w[l-1]&1||q==(b.s<0?8:7)),l<1||!w[0])O=_?Ei(o.charAt(1),-M,o.charAt(0)):o.charAt(0);else{if(w.length=l,_)for(--N;++w[--l]>N;)w[l]=0,l||(++d,w=[1].concat(w));for(m=w.length;!w[--m];);for(u=0,O="";u<=m;O+=o.charAt(w[u++]));O=Ei(O,d,o.charAt(0))}return O}})(),t=(function(){function E(R,N,S){var h,o,l,d,m=0,_=R.length,b=N%Di,w=N/Di|0;for(R=R.slice();_--;)l=R[_]%Di,d=R[_]/Di|0,h=w*l+d*b,o=b*l+h%Di*Di+m,m=(o/S|0)+(h/Di|0)+w*d,R[_]=o%S;return m&&(R=[m].concat(R)),R}function I(R,N,S,h){var o,l;if(S!=h)l=S>h?1:-1;else for(o=l=0;o<S;o++)if(R[o]!=N[o]){l=R[o]>N[o]?1:-1;break}return l}function O(R,N,S,h){for(var o=0;S--;)R[S]-=o,o=R[S]<N[S]?1:0,R[S]=o*h+R[S]-N[S];for(;!R[0]&&R.length>1;R.splice(0,1));}return function(R,N,S,h,o){var l,d,m,_,b,w,f,u,M,q,$,z,ie,C,T,x,F,L=R.s==N.s?1:-1,G=R.c,B=N.c;if(!G||!G[0]||!B||!B[0])return new K(!R.s||!N.s||(G?B&&G[0]==B[0]:!B)?NaN:G&&G[0]==0||!B?L*0:L/0);for(u=new K(L),M=u.c=[],d=R.e-N.e,L=S+d+1,o||(o=li,d=Ht(R.e/We)-Ht(N.e/We),L=L/We|0),m=0;B[m]==(G[m]||0);m++);if(B[m]>(G[m]||0)&&d--,L<0)M.push(1),_=!0;else{for(C=G.length,x=B.length,m=0,L+=2,b=$t(o/(B[0]+1)),b>1&&(B=E(B,b,o),G=E(G,b,o),x=B.length,C=G.length),ie=x,q=G.slice(0,x),$=q.length;$<x;q[$++]=0);F=B.slice(),F=[0].concat(F),T=B[0],B[1]>=o/2&&T++;do{if(b=0,l=I(B,q,x,$),l<0){if(z=q[0],x!=$&&(z=z*o+(q[1]||0)),b=$t(z/T),b>1)for(b>=o&&(b=o-1),w=E(B,b,o),f=w.length,$=q.length;I(w,q,f,$)==1;)b--,O(w,x<f?F:B,f,o),f=w.length,l=1;else b==0&&(l=b=1),w=B.slice(),f=w.length;if(f<$&&(w=[0].concat(w)),O(q,w,$,o),$=q.length,l==-1)for(;I(B,q,x,$)<1;)b++,O(q,x<$?F:B,$,o),$=q.length}else l===0&&(b++,q=[0]);M[m++]=b,q[0]?q[$++]=G[ie]||0:(q=[G[ie]],$=1)}while((ie++<C||q[0]!=null)&&L--);_=q[0]!=null,M[0]||M.splice(0,1)}if(o==li){for(m=1,L=M[0];L>=10;L/=10,m++);Y(u,S+(u.e=m+d*We-1)+1,h,_)}else u.e=d,u.r=+_;return u}})();function X(E,I,O,R){var N,S,h,o,l;if(O==null?O=c:_t(O,0,8),!E.c)return E.toString();if(N=E.c[0],h=E.e,I==null)l=qt(E.c),l=R==1||R==2&&(h<=p||h>=g)?on(l,h):Ei(l,h,"0");else if(E=Y(new K(E),I,O),S=E.e,l=qt(E.c),o=l.length,R==1||R==2&&(I<=S||S<=p)){for(;o<I;l+="0",o++);l=on(l,S)}else if(I-=h+(R===2&&S>h),l=Ei(l,S,"0"),S+1>o){if(--I>0)for(l+=".";I--;l+="0");}else if(I+=S-o,I>0)for(S+1==o&&(l+=".");I--;l+="0");return E.s<0&&N?"-"+l:l}function Q(E,I){for(var O,R,N=1,S=new K(E[0]);N<E.length;N++)R=new K(E[N]),(!R.s||(O=nr(S,R))===I||O===0&&S.s===I)&&(S=R);return S}function se(E,I,O){for(var R=1,N=I.length;!I[--N];I.pop());for(N=I[0];N>=10;N/=10,R++);return(O=R+O*We-1)>y?E.c=E.e=null:O<v?E.c=[E.e=0]:(E.e=O,E.c=I),E}r=(function(){var E=/^(-?)0([xbo])(?=\w[\w.]*$)/i,I=/^([^.]+)\.$/,O=/^\.([^.]+)$/,R=/^-?(Infinity|NaN)$/,N=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(S,h,o,l){var d,m=o?h:h.replace(N,"");if(R.test(m))S.s=isNaN(m)?null:m<0?-1:1;else{if(!o&&(m=m.replace(E,function(_,b,w){return d=(w=w.toLowerCase())=="x"?16:w=="b"?2:8,!l||l==d?b:_}),l&&(d=l,m=m.replace(I,"$1").replace(O,"0.$1")),h!=m))return new K(m,d);if(K.DEBUG)throw Error(Rt+"Not a"+(l?" base "+l:"")+" number: "+h);S.s=null}S.c=S.e=null}})();function Y(E,I,O,R){var N,S,h,o,l,d,m,_=E.c,b=_o;if(_){e:{for(N=1,o=_[0];o>=10;o/=10,N++);if(S=I-N,S<0)S+=We,h=I,l=_[d=0],m=$t(l/b[N-h-1]%10);else if(d=mo((S+1)/We),d>=_.length)if(R){for(;_.length<=d;_.push(0));l=m=0,N=1,S%=We,h=S-We+1}else break e;else{for(l=o=_[d],N=1;o>=10;o/=10,N++);S%=We,h=S-We+N,m=h<0?0:$t(l/b[N-h-1]%10)}if(R=R||I<0||_[d+1]!=null||(h<0?l:l%b[N-h-1]),R=O<4?(m||R)&&(O==0||O==(E.s<0?3:2)):m>5||m==5&&(O==4||R||O==6&&(S>0?h>0?l/b[N-h]:0:_[d-1])%10&1||O==(E.s<0?8:7)),I<1||!_[0])return _.length=0,R?(I-=E.e+1,_[0]=b[(We-I%We)%We],E.e=-I||0):_[0]=E.e=0,E;if(S==0?(_.length=d,o=1,d--):(_.length=d+1,o=b[We-S],_[d]=h>0?$t(l/b[N-h]%b[h])*o:0),R)for(;;)if(d==0){for(S=1,h=_[0];h>=10;h/=10,S++);for(h=_[0]+=o,o=1;h>=10;h/=10,o++);S!=o&&(E.e++,_[0]==li&&(_[0]=1));break}else{if(_[d]+=o,_[d]!=li)break;_[d--]=0,o=1}for(S=_.length;_[--S]===0;_.pop());}E.e>y?E.c=E.e=null:E.e<v&&(E.c=[E.e=0])}return E}function ae(E){var I,O=E.e;return O===null?E.toString():(I=qt(E.c),I=O<=p||O>=g?on(I,O):Ei(I,O,"0"),E.s<0?"-"+I:I)}return n.absoluteValue=n.abs=function(){var E=new K(this);return E.s<0&&(E.s=1),E},n.comparedTo=function(E,I){return nr(this,new K(E,I))},n.decimalPlaces=n.dp=function(E,I){var O,R,N,S=this;if(E!=null)return _t(E,0,At),I==null?I=c:_t(I,0,8),Y(new K(S),E+S.e+1,I);if(!(O=S.c))return null;if(R=((N=O.length-1)-Ht(this.e/We))*We,N=O[N])for(;N%10==0;N/=10,R--);return R<0&&(R=0),R},n.dividedBy=n.div=function(E,I){return t(this,new K(E,I),a,c)},n.dividedToIntegerBy=n.idiv=function(E,I){return t(this,new K(E,I),0,1)},n.exponentiatedBy=n.pow=function(E,I){var O,R,N,S,h,o,l,d,m,_=this;if(E=new K(E),E.c&&!E.isInteger())throw Error(Rt+"Exponent not an integer: "+ae(E));if(I!=null&&(I=new K(I)),o=E.e>14,!_.c||!_.c[0]||_.c[0]==1&&!_.e&&_.c.length==1||!E.c||!E.c[0])return m=new K(Math.pow(+ae(_),o?E.s*(2-nn(E)):+ae(E))),I?m.mod(I):m;if(l=E.s<0,I){if(I.c?!I.c[0]:!I.s)return new K(NaN);R=!l&&_.isInteger()&&I.isInteger(),R&&(_=_.mod(I))}else{if(E.e>9&&(_.e>0||_.e<-1||(_.e==0?_.c[0]>1||o&&_.c[1]>=24e7:_.c[0]<8e13||o&&_.c[0]<=9999975e7)))return S=_.s<0&&nn(E)?-0:0,_.e>-1&&(S=1/S),new K(l?1/S:S);U&&(S=mo(U/We+2))}for(o?(O=new K(.5),l&&(E.s=1),d=nn(E)):(N=Math.abs(+ae(E)),d=N%2),m=new K(s);;){if(d){if(m=m.times(_),!m.c)break;S?m.c.length>S&&(m.c.length=S):R&&(m=m.mod(I))}if(N){if(N=$t(N/2),N===0)break;d=N%2}else if(E=E.times(O),Y(E,E.e+1,1),E.e>14)d=nn(E);else{if(N=+ae(E),N===0)break;d=N%2}_=_.times(_),S?_.c&&_.c.length>S&&(_.c.length=S):R&&(_=_.mod(I))}return R?m:(l&&(m=s.div(m)),I?m.mod(I):S?Y(m,U,c,h):m)},n.integerValue=function(E){var I=new K(this);return E==null?E=c:_t(E,0,8),Y(I,I.e+1,E)},n.isEqualTo=n.eq=function(E,I){return nr(this,new K(E,I))===0},n.isFinite=function(){return!!this.c},n.isGreaterThan=n.gt=function(E,I){return nr(this,new K(E,I))>0},n.isGreaterThanOrEqualTo=n.gte=function(E,I){return(I=nr(this,new K(E,I)))===1||I===0},n.isInteger=function(){return!!this.c&&Ht(this.e/We)>this.c.length-2},n.isLessThan=n.lt=function(E,I){return nr(this,new K(E,I))<0},n.isLessThanOrEqualTo=n.lte=function(E,I){return(I=nr(this,new K(E,I)))===-1||I===0},n.isNaN=function(){return!this.s},n.isNegative=function(){return this.s<0},n.isPositive=function(){return this.s>0},n.isZero=function(){return!!this.c&&this.c[0]==0},n.minus=function(E,I){var O,R,N,S,h=this,o=h.s;if(E=new K(E,I),I=E.s,!o||!I)return new K(NaN);if(o!=I)return E.s=-I,h.plus(E);var l=h.e/We,d=E.e/We,m=h.c,_=E.c;if(!l||!d){if(!m||!_)return m?(E.s=-I,E):new K(_?h:NaN);if(!m[0]||!_[0])return _[0]?(E.s=-I,E):new K(m[0]?h:c==3?-0:0)}if(l=Ht(l),d=Ht(d),m=m.slice(),o=l-d){for((S=o<0)?(o=-o,N=m):(d=l,N=_),N.reverse(),I=o;I--;N.push(0));N.reverse()}else for(R=(S=(o=m.length)<(I=_.length))?o:I,o=I=0;I<R;I++)if(m[I]!=_[I]){S=m[I]<_[I];break}if(S&&(N=m,m=_,_=N,E.s=-E.s),I=(R=_.length)-(O=m.length),I>0)for(;I--;m[O++]=0);for(I=li-1;R>o;){if(m[--R]<_[R]){for(O=R;O&&!m[--O];m[O]=I);--m[O],m[R]+=li}m[R]-=_[R]}for(;m[0]==0;m.splice(0,1),--d);return m[0]?se(E,m,d):(E.s=c==3?-1:1,E.c=[E.e=0],E)},n.modulo=n.mod=function(E,I){var O,R,N=this;return E=new K(E,I),!N.c||!E.s||E.c&&!E.c[0]?new K(NaN):!E.c||N.c&&!N.c[0]?new K(N):(k==9?(R=E.s,E.s=1,O=t(N,E,0,3),E.s=R,O.s*=R):O=t(N,E,0,k),E=N.minus(O.times(E)),!E.c[0]&&k==1&&(E.s=N.s),E)},n.multipliedBy=n.times=function(E,I){var O,R,N,S,h,o,l,d,m,_,b,w,f,u,M,q=this,$=q.c,z=(E=new K(E,I)).c;if(!$||!z||!$[0]||!z[0])return!q.s||!E.s||$&&!$[0]&&!z||z&&!z[0]&&!$?E.c=E.e=E.s=null:(E.s*=q.s,!$||!z?E.c=E.e=null:(E.c=[0],E.e=0)),E;for(R=Ht(q.e/We)+Ht(E.e/We),E.s*=q.s,l=$.length,_=z.length,l<_&&(f=$,$=z,z=f,N=l,l=_,_=N),N=l+_,f=[];N--;f.push(0));for(u=li,M=Di,N=_;--N>=0;){for(O=0,b=z[N]%M,w=z[N]/M|0,h=l,S=N+h;S>N;)d=$[--h]%M,m=$[h]/M|0,o=w*d+m*b,d=b*d+o%M*M+f[S]+O,O=(d/u|0)+(o/M|0)+w*m,f[S--]=d%u;f[S]=O}return O?++R:f.splice(0,1),se(E,f,R)},n.negated=function(){var E=new K(this);return E.s=-E.s||null,E},n.plus=function(E,I){var O,R=this,N=R.s;if(E=new K(E,I),I=E.s,!N||!I)return new K(NaN);if(N!=I)return E.s=-I,R.minus(E);var S=R.e/We,h=E.e/We,o=R.c,l=E.c;if(!S||!h){if(!o||!l)return new K(N/0);if(!o[0]||!l[0])return l[0]?E:new K(o[0]?R:N*0)}if(S=Ht(S),h=Ht(h),o=o.slice(),N=S-h){for(N>0?(h=S,O=l):(N=-N,O=o),O.reverse();N--;O.push(0));O.reverse()}for(N=o.length,I=l.length,N-I<0&&(O=l,l=o,o=O,I=N),N=0;I;)N=(o[--I]=o[I]+l[I]+N)/li|0,o[I]=li===o[I]?0:o[I]%li;return N&&(o=[N].concat(o),++h),se(E,o,h)},n.precision=n.sd=function(E,I){var O,R,N,S=this;if(E!=null&&E!==!!E)return _t(E,1,At),I==null?I=c:_t(I,0,8),Y(new K(S),E,I);if(!(O=S.c))return null;if(N=O.length-1,R=N*We+1,N=O[N]){for(;N%10==0;N/=10,R--);for(N=O[0];N>=10;N/=10,R++);}return E&&S.e+1>R&&(R=S.e+1),R},n.shiftedBy=function(E){return _t(E,-go,go),this.times("1e"+E)},n.squareRoot=n.sqrt=function(){var E,I,O,R,N,S=this,h=S.c,o=S.s,l=S.e,d=a+4,m=new K("0.5");if(o!==1||!h||!h[0])return new K(!o||o<0&&(!h||h[0])?NaN:h?S:1/0);if(o=Math.sqrt(+ae(S)),o==0||o==1/0?(I=qt(h),(I.length+l)%2==0&&(I+="0"),o=Math.sqrt(+I),l=Ht((l+1)/2)-(l<0||l%2),o==1/0?I="5e"+l:(I=o.toExponential(),I=I.slice(0,I.indexOf("e")+1)+l),O=new K(I)):O=new K(o+""),O.c[0]){for(l=O.e,o=l+d,o<3&&(o=0);;)if(N=O,O=m.times(N.plus(t(S,N,d,1))),qt(N.c).slice(0,o)===(I=qt(O.c)).slice(0,o))if(O.e<l&&--o,I=I.slice(o-3,o+1),I=="9999"||!R&&I=="4999"){if(!R&&(Y(N,N.e+a+2,0),N.times(N).eq(S))){O=N;break}d+=4,o+=4,R=1}else{(!+I||!+I.slice(1)&&I.charAt(0)=="5")&&(Y(O,O.e+a+2,1),E=!O.times(O).eq(S));break}}return Y(O,O.e+a+1,c,E)},n.toExponential=function(E,I){return E!=null&&(_t(E,0,At),E++),X(this,E,I,1)},n.toFixed=function(E,I){return E!=null&&(_t(E,0,At),E=E+this.e+1),X(this,E,I)},n.toFormat=function(E,I,O){var R,N=this;if(O==null)E!=null&&I&&typeof I=="object"?(O=I,I=null):E&&typeof E=="object"?(O=E,E=I=null):O=P;else if(typeof O!="object")throw Error(Rt+"Argument not an object: "+O);if(R=N.toFixed(E,I),N.c){var S,h=R.split("."),o=+O.groupSize,l=+O.secondaryGroupSize,d=O.groupSeparator||"",m=h[0],_=h[1],b=N.s<0,w=b?m.slice(1):m,f=w.length;if(l&&(S=o,o=l,l=S,f-=S),o>0&&f>0){for(S=f%o||o,m=w.substr(0,S);S<f;S+=o)m+=d+w.substr(S,o);l>0&&(m+=d+w.slice(S)),b&&(m="-"+m)}R=_?m+(O.decimalSeparator||"")+((l=+O.fractionGroupSize)?_.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(O.fractionGroupSeparator||"")):_):m}return(O.prefix||"")+R+(O.suffix||"")},n.toFraction=function(E){var I,O,R,N,S,h,o,l,d,m,_,b,w=this,f=w.c;if(E!=null&&(o=new K(E),!o.isInteger()&&(o.c||o.s!==1)||o.lt(s)))throw Error(Rt+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+ae(o));if(!f)return new K(w);for(I=new K(s),d=O=new K(s),R=l=new K(s),b=qt(f),S=I.e=b.length-w.e-1,I.c[0]=_o[(h=S%We)<0?We+h:h],E=!E||o.comparedTo(I)>0?S>0?I:d:o,h=y,y=1/0,o=new K(b),l.c[0]=0;m=t(o,I,0,1),N=O.plus(m.times(R)),N.comparedTo(E)!=1;)O=R,R=N,d=l.plus(m.times(N=d)),l=N,I=o.minus(m.times(N=I)),o=N;return N=t(E.minus(O),R,0,1),l=l.plus(N.times(d)),O=O.plus(N.times(R)),l.s=d.s=w.s,S=S*2,_=t(d,R,S,c).minus(w).abs().comparedTo(t(l,O,S,c).minus(w).abs())<1?[d,R]:[l,O],y=h,_},n.toNumber=function(){return+ae(this)},n.toPrecision=function(E,I){return E!=null&&_t(E,1,At),X(this,E,I,2)},n.toString=function(E){var I,O=this,R=O.s,N=O.e;return N===null?R?(I="Infinity",R<0&&(I="-"+I)):I="NaN":(E==null?I=N<=p||N>=g?on(qt(O.c),N):Ei(qt(O.c),N,"0"):E===10&&j?(O=Y(new K(O),a+N+1,c),I=Ei(qt(O.c),O.e,"0")):(_t(E,2,W.length,"Base"),I=i(Ei(qt(O.c),N,"0"),10,E,R,!0)),R<0&&O.c[0]&&(I="-"+I)),I},n.valueOf=n.toJSON=function(){return ae(this)},n._isBigNumber=!0,n[Symbol.toStringTag]="BigNumber",n[Symbol.for("nodejs.util.inspect.custom")]=n.valueOf,e!=null&&K.set(e),K}function Ht(e){var t=e|0;return e>0||e===t?t:t-1}function qt(e){for(var t,i,r=1,n=e.length,s=e[0]+"";r<n;){for(t=e[r++]+"",i=We-t.length;i--;t="0"+t);s+=t}for(n=s.length;s.charCodeAt(--n)===48;);return s.slice(0,n+1||1)}function nr(e,t){var i,r,n=e.c,s=t.c,a=e.s,c=t.s,p=e.e,g=t.e;if(!a||!c)return null;if(i=n&&!n[0],r=s&&!s[0],i||r)return i?r?0:-c:a;if(a!=c)return a;if(i=a<0,r=p==g,!n||!s)return r?0:!n^i?1:-1;if(!r)return p>g^i?1:-1;for(c=(p=n.length)<(g=s.length)?p:g,a=0;a<c;a++)if(n[a]!=s[a])return n[a]>s[a]^i?1:-1;return p==g?0:p>g^i?1:-1}function _t(e,t,i,r){if(e<t||e>i||e!==$t(e))throw Error(Rt+(r||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function nn(e){var t=e.c.length-1;return Ht(e.e/We)==t&&e.c[t]%2!=0}function on(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function Ei(e,t,i){var r,n;if(t<0){for(n=i+".";++t;n+=i);e=n+e}else if(r=e.length,++t>r){for(n=i,t-=r;--t;n+=i);e+=n}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var i0=Ks(),_i=i0;import{linearlyInterpolate as s0,Side as or}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as a0,NORMALIZED_jugSUI_COINTYPE as l0,NORMALIZED_LBTC_COINTYPE as u0}from"@suilend/sui-fe";import r0 from"crypto";var an=new Uint8Array(256),sn=an.length;function vo(){return sn>an.length-16&&(r0.randomFillSync(an),sn=0),an.slice(sn,sn+=16)}var Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function Ws(e,t=0){return Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]}import n0 from"crypto";var wo={randomUUID:n0.randomUUID};function o0(e,t,i){if(wo.randomUUID&&!t&&!e)return wo.randomUUID();e=e||{};let r=e.random||(e.rng||vo)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){i=i||0;for(let n=0;n<16;++n)t[i+n]=r[n];return t}return Ws(r)}var ln=o0;import{getPackagerConfigs as c0}from"@cetusprotocol/common-sdk";var bo=10n;function zs(e){return e.depositedAmount.eq(0)?new _i(0):e.borrowedAmount.div(e.depositedAmount).times(100)}function yo(e){let t=zs(e);if(!t.gt(100))return s0(e.config.interestRate,"utilPercent","aprPercent",t)}function Xs(e){let t=zs(e),i=yo(e);if(!(i===void 0||t.gt(100)))return new _i(t.div(100)).times(i.div(100)).times(1-e.config.spreadFeeBps/1e4).times(100)}function Js(e,t,i,r){let{apiUrl:n}=c0(r.sdkOptions.suilend);e===or.DEPOSIT&&([a0,l0].includes(t.coinType)&&i.push({stats:{id:ln(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${n}/partners/LiqAg.png`,perDay:new _i(.036),side:or.DEPOSIT},obligationClaims:{}}),t.coinType===u0&&i.push({stats:{id:ln(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${n}/partners/Lombard Lux.png`,perDay:new _i(0),side:or.DEPOSIT},obligationClaims:{}}))}function Ys(e,t,i){return{...e,depositedAmount:t===or.DEPOSIT?_i.max(e.depositedAmount.plus(i),0):e.depositedAmount,borrowedAmount:t===or.BORROW?_i.max(e.borrowedAmount.plus(i),0):e.borrowedAmount}}function Qs(e,t,i){let r=e===or.DEPOSIT?t.depositedAmount:t.borrowedAmount,n=e===or.DEPOSIT?i.depositedAmount:i.borrowedAmount,s=n.eq(0)?new _i(-1):r.div(n);return{multiplier:s,isValid:!s.eq(-1)}}function ea(e,t,i,r){let n=e.map(a=>({...a,stats:{...a.stats,perDay:r?a.stats.perDay.times(i):void 0}})),s=t.map(a=>({...a,stats:{...a.stats,aprPercent:r?a.stats.aprPercent.times(i):void 0}}));return{newPerDayRewards:n,newAprRewards:s}}function ta(e,t){if(!bo)throw new Error("oraclePriceMultiplierDecimal is required");if(e===0n)throw new Error("Invalid oracle price");if(t<0n){let i=10n**(bo- -t);return e*i}return e/10n**(t+bo)}import{d as Ur,getPackagerConfigs as hr,removeHexPrefix as na}from"@cetusprotocol/common-sdk";import{toHEX as y0}from"@mysten/sui/utils";var un=class{constructor(t){this.getSuiLendCoinInfo=(t,i)=>{let{allLendingMarketData:r,lstAprPercentMap:n}=this.lendingMarketCache??{};if(!r||!n)throw new Error("lendingMarketCache is not initialized");let s=Object.values(r??{})[0],a=s.lendingMarket.reserves.find(ae=>ae.coinType===t);if(!a)throw new Error("reserve not found");let c=this.obligationsCache?.[s.lendingMarket.id],p="borrow",g=c.rewardMap[a.token.coinType]?.[p]??[],v=g0(g);Js(p,a,v,this.sdk);let y=_0(p,a.coinType,n),A=p===ia.DEPOSIT?a.depositAprPercent:a.borrowAprPercent,k=A,U=Ys(a,p,i);k=p===ia.DEPOSIT?Xs(U):yo(U);let{multiplier:P,isValid:W}=Qs(p,a,U),j=v0(v),K=w0(v),{newPerDayRewards:X,newAprRewards:Q}=ea(j,K,P,W),se=ra(p,A,v,y),Y=k===void 0||Q.some(ae=>ae.stats.aprPercent===void 0)?void 0:ra(p,k,Q,y);return{borrowLimit:a.config.borrowLimit.toString(),borrowedAmount:a.borrowedAmount.toString(),remainingBorrowLimit:Ur(a.config.borrowLimit.toString()).sub(Ur(a.borrowedAmount.toString())).toString(),depositAprPercent:a.depositAprPercent.toString(),totalAprPercent:se.toString(),borrowInterest:A.toString(),stakingYieldAprPercent:y?.toString(),rewardAprPercent:K[0]?.stats.aprPercent?.toString()}};this.createObligation=async t=>{let{lendingMarketId:i,lendingMarketType:r}=hr(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(i,r)).createObligation(t)};this.refreshReservePrices=async(t,i,r)=>{let{lendingMarketId:n,lendingMarketType:s}=hr(this.sdk.sdkOptions?.suilend),a=`${n}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let c=await this.suilendClientCache[a].pythClient.getPriceFeedObjectId(i);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",c),this.suilendClientCache[a].pythConnection.getLatestPriceFeeds,this.suilendClientCache[a].refreshReservePrices(t,c,r)};this.getLatestPriceFeeds=async t=>{let{lendingMarketId:i,lendingMarketType:r}=hr(this.sdk.sdkOptions?.suilend),n=`${i}_${r}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let s=Array.from(new Set(t.map(p=>y0(new Uint8Array(p.priceIdentifier.bytes))))),a=await this.suilendClientCache[n].pythConnection.getLatestPriceFeeds(s),c={};return a?.forEach((p,g)=>{let v=p.getPriceUnchecked(),y=t[g];if(v){let{price:A,expo:k}=v,U=Ur(A).mul(Ur(10).pow(Ur(k))).toString(),P={coin_type:y.coinType.name,price:U,oracle_price:0n,last_update_time:v.publishTime};P.oracle_price=ta(BigInt(A),BigInt(k)),c[y.coinType.name]=P,this.sdk.updateCache(`getLatestPrice_${P.coin_type}`,P)}}),c};this.getSuiLendReserveInfo=async(t,i)=>{let{lendingMarketId:r}=hr(this.sdk.sdkOptions?.suilend),{allLendingMarketData:n}=await this.getLendingMarketData(),s=n[r].reserveMap[t],a=n[r].reserveMap[i],c=n[r].refreshedRawReserves.filter(p=>p.coinType.name==na(t)||p.coinType.name==na(i));return{baseReserveArrayIndex:s.arrayIndex.toString(),quoteReserveArrayIndex:a.arrayIndex.toString(),reserve:c}};this.sdk=t}async getSuilendClient(t,i){let r=`${t}_${i}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[r]||(this.suilendClientCache[r]=await d0.initialize(t,i,this.sdk.FullClient,!0)),this.suilendClientCache[r]}async getLendingMarketData(t=!1){if(!t&&this.lendingMarketCache)return this.lendingMarketCache;let i=hr(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!i.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[r,n]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(i.map(async a=>{let c=await this.getSuilendClient(a.id,a.type),{lendingMarket:p,coinMetadataMap:g,refreshedRawReserves:v,reserveMap:y,reserveCoinTypes:A,reserveCoinMetadataMap:k,rewardCoinTypes:U,activeRewardCoinTypes:P,rewardCoinMetadataMap:W}=await h0(this.sdk.FullClient,c),{rewardPriceMap:j}=await f0(y,P);return[a.id,{suilendClient:c,lendingMarket:p,coinMetadataMap:g,refreshedRawReserves:v,reserveMap:y,reserveCoinTypes:A,reserveCoinMetadataMap:k,rewardPriceMap:j,rewardCoinTypes:U,activeRewardCoinTypes:P,rewardCoinMetadataMap:W}]}))))(),(async()=>{try{let s=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),a=await s.json();if(s?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(a).map(([c,p])=>[c,new _i(p)]))}catch(s){return console.error(s),{}}})()]);return this.lendingMarketCache={allLendingMarketData:r,lstAprPercentMap:n},this.lendingMarketCache}catch(r){throw console.log("\u{1F680} getLendingMarketData error:",r),r}}async getInitializeObligations(t,i=!1){if(!i&&this.obligationsCache)return this.obligationsCache;t||(t=await this.getLendingMarketData());let r={};for(let n of Object.values(t.allLendingMarketData)){let{obligationOwnerCaps:s,obligations:a}=await p0(this.sdk.FullClient,n.suilendClient,n.refreshedRawReserves,n.reserveMap,this.sdk.senderAddress),c=m0(n.reserveMap,n.rewardCoinMetadataMap,n.rewardPriceMap,a);r[n.lendingMarket.id]={obligationOwnerCaps:s,obligations:a,rewardMap:c}}return this.obligationsCache=r,this.obligationsCache}async getSuiLendUserData(t,i=!1){let{lstAprPercentMap:r}=this.lendingMarketCache??{},n=this.obligationsCache??{},{lendingMarketId:s}=hr(this.sdk.sdkOptions?.suilend),a=n[s];if(!a)throw new Error(`No user data found for lending market: ${s}`);if(t){let c=a.obligations.find(g=>g.id===t);if(!c)throw new Error(`Obligation not found: ${t}`);let p=b0(c,a.rewardMap,r??{});return{obligation:c,netAprPercent:p,deposits:c.deposits,borrowedAmount:c.borrowedAmount,depositedAmount:c.depositedAmount,netValueUsd:c.netValueUsd,rewardMap:a.rewardMap}}}priceCheck(t,i=60){let r=Math.floor(Date.now()/1e3);if(!(Math.abs(r-t.last_update_time)>i))return t}};import{getPackagerConfigs as bt,CACHE_TIME_5MIN as Sa,CoinAssist as mt,CLOCK_ADDRESS as $i,d as Xe,removeHexPrefix as Ca}from"@cetusprotocol/common-sdk";var fr=9e15,qi=1e9,Mo="0123456789abcdef",hn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",fn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ao={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-fr,maxE:fr,crypto:!1},la,Ii,Le=!0,mn="[DecimalError] ",ji=mn+"Invalid argument: ",ua=mn+"Precision limit exceeded",ca=mn+"crypto unavailable",da="[object Decimal]",Pt=Math.floor,wt=Math.pow,M0=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,A0=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,S0=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ha=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ui=1e7,Pe=7,C0=9007199254740991,E0=hn.length-1,So=fn.length-1,re={toStringTag:da};re.absoluteValue=re.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),ke(e)};re.ceil=function(){return ke(new this.constructor(this),this.e+1,2)};re.clampedTo=re.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(ji+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};re.comparedTo=re.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};re.cosine=re.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Pe,r.rounding=1,i=I0(r,_a(r,i)),r.precision=e,r.rounding=t,ke(Ii==2||Ii==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};re.cubeRoot=re.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for(Le=!1,s=v.s*wt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Et(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=wt(i,1/3),e=Pt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=tt(g.plus(v).times(c),g.plus(p),a+2,1),Et(c.d).slice(0,a)===(i=Et(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(ke(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(ke(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return Le=!0,ke(r,e,y.rounding,t)};re.decimalPlaces=re.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-Pt(this.e/Pe))*Pe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};re.dividedBy=re.div=function(e){return tt(this,new this.constructor(e))};re.dividedToIntegerBy=re.divToInt=function(e){var t=this,i=t.constructor;return ke(tt(t,new i(e),0,1,1),i.precision,i.rounding)};re.equals=re.eq=function(e){return this.cmp(e)===0};re.floor=function(){return ke(new this.constructor(this),this.e+1,3)};re.greaterThan=re.gt=function(e){return this.cmp(e)>0};re.greaterThanOrEqualTo=re.gte=function(e){var t=this.cmp(e);return t==1||t===0};re.hyperbolicCosine=re.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/_n(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=pr(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return ke(s,a.precision=i,a.rounding=r,!0)};re.hyperbolicSine=re.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=pr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/_n(5,e)),n=pr(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,ke(n,t,i,!0)};re.hyperbolicTangent=re.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,tt(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};re.inverseCosine=re.acos=function(){var e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?vi(t,r,n):new t(0):new t(NaN):e.isZero()?vi(t,r+4,n).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=n,e.times(2))};re.inverseHyperbolicCosine=re.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,Le=!1,i=i.times(i).minus(1).sqrt().plus(i),Le=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};re.inverseHyperbolicSine=re.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,Le=!1,i=i.times(i).plus(1).sqrt().plus(i),Le=!0,r.precision=e,r.rounding=t,i.ln())};re.inverseHyperbolicTangent=re.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?ke(new s(n),e,t,!0):(s.precision=i=r-n.e,n=tt(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};re.inverseSine=re.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=vi(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};re.inverseTangent=re.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=So)return a=vi(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=So)return a=vi(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/Pe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Le=!1,t=Math.ceil(c/Pe),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),Le=!0,ke(a,v.precision=y,v.rounding=A,!0)};re.isFinite=function(){return!!this.d};re.isInteger=re.isInt=function(){return!!this.d&&Pt(this.e/Pe)>this.d.length-2};re.isNaN=function(){return!this.s};re.isNegative=re.isNeg=function(){return this.s<0};re.isPositive=re.isPos=function(){return this.s>0};re.isZero=function(){return!!this.d&&this.d[0]===0};re.lessThan=re.lt=function(e){return this.cmp(e)<0};re.lessThanOrEqualTo=re.lte=function(e){return this.cmp(e)<1};re.logarithm=re.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if(Le=!1,c=y+k,a=Ui(g,c),r=t?pn(v,c+10):Ui(e,c),p=tt(a,r,c,1),jr(p.d,n=y,A))do if(c+=10,a=Ui(g,c),r=t?pn(v,c+10):Ui(e,c),p=tt(a,r,c,1),!s){+Et(p.d).slice(n+1,n+15)+1==1e14&&(p=ke(p,y+1,0));break}while(jr(p.d,n+=10,A));return Le=!0,ke(p,y,A)};re.minus=re.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return Le?ke(e,c,p):e}if(i=Pt(e.e/Pe),v=Pt(k.e/Pe),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/Pe),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=ui-1;--g[n],g[r]+=ui}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=gn(g,i),Le?ke(e,c,p):e):new U(p===3?-0:0)};re.modulo=re.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?ke(new r(i),r.precision,r.rounding):(Le=!1,r.modulo==9?(t=tt(i,e.abs(),0,3,1),t.s*=e.s):t=tt(i,e,0,r.modulo,1),t=t.times(e),Le=!0,i.minus(t))};re.naturalExponential=re.exp=function(){return Co(this)};re.naturalLogarithm=re.ln=function(){return Ui(this)};re.negated=re.neg=function(){var e=new this.constructor(this);return e.s=-e.s,ke(e)};re.plus=re.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),Le?ke(e,c,p):e;if(s=Pt(y.e/Pe),r=Pt(e.e/Pe),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/Pe),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/ui|0,g[n]%=ui;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=gn(g,r),Le?ke(e,c,p):e};re.precision=re.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ji+e);return i.d?(t=fa(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};re.round=function(){var e=this,t=e.constructor;return ke(new t(e),e.e+1,t.rounding)};re.sine=re.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Pe,r.rounding=1,i=T0(r,_a(r,i)),r.precision=e,r.rounding=t,ke(Ii>2?i.neg():i,e,t,!0)):new r(NaN)};re.squareRoot=re.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for(Le=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Et(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Pt((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(tt(a,s,i+2,1)).times(.5),Et(s.d).slice(0,i)===(t=Et(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(ke(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(ke(r,p+1,1),e=!r.times(r).eq(a));break}return Le=!0,ke(r,p,v.rounding,e)};re.tangent=re.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=tt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,ke(Ii==2||Ii==4?i.neg():i,e,t,!0)):new r(NaN)};re.times=re.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=Pt(v.e/Pe)+Pt(e.e/Pe),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%ui|0,t=c/ui|0;s[n]=(s[n]+t)%ui|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=gn(s,i),Le?ke(e,y.precision,y.rounding):e};re.toBinary=function(e,t){return Eo(this,2,e,t)};re.toDecimalPlaces=re.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Lt(e,0,qi),t===void 0?t=r.rounding:Lt(t,0,8),ke(i,e+i.e+1,t))};re.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=wi(r,!0):(Lt(e,0,qi),t===void 0?t=n.rounding:Lt(t,0,8),r=ke(new n(r),e+1,t),i=wi(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};re.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=wi(n):(Lt(e,0,qi),t===void 0?t=s.rounding:Lt(t,0,8),r=ke(new s(n),e+n.e+1,t),i=wi(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};re.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=fa(U)-k.e-1,a=s%Pe,t.d[0]=wt(10,a<0?Pe+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(ji+c);e=c.gt(t)?s>0?t:g:c}for(Le=!1,c=new P(Et(U)),v=P.precision,P.precision=s=U.length*Pe*2;y=tt(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=tt(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=tt(g,r,s,1).minus(k).abs().cmp(tt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,Le=!0,A};re.toHexadecimal=re.toHex=function(e,t){return Eo(this,16,e,t)};re.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Lt(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(Le=!1,i=tt(i,e,0,t,1).times(e),Le=!0,ke(i)):(e.s=i.s,i=e),i};re.toNumber=function(){return+this};re.toOctal=function(e,t){return Eo(this,8,e,t)};re.toPower=re.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(wt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return ke(c,r,s);if(t=Pt(e.e/Pe),t>=e.d.length-1&&(i=g<0?-g:g)<=C0)return n=pa(p,c,i,r),e.s<0?new p(1).div(n):ke(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=wt(+c,g),t=i==0||!isFinite(i)?Pt(g*(Math.log("0."+Et(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):(Le=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Co(e.times(Ui(c,r+i)),r),n.d&&(n=ke(n,r+5,1),jr(n.d,r,s)&&(t=r+10,n=ke(Co(e.times(Ui(c,t+i)),t),t+5,1),+Et(n.d).slice(r+1,r+15)+1==1e14&&(n=ke(n,r+1,0)))),n.s=a,Le=!0,p.rounding=s,ke(n,r,s))};re.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=wi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Lt(e,1,qi),t===void 0?t=n.rounding:Lt(t,0,8),r=ke(new n(r),e,t),i=wi(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};re.toSignificantDigits=re.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Lt(e,1,qi),t===void 0?t=r.rounding:Lt(t,0,8)),ke(new r(i),e,t)};re.toString=function(){var e=this,t=e.constructor,i=wi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};re.truncated=re.trunc=function(){return ke(new this.constructor(this),this.e+1,1)};re.valueOf=re.toJSON=function(){var e=this,t=e.constructor,i=wi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Et(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=Pe-r.length,i&&(s+=Bi(i)),s+=r;a=e[t],r=a+"",i=Pe-r.length,i&&(s+=Bi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Lt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(ji+e)}function jr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Pe,n=0):(n=Math.ceil((t+1)/Pe),t%=Pe),s=wt(10,Pe-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==wt(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==wt(10,t-3)-1,a}function cn(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=Mo.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function I0(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/_n(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=pr(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var tt=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,ae,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=ui,k=Pe,v=Pt(r.e/k)-Pt(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,la=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,ke(j,c?s+j.e+1:s,a,U)}return j}})();function ke(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=Pe,a=t,v=y[A=0],p=v/wt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Pe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Pe,a=s-Pe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Pe,a=s-Pe+n,p=a<0?0:v/wt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%wt(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/wt(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=wt(10,(Pe-t%Pe)%Pe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=wt(10,Pe-s),y[A]=a>0?(v/wt(10,n-a)%wt(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==ui&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=ui)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return Le&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function wi(e,t,i){if(!e.isFinite())return ga(e);var r,n=e.e,s=Et(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Bi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Bi(-n-1)+s,i&&(r=i-a)>0&&(s+=Bi(r))):n>=a?(s+=Bi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Bi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Bi(r))),s}function gn(e,t){var i=e[0];for(t*=Pe;i>=10;i/=10)t++;return t}function pn(e,t,i){if(t>E0)throw Le=!0,i&&(e.precision=i),Error(ua);return ke(new e(hn),t,1,!0)}function vi(e,t,i){if(t>So)throw Error(ua);return ke(new e(fn),t,i,!0)}function fa(e){var t=e.length-1,i=t*Pe+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function Bi(e){for(var t="";e--;)t+="0";return t}function pa(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Pe+4);for(Le=!1;;){if(i%2&&(s=s.times(t),sa(s.d,a)&&(n=!0)),i=Pt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),sa(t.d,a)}return Le=!0,s}function oa(e){return e.d[e.d.length-1]&1}function ma(e,t,i){for(var r,n,s=new e(t[0]),a=0;++a<t.length;){if(n=new e(t[a]),!n.s){s=n;break}r=s.cmp(n),(r===i||r===0&&s.s===i)&&(s=n)}return s}function Co(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(Le=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(wt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=ke(s.times(e),p,1),i=i.times(++v),c=a.plus(tt(s,i,p,1)),Et(c.d).slice(0,p)===Et(a.d).slice(0,p)){for(n=y;n--;)a=ke(a.times(a),p,1);if(t==null)if(g<3&&jr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return ke(a,A.precision=U,k,Le=!0);else return A.precision=U,a}a=c}}function Ui(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?(Le=!1,v=X):v=t,j.precision=v+=U,i=Et(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=Et(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=pn(j,v+2,X).times(s+""),P=Ui(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?ke(P,X,K,Le=!0):P;for(y=P,p=a=P=tt(P.minus(1),P.plus(1),v,1),A=ke(P.times(P),v,1),n=3;;){if(a=ke(a.times(A),v,1),g=p.plus(tt(a,new j(n),v,1)),Et(g.d).slice(0,v)===Et(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(pn(j,v+2,X).times(s+""))),p=tt(p,new j(k),v,1),t==null)if(jr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=tt(y.minus(1),y.plus(1),v,1),A=ke(P.times(P),v,1),n=c=1;else return ke(p,j.precision=X,K,Le=!0);else return j.precision=X,p;p=g,n+=2}}function ga(e){return String(e.s*e.s/0)}function dn(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%Pe,i<0&&(r+=Pe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Pe;r<n;)e.d.push(+t.slice(r,r+=Pe));t=t.slice(r),r=Pe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),Le&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function k0(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),ha.test(t))return dn(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(A0.test(t))i=16,t=t.toLowerCase();else if(M0.test(t))i=2;else if(S0.test(t))i=8;else throw Error(ji+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=pa(r,new r(i),s,s*2)),g=cn(t,i,ui),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=gn(g,v),e.d=g,Le=!1,a&&(e=tt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?wt(2,p):qr.pow(2,p))),Le=!0,e)}function T0(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:pr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/_n(5,i)),t=pr(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function pr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Pe);for(Le=!1,p=i.times(i),c=new e(r);;){if(a=tt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=tt(a.times(p),new e(t++*t++),v,1),a=c.plus(r),a.d[y]!==void 0){for(s=y;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s,g++}return Le=!0,a.d.length=y+1,a}function _n(e,t){for(var i=e;--t;)i*=e;return i}function _a(e,t){var i,r=t.s<0,n=vi(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ii=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ii=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ii=oa(i)?r?2:3:r?4:1,t;Ii=oa(i)?r?1:4:r?3:2}return t.minus(n).abs()}function Eo(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Lt(i,1,qi),r===void 0?r=k.rounding:Lt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=ga(e);else{for(v=wi(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=cn(wi(A),10,n),A.e=A.d.length),y=cn(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=tt(e,A,i,r,0,n),y=e.d,s=e.e,g=la),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=Mo.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=cn(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=Mo.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function sa(e,t){if(e.length>t)return e.length=t,!0}function O0(e){return new this(e).abs()}function P0(e){return new this(e).acos()}function x0(e){return new this(e).acosh()}function N0(e,t){return new this(e).plus(t)}function R0(e){return new this(e).asin()}function L0(e){return new this(e).asinh()}function F0(e){return new this(e).atan()}function D0(e){return new this(e).atanh()}function B0(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=vi(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?vi(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=vi(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(tt(e,t,s,1)),t=vi(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(tt(e,t,s,1)),i}function U0(e){return new this(e).cbrt()}function j0(e){return ke(e=new this(e),e.e+1,2)}function q0(e,t,i){return new this(e).clamp(t,i)}function $0(e){if(!e||typeof e!="object")throw Error(mn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,qi,"rounding",0,8,"toExpNeg",-fr,0,"toExpPos",0,fr,"maxE",0,fr,"minE",-fr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=Ao[i]),(r=e[i])!==void 0)if(Pt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(ji+i+": "+r);if(i="crypto",n&&(this[i]=Ao[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(ca);else this[i]=!1;else throw Error(ji+i+": "+r);return this}function H0(e){return new this(e).cos()}function G0(e){return new this(e).cosh()}function va(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,aa(s)){g.s=s.s,Le?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;Le?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return dn(g,s.toString())}if(p==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),ha.test(s)?dn(g,s):k0(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,dn(g,s.toString());throw Error(ji+s)}if(n.prototype=re,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=$0,n.clone=va,n.isDecimal=aa,n.abs=O0,n.acos=P0,n.acosh=x0,n.add=N0,n.asin=R0,n.asinh=L0,n.atan=F0,n.atanh=D0,n.atan2=B0,n.cbrt=U0,n.ceil=j0,n.clamp=q0,n.cos=H0,n.cosh=G0,n.div=V0,n.exp=Z0,n.floor=K0,n.hypot=W0,n.ln=z0,n.log=X0,n.log10=Y0,n.log2=J0,n.max=Q0,n.min=ec,n.mod=tc,n.mul=ic,n.pow=rc,n.random=nc,n.round=oc,n.sign=sc,n.sin=ac,n.sinh=lc,n.sqrt=uc,n.sub=cc,n.sum=dc,n.tan=hc,n.tanh=fc,n.trunc=pc,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function V0(e,t){return new this(e).div(t)}function Z0(e){return new this(e).exp()}function K0(e){return ke(e=new this(e),e.e+1,3)}function W0(){var e,t,i=new this(0);for(Le=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return Le=!0,new this(1/0);i=t}return Le=!0,i.sqrt()}function aa(e){return e instanceof qr||e&&e.toStringTag===da||!1}function z0(e){return new this(e).ln()}function X0(e,t){return new this(e).log(t)}function J0(e){return new this(e).log(2)}function Y0(e){return new this(e).log(10)}function Q0(){return ma(this,arguments,-1)}function ec(){return ma(this,arguments,1)}function tc(e,t){return new this(e).mod(t)}function ic(e,t){return new this(e).mul(t)}function rc(e,t){return new this(e).pow(t)}function nc(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Lt(e,1,qi),r=Math.ceil(e/Pe),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(ca);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Pe,r&&e&&(n=wt(10,Pe-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=Pe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Pe&&(i-=Pe-r)}return a.e=i,a.d=c,a}function oc(e){return ke(e=new this(e),e.e+1,this.rounding)}function sc(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function ac(e){return new this(e).sin()}function lc(e){return new this(e).sinh()}function uc(e){return new this(e).sqrt()}function cc(e,t){return new this(e).sub(t)}function dc(){var e=0,t=arguments,i=new this(t[e]);for(Le=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return Le=!0,ke(i,this.precision,this.rounding)}function hc(e){return new this(e).tan()}function fc(e){return new this(e).tanh()}function pc(e){return ke(e=new this(e),e.e+1,1)}re[Symbol.for("nodejs.util.inspect.custom")]=re.toString;re[Symbol.toStringTag]="Decimal";var qr=re.constructor=va(Ao);hn=new qr(hn);fn=new qr(fn);var bi=qr;var Oo=Gs(ba());import{Transaction as Hi}from"@mysten/sui/transactions";import{addHexPrefix as ya,getObjectFields as Ma}from"@cetusprotocol/common-sdk";var Aa=e=>{let t=[];return e.forEach(i=>{t.push(ko(i))}),t},ko=e=>{let t=Ma(e);return{marketId:t.id.id,baseToken:ya(t.base_token.fields.name),quoteToken:ya(t.quote_token.fields.name),isOpenPause:t.is_open_pause,isClosePause:t.is_close_pause,maxLongLeverage:t.max_long_leverage,maxShortLeverage:t.max_short_leverage,openFeeRate:(t.open_fee_rate/1e6).toString(),closeFeeRate:(t.close_fee_rate/1e6).toString(),positionsHandle:t.positions.fields.id.id}},To=e=>{let t=Ma(e);return{createdAt:t.created_ts,id:t.id.id,initDepositAmount:t.init_deposit_amount,isLong:t.is_long,lendingMarketId:t.lending_market_id,obligationOwnerCap:t.obligation_owner_cap.fields.obligation_id}};import{SUI_SYSTEM_STATE_OBJECT_ID as Ea,toHEX as $r}from"@mysten/sui/utils";import{parseObligation as mc}from"@suilend/sdk/parsers/obligation";import{obligation as gc}from"@suilend/sdk/_generated/suilend/lending-market/functions";var vn=class{constructor(t){this.getLeverageConfig=async()=>{let t=bt(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:t.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(t=!1)=>{let i="leverage_markets_list",r=this._sdk.getCache(i,t);if(r)return r;let n=bt(this._sdk.sdkOptions.leverage),s=50,a=null,c=[];for(;;){let A=await this._sdk.FullClient.getDynamicFields({parentId:n.markets_table_id,limit:s,cursor:a});if(A.data.forEach(k=>{c.push(k.objectId)}),A.data.length<s)break;a=A.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",c);let p=await this._sdk.FullClient.batchGetObjects(c,{showContent:!0}),g=[];p.forEach(A=>{g.push(A.data.content.fields.value.fields.market_id)});let v=await this._sdk.FullClient.batchGetObjects(g,{showContent:!0}),y=Aa(v);return this._sdk.updateCache(i,y,Sa),y};this.getLeverageMarketInfo=async t=>{let i=`leverage_market_info_${t}`,r=this._sdk.getCache(i);if(r)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),s=ko(n);return this._sdk.updateCache(i,s,Sa),s};this.getLeveragePositionList=async()=>{let t=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{Package:this._sdk.sdkOptions.leverage.package_id}]}}),{lendingMarketId:i,lendingMarketType:r}=bt(this._sdk.sdkOptions.suilend),n=await this._sdk.SuiLendModule.getSuilendClient(i,r),s=[];for(let a=0;a<t.data.length;a++){let c=To(t.data[a]),p=await n.getObligation(c.obligationOwnerCap);s.push({...c,...p})}return s};this.getLeveragePosition=async t=>{let i=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:t}}),r=To(i.data[0]),{lendingMarketId:n,lendingMarketType:s}=bt(this._sdk.sdkOptions.suilend),a=await this._sdk.SuiLendModule.getSuilendClient(n,s),{allLendingMarketData:c}=await this._sdk.SuiLendModule.getLendingMarketData(),p=c[n].reserveMap,g=await a.getObligation(r.obligationOwnerCap);return{...mc(g,p||{}),...r}};this.getClmmPoolInfo=async t=>{let i=await this._sdk.ClmmSDK.Pool.getPool(t),{coin_type_a:r,coin_type_b:n,fee_rate:s}=i;return{clmmFeeTier:s/1e6,clmmPoolCoinTypeA:r,clmmPoolCoinTypeB:n}};this.openLeveragePosition=async t=>{let{isQuote:i,isLong:r,depositAmount:n,clmmPool:s,slippage:a,leverage:c,marketId:p}=t,{lendingMarketId:g}=bt(this._sdk.sdkOptions.suilend),v=new Hi,{openFeeRate:y,baseToken:A,quoteToken:k}=await this.getLeverageMarketInfo(p),{clmmFeeTier:U,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}=await this.getClmmPoolInfo(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",U,P,W);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:K,reserve:X}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(A,k),Q=r&&i||!r&&!i;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",Q);let se=n.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",se);let Y,ae;if(Q){let $=r&&i?k:A,z=r&&i?A:k,ie=await this.findRouters($,z,n,!0,[s]);if(se=ie?.amount_out.toString(),ie){let C=mt.buildCoinWithBalance(BigInt(n.toString()),$,v);ae=await this.routerSwap({router:ie.route_obj,slippage:a,inputCoin:C,txb:v}),Y=ae}}else Y=mt.buildCoinWithBalance(BigInt(n.toString()),i?k:A,v);let{flashAmount:E}=await this.calculateFlashLoanParams({isLong:r,leverage:c,baseToken:A,quoteToken:k,initDepositAmount:se,reserve:X});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",E);let I=r?k:A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",I);let O=P===I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",P),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",O);let R=Xe(E).mul(U).toString(),{balanceA:N,balanceB:S,receipt:h}=this.flashLoan({amount:Xe(E),clmmPool:s,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W,flashLoanCoin:I,tx:v}),o=r?k:A,l=r?A:k,d=await this.findRouters(o,l,Xe(E),!0,[s]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:d,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W});let m=Xe(d?.amount_out||0),_;d&&(_=await this.routerSwap({router:d.route_obj,inputCoin:O?mt.fromBalance(N,P,v):mt.fromBalance(S,W,v),slippage:a,txb:v}));let b=Xe(m).add(se).mul(1-y).toDP(0,bi.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",b,se,m);let w=this.createLeveragePosition({leverage:c,marketId:p,baseToken:A,quoteToken:k,isLong:r,totalDepositAmount:b,tx:v});for(let $=0;$<X.length;$++){let z=$r(new Uint8Array(X[$].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(v,z,BigInt(X[$].arrayIndex))}let f=r?j:K;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",Y),await v.mergeCoins(_,[Y]),await this.depositToLeveragePosition({isLong:r,marketId:p,position:w,depositReserveArrayIndex:f,inputCoin:_},v);let u=Xe(E).add(R).toDP(0,bi.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",u,E,R);let M=await this.borrowAsset({position:w,reserveArrayIndex:r?K:j,borrowAmount:Xe(u),baseToken:A,quoteToken:k,isLong:r,lendingMarketId:g},v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",M);let q=mt.mintBalanceZero(O?W:P,v);return this.repayFlashLoan({tx:v,clmmPool:s,repayBase:O?mt.intoBalance(M,P,v):q,repayQuote:O?q:mt.intoBalance(M,W,v),receipt:h,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}),v.transferObjects([w],v.pure.address(this._sdk.getSenderAddress())),mt.destroyBalanceZero(O?S:N,O?W:P,v),v};this.positionManageSizeDeposit=async t=>{let{marketId:i,positionId:r,isQuote:n,depositAmount:s,clmmPool:a,slippage:c,leverage:p,txb:g}=t,{lendingMarketId:v}=bt(this._sdk.sdkOptions.suilend),{baseToken:y,quoteToken:A}=await this.getLeverageMarketInfo(i),{isLong:k,deposits:U,borrows:P}=await this.getLeveragePosition(r),{reserve:W}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(y,A),{clmmFeeTier:j,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}=await this.getClmmPoolInfo(a),Q=g||new Hi,se=U[0].reserveArrayIndex.toString(),Y=P[0].reserveArrayIndex.toString(),ae=n&&k||!n&&!k,E;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",ae);let I;if(ae){let M=n&&k?A:y,q=n&&k?y:A,$=await this.findRouters(M,q,s,!0,[a]);if($){let z=mt.buildCoinWithBalance(BigInt(s.toString()),M,Q);I=await this.routerSwap({router:$.route_obj,inputCoin:z,slippage:c,txb:Q}),E=I}}else E=mt.buildCoinWithBalance(BigInt(s.toString()),n?A:y,Q);let O=k?A:y;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",O);let{flashAmount:R}=await this.calculateFlashLoanParams({isLong:k,leverage:p,baseToken:y,quoteToken:A,initDepositAmount:s.toString(),reserve:W}),N=Xe(R).mul(j).toString(),S=K===O;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",S);let{balanceA:h,balanceB:o,receipt:l}=this.flashLoan({amount:Xe(R),clmmPool:a,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X,flashLoanCoin:O,tx:Q}),d=k?A:y,m=k?y:A,_=await this.findRouters(d,m,Xe(R),!0,[a]),b;_&&(b=await this.routerSwap({router:_.route_obj,inputCoin:S?mt.fromBalance(h,K,Q):mt.fromBalance(o,X,Q),slippage:c,txb:Q})),Q.mergeCoins(b,[E]);for(let M=0;M<W.length;M++){let q=$r(new Uint8Array(W[M].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(Q,q,BigInt(W[M].arrayIndex))}this.depositToLeveragePosition({isLong:k,marketId:i,positionId:r,depositReserveArrayIndex:se,inputCoin:b},Q);let w=Xe(R).add(N).toDP(0,bi.ROUND_UP).toString(),f=this.borrowAsset({positionId:r,reserveArrayIndex:Y,borrowAmount:Xe(w),baseToken:y,quoteToken:A,isLong:k,lendingMarketId:v},Q),u=mt.mintBalanceZero(S?X:K,Q);return this.repayFlashLoan({tx:Q,clmmPool:a,repayBase:S?mt.intoBalance(f,K,Q):u,repayQuote:S?u:mt.intoBalance(f,X,Q),receipt:l,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}),mt.destroyBalanceZero(S?o:h,S?X:K,Q),Q};this.positionManageSizeWithdraw=async t=>{let{marketId:i,positionId:r,withdrawAmount:n,isQuote:s,txb:a,clmmPool:c,slippage:p,leverage:g}=t,{lendingMarketType:v,lendingMarketId:y}=bt(this._sdk.sdkOptions.suilend),A=a||new Hi,{baseToken:k,quoteToken:U}=await this.getLeverageMarketInfo(i),{isLong:P,deposits:W,borrows:j}=await this.getLeveragePosition(r),{reserve:K}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(k,U),X=s&&P||!s&&!P;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",X);let Q=n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",Q);let se=null;if(X){let b=k,w=U;se=await this.findRouters(b,w,n,!1,[c]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:se,from:b,to:w}),Q=se?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",Q);for(let b=0;b<K.length;b++){let w=$r(new Uint8Array(K[b].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,w,BigInt(K[b].arrayIndex))}let{token:Y}=j[0].reserve,ae=Xe(W[0].depositedCtokenAmount.toString()).div(Xe(g)).toDP(0,bi.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",ae);let E=Xe(Q).div(Xe(ae)).toString(),I=Xe(j[0].borrowedAmount.toString()).mul(10**Y.decimals).toString(),O=Xe(I).mul(E).toDP(0,bi.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:O,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:Q,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:ae});let R=await this._sdk.SuiLendModule.getSuilendClient(y,v),N=await this._sdk.PythConnection.getPriceFeedsUpdateData([W[0].reserve.priceIdentifier]),S=await R.pythClient.updatePriceFeeds(A,N,[W[0].reserve.priceIdentifier]),h=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:Xe(Q),withdrawReserveArrayIndex:W[0].reserveArrayIndex.toString(),withdrawCoinType:P?k:U,baseToken:k,quoteToken:U,priceObjectId:S&&S[0]},A),o=P?k:U,l=P?U:k;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let d=await this.findRouters(o,l,Xe(O),!1,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:d,debtFrom:o,debtTo:l});let m;d&&(m=await this.routerSwap({router:d.route_obj,inputCoin:h,slippage:p,txb:A}));let _=A.splitCoins(m,[O]);return this.repay({txb:A,positionId:r,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:_,repayCoinType:P?U:k,repayAmount:Xe(0)}),A.transferObjects([m,_],this._sdk.getSenderAddress()),A};this.positionManageLeverageIncrease=async t=>{let{marketId:i,positionId:r,isLong:n,currentLeverage:s,targetLeverage:a,clmmPool:c,slippage:p}=t,{baseToken:g,quoteToken:v}=await this.getLeverageMarketInfo(i),{deposits:y,borrows:A}=await this.getLeveragePosition(r),{reserve:k}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),{clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,clmmFeeTier:W}=await this.getClmmPoolInfo(c),{lendingMarketId:j}=bt(this._sdk.sdkOptions.suilend),{token:K}=A[0].reserve,X=new Hi,Q=Xe(A[0].borrowedAmount.toString()).mul(Xe(a).sub(Xe(s))).mul(10**K.decimals).toDP(0,bi.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",Q);let se=Q,Y=n?v:g,{balanceA:ae,balanceB:E,receipt:I}=this.flashLoan({tx:X,amount:Xe(se),clmmPool:c,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,flashLoanCoin:Y}),O=n?v:g,R=n?g:v,N=await this.findRouters(O,R,Xe(Q),!0,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",N,O,R);let S=await this.routerSwap({router:N?.route_obj,inputCoin:n?mt.fromBalance(E,P,X):mt.fromBalance(ae,U,X),slippage:p,txb:X});for(let m=0;m<k.length;m++){let _=$r(new Uint8Array(k[m].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(X,_,BigInt(k[m].arrayIndex))}this.depositToLeveragePosition({isLong:n,marketId:i,positionId:r,depositReserveArrayIndex:n?y[0].reserveArrayIndex.toString():A[0].reserveArrayIndex.toString(),inputCoin:S},X);let h=Xe(se).mul(Xe(1).add(W)).toDP(0,bi.ROUND_UP).toString(),o=await this.borrowAsset({positionId:r,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:Xe(h),baseToken:g,quoteToken:v,isLong:n,lendingMarketId:j},X),l=mt.mintBalanceZero(n?g:v,X),d=U===Y;return this.repayFlashLoan({tx:X,clmmPool:c,repayBase:n?l:mt.intoBalance(o,g,X),repayQuote:n?mt.intoBalance(o,v,X):l,receipt:I,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P}),mt.destroyBalanceZero(d?E:ae,d?P:U,X),X};this.positionManageLeverageDecrease=async t=>{let{marketId:i,positionId:r,isLong:n,currentLeverage:s,targetLeverage:a,clmmPool:c,slippage:p}=t,{baseToken:g,quoteToken:v,closeFeeRate:y}=await this.getLeverageMarketInfo(i),{deposits:A,borrows:k}=await this.getLeveragePosition(r),{reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),{lendingMarketId:P,lendingMarketType:W}=bt(this._sdk.sdkOptions.suilend),j=new Hi,K=Xe(A[0].depositedCtokenAmount.toString()).mul(Xe(s).sub(Xe(a))).toString(),X=Xe(K).toDP(0,bi.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",X);for(let N=0;N<U.length;N++){let S=$r(new Uint8Array(U[N].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,S,BigInt(U[N].arrayIndex))}let Q=await this._sdk.SuiLendModule.getSuilendClient(P,W),se=await this._sdk.PythConnection.getPriceFeedsUpdateData([A[0].reserve.priceIdentifier]),Y=await Q.pythClient.updatePriceFeeds(j,se,[A[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",g);let ae=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:Xe(X),withdrawReserveArrayIndex:A[0].reserveArrayIndex.toString(),withdrawCoinType:n?g:v,baseToken:g,quoteToken:v,priceObjectId:Y&&Y[0]},j),E=n?g:v,I=n?v:g,O=await this.findRouters(E,I,Xe(X),!0,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",O,O?.route_obj.paths,E,I);let R=await this.routerSwap({router:O?.route_obj,inputCoin:ae,slippage:p,txb:j});return this.repay({txb:j,positionId:r,repayReserveArrayIndex:k[0].reserveArrayIndex.toString(),repayCoin:R,repayCoinType:n?v:g,repayAmount:Xe(0)}),R&&j.transferObjects([R],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(t,i)=>{let r=i||new Hi,{marketId:n,positionId:s}=t,{leverage:a}=this._sdk.sdkOptions,{global_config_id:c}=bt(this._sdk.sdkOptions.leverage),{lendingMarketType:p,lendingMarketId:g}=bt(this._sdk.sdkOptions.suilend),{baseToken:v,quoteToken:y}=await this.getLeverageMarketInfo(n),A=await this.getLeveragePosition(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:541 ~ LeverageModules ~ positionInfo:",A.original.id);let k=gc(r,p,{obligationId:A.original.id,lendingMarket:r.object(g)});return r.moveCall({target:`${a.published_at}::position::close_Position`,typeArguments:[p,v,y],arguments:[r.object(c),r.object(n),r.object(s),k,r.object($i)]}),r};this.flashLoan=t=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",t);let{clmm_pool:i}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:r}=bt(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:n,clmmPool:s,clmmPoolCoinTypeA:a,clmmPoolCoinTypeB:c,flashLoanCoin:p,tx:g}=t,v=a===p,[y,A,k]=g.moveCall({target:`${i.published_at}::pool::flash_loan`,arguments:[g.object(r),g.object(s),g.pure.bool(v),g.pure.u64(n.toString())],typeArguments:[a,c]});return{balanceA:y,balanceB:A,receipt:k}};this.repayFlashLoan=t=>{let{clmm_pool:i}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:r}=bt(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:n,repayBase:s,repayQuote:a,receipt:c,clmmPool:p,clmmPoolCoinTypeA:g,clmmPoolCoinTypeB:v}=t;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",t),n.moveCall({target:`${i.published_at}::pool::repay_flash_loan`,arguments:[n.object(r),n.object(p),s,a,c],typeArguments:[g,v]}),n};this.borrowAsset=(t,i)=>{let{position:r,reserveArrayIndex:n,borrowAmount:s,baseToken:a,quoteToken:c,lendingMarketId:p,isLong:g,positionId:v}=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",t);let{leverage:y}=this._sdk.sdkOptions,{lendingMarketType:A}=bt(this._sdk.sdkOptions.suilend);return mt.isSuiCoin(g?c:a)?i.moveCall({target:`${y.published_at}::position::borrow_sui`,typeArguments:[A],arguments:[i.object(p),r,i.pure.u64(n),i.pure.u64(s.toString()),i.object(Ea),i.object($i)]}):i.moveCall({target:`${y.published_at}::position::borrow_not_sui`,typeArguments:[A,g?c:a],arguments:[i.object(p),v?i.object(v):r,i.pure.u64(n),i.pure.u64(s.toString()),i.object($i)]})};this.withdrawAsset=(t,i)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",t);let{leverage:r}=this._sdk.sdkOptions,{lendingMarketId:n,lendingMarketType:s}=bt(this._sdk.sdkOptions.suilend),{package_id:a}=this._sdk.sdkOptions.suilend,{marketId:c,positionId:p,withdrawAmount:g,withdrawReserveArrayIndex:v,withdrawCoinType:y,baseToken:A,quoteToken:k,priceObjectId:U}=t,[P]=i.moveCall({target:"0x1::option::none",typeArguments:[`${a}::lending_market::RateLimiterExemption<${s}, ${y}>`],arguments:[]});return mt.isSuiCoin(y)?i.moveCall({target:`${r.published_at}::position::withdraw_sui`,typeArguments:[s,A,k],arguments:[i.object(n),i.object(c),i.object(p),i.object(U),i.object(P),i.pure.u64(g.toString()),i.pure.u64(v),i.object(Ea),i.object($i)]}):i.moveCall({target:`${r.published_at}::position::withdraw_not_sui`,typeArguments:[s,A,k,y],arguments:[i.object(n),i.object(c),i.object(p),i.object(U),i.object(P),i.pure.u64(g.toString()),i.pure.u64(v),i.object($i)]})};this.repay=t=>{let{leverage:i}=this._sdk.sdkOptions,{lendingMarketId:r,lendingMarketType:n}=bt(this._sdk.sdkOptions.suilend),{txb:s,positionId:a,repayAmount:c,repayCoinType:p,repayCoin:g,repayReserveArrayIndex:v}=t,y=s||new Hi,A=g||mt.buildCoinWithBalance(BigInt(c.toString()),p,y);y.moveCall({target:`${i.published_at}::position::repay`,typeArguments:[n,p],arguments:[y.object(r),y.object(a),y.object(A),y.pure.u64(v.toString()),y.object($i)]})};this.routerSwap=async t=>{let{slippage:i,txb:r,inputCoin:n,router:s}=t,a=r||new Hi;if(s)return await this._sdk.AggregatorClient.routerSwap({router:s,inputCoin:n,slippage:i,txb:a})};this.calculateOpenPosition=async t=>{let{isQuote:i,isLong:r,depositAmount:n,clmmPool:s,slippage:a,leverage:c,marketId:p}=t,{baseToken:g,quoteToken:v}=await this.getLeverageMarketInfo(p),{reserve:y}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),A=r&&i||!r&&!i;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",A);let k=n.toString();if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",k),A){let K=r&&i?v:g,X=r&&i?g:v;k=(await this.findRouters(K,X,n,!0,[s]))?.amount_out.toString()}let{flashAmount:U}=await this.calculateFlashLoanParams({isLong:r,leverage:c,baseToken:g,quoteToken:v,initDepositAmount:k,reserve:y});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",U);let P=r?v:g,W=r?g:v,j=await this.findRouters(P,W,Xe(U),!0,[s]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",j),j};this._sdk=t}async calculateFlashLoanParams(t){let{isLong:i,leverage:r,baseToken:n,quoteToken:s,initDepositAmount:a,reserve:c}=t,p=await this._sdk.SuiLendModule.getLatestPriceFeeds(c);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",p,s,n);let g=p[Ca(s)]?.price,v=p[Ca(n)]?.price,y=i?Xe(v).div(Xe(g)).toString():Xe(g).div(Xe(v)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",a.toString(),i,y,g,v),{flashAmount:Xe(a).mul(r-1).mul(y).toDP(0,bi.ROUND_UP).toString(),rate:y,quotePrice:g,basePrice:v}}createLeveragePosition(t){let{lendingMarketId:i,lendingMarketType:r}=bt(this._sdk.sdkOptions.suilend),{global_config_id:n}=bt(this._sdk.sdkOptions.leverage),s=this._sdk.sdkOptions.leverage,{leverage:a,marketId:c,baseToken:p,quoteToken:g,isLong:v,totalDepositAmount:y,tx:A}=t;return A.moveCall({target:`${s.published_at}::position::open_position`,arguments:[A.object(n),A.object(c),A.object(i),A.pure.u64(y),A.pure.u64(a*1e4),A.object($i)],typeArguments:[r,p,g,v?p:g]})}async depositToLeveragePosition(t,i){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",t);let{leverage:r}=this._sdk.sdkOptions,{lendingMarketType:n,lendingMarketId:s}=bt(this._sdk.sdkOptions.suilend),{isLong:a,marketId:c,position:p,positionId:g,depositReserveArrayIndex:v,inputCoin:y}=t,{baseToken:A,quoteToken:k}=await this.getLeverageMarketInfo(c);return i.moveCall({target:`${r.published_at}::position::deposit`,typeArguments:[n,A,k,a?A:k],arguments:[i.object(s),i.object(c),p||i.object(g),y,i.pure.u64(v),i.object($i)]}),i}async findRouters(t,i,r,n,s){let{providers:a}=this._sdk.sdkOptions;try{let c={from:t,target:i,amount:new Oo.default(r.toFixed(0).toString()),byAmountIn:n,depth:3,providers:a},p=await this._sdk.AggregatorClient.findRouters(c);if(p?.error?.code===10001)return{...p,is_exceed:p.insufficientLiquidity};if(p?.insufficientLiquidity)return{...p,is_exceed:p.insufficientLiquidity};if(!p?.paths||p?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:p.amountIn.toString(),amount_out:p.amountOut.toString(),is_exceed:p.insufficientLiquidity,route_obj:p,byAmountIn:!0,originRes:p}}catch{try{if(s){let p=await this._sdk.AggregatorClient.swapInPools({from:t,target:i,amount:new Oo.default(r.toFixed(0).toString()),byAmountIn:n,pools:s});return p?{amount_in:p.routeData.amountIn.toString(),amount_out:p.routeData.amountOut.toString(),is_exceed:p.isExceed,route_obj:p.routeData,byAmountIn:!0,originRes:p}:null}return null}catch{return null}}}};var rn=Gs(Bl());import{normalizeSuiAddress as Q1}from"@mysten/sui/utils";import{SuiClient as eg}from"@mysten/sui/client";import{SdkWrapper as Ap}from"@cetusprotocol/common-sdk";import{normalizeSuiObjectId as ds}from"@mysten/sui/utils";import{CACHE_TIME_24H as fi,CACHE_TIME_5MIN as Sp,CachedContent as Cp,DETAILS_KEYS as Xr,extractStructTagFromType as hs,fixCoinType as Ep,getFutureTime as Ul,getObjectFields as Hn,getObjectId as fs,getObjectPreviousTransactionDigest as Ip,getObjectType as kp,getPackagerConfigs as zi,normalizeCoinType as jl}from"@cetusprotocol/common-sdk";import{BaseError as Up}from"@cetusprotocol/common-sdk";import{SuiClient as Jp}from"@mysten/sui/client";import{Transaction as Jr}from"@mysten/sui/transactions";import{normalizeSuiAddress as yr}from"@mysten/sui/utils";import{asUintN as Zl,FEE_RATE_DENOMINATOR as Vn,getDeltaDownFromOutput as Kl,getDeltaUpFromInput as Wl,getNextSqrtPriceFromInput as tm,getNextSqrtPriceFromOutput as im,MathUtil as lr,ZERO as pi}from"@cetusprotocol/common-sdk";import{Transaction as ms}from"@mysten/sui/transactions";import{adjustForSlippage as nm,CLOCK_ADDRESS as Zn,CoinAssist as Ut,getPackagerConfigs as zl,MathUtil as U_,MAX_SQRT_PRICE as om,MIN_SQRT_PRICE as sm,U64_MAX as am,ZERO as lm}from"@cetusprotocol/common-sdk";import{Transaction as gs}from"@mysten/sui/transactions";import{asUintN as Xl,ClmmPoolUtil as fm,CLOCK_ADDRESS as Jl,CoinAssist as jt,getPackagerConfigs as pm,normalizeCoinType as _s}from"@cetusprotocol/common-sdk";import{asIntN as cr,buildNFT as h1,d as Yr,DETAILS_KEYS as ho,extractStructTagFromType as Dr,getMoveObjectType as Vu,getObjectDeletedResponse as f1,getObjectFields as $s,getObjectId as Fs,getObjectNotExistsResponse as p1,getObjectOwner as m1,MathUtil as g1}from"@cetusprotocol/common-sdk";import{asUintN as Mr,CACHE_TIME_24H as Wn,ClmmPoolUtil as M1,CLOCK_ADDRESS as tu,CoinAssist as zn,createFullClient as A1,d as Ar,DETAILS_KEYS as rt,extractStructTagFromType as Sr,getObjectFields as S1,getObjectPreviousTransactionDigest as C1,getPackagerConfigs as ys,isSortedSymbols as iu,TickMath as Ms,tickScore as E1,TickUtil as ru}from"@cetusprotocol/common-sdk";import{asIntN as nu,d as ou,extractStructTagFromType as I1,fixCoinType as su,getObjectFields as As,getObjectType as k1}from"@cetusprotocol/common-sdk";import{SuiClient as P1}from"@mysten/sui/client";import{Transaction as Pi}from"@mysten/sui/transactions";import{isValidSuiObjectId as x1,normalizeSuiAddress as N1}from"@mysten/sui/utils";import{asUintN as Cr,ClmmPoolUtil as au,CLOCK_ADDRESS as Jn,CoinAssist as Yn,d as Mi,DETAILS_KEYS as Xi,extractStructTagFromType as R1,getObjectFields as lu,getPackagerConfigs as xi,TickMath as Er,TickUtil as Qn,createFullClient as L1,deriveDynamicFieldIdByType as F1}from"@cetusprotocol/common-sdk";import{Transaction as Ss}from"@mysten/sui/transactions";import{normalizeSuiAddress as B1}from"@mysten/sui/utils";import{CLOCK_ADDRESS as Cs,CoinAssist as Es,DETAILS_KEYS as cu,getPackagerConfigs as Is,MathUtil as U1,normalizeCoinType as ks,ZERO as Ir}from"@cetusprotocol/common-sdk";import{Transaction as du}from"@mysten/sui/transactions";import{normalizeSuiAddress as hu}from"@mysten/sui/utils";import{d as Tr,DETAILS_KEYS as Ji,extractStructTagFromType as fu,TickMath as pu,U64_MAX as q1,ZERO as $1}from"@cetusprotocol/common-sdk";import{CLOCK_ADDRESS as G1,CoinAssist as V1,DETAILS_KEYS as ar,getPackagerConfigs as Ts}from"@cetusprotocol/common-sdk";import{Transaction as mu}from"@mysten/sui/transactions";import{normalizeSuiAddress as Z1}from"@mysten/sui/utils";import{FullRpcUrlMainnet as W1}from"@cetusprotocol/common-sdk";import{FullRpcUrlTestnet as X1}from"@cetusprotocol/common-sdk";import{MathUtil as av,TickMath as lv}from"@cetusprotocol/common-sdk";var mp=Object.create,_u=Object.defineProperty,gp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyNames,vp=Object.getPrototypeOf,wp=Object.prototype.hasOwnProperty,bp=(e=>typeof vt<"u"?vt:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof vt<"u"?vt:t)[i]}):e)(function(e){if(typeof vt<"u")return vt.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),yp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mp=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _p(t))!wp.call(e,n)&&n!==i&&_u(e,n,{get:()=>t[n],enumerable:!(r=gp(t,n))||r.enumerable});return e},Li=(e,t,i)=>(i=e!=null?mp(vp(e)):{},Mp(t||!e||!e.__esModule?_u(i,"default",{value:e,enumerable:!0}):i,e)),Fi=yp((e,t)=>{"use strict";(function(i,r){"use strict";function n(o,l){if(!o)throw new Error(l||"Assertion failed")}function s(o,l){o.super_=l;var d=function(){};d.prototype=l.prototype,o.prototype=new d,o.prototype.constructor=o}function a(o,l,d){if(a.isBN(o))return o;this.negative=0,this.words=null,this.length=0,this.red=null,o!==null&&((l==="le"||l==="be")&&(d=l,l=10),this._init(o||0,l||10,d||"be"))}typeof i=="object"?i.exports=a:r.BN=a,a.BN=a,a.wordSize=26;var c;try{typeof window<"u"&&typeof window.Buffer<"u"?c=window.Buffer:c=bp("buffer").Buffer}catch{}a.isBN=function(o){return o instanceof a?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===a.wordSize&&Array.isArray(o.words)},a.max=function(o,l){return o.cmp(l)>0?o:l},a.min=function(o,l){return o.cmp(l)<0?o:l},a.prototype._init=function(o,l,d){if(typeof o=="number")return this._initNumber(o,l,d);if(typeof o=="object")return this._initArray(o,l,d);l==="hex"&&(l=16),n(l===(l|0)&&l>=2&&l<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(l===16?this._parseHex(o,m,d):(this._parseBase(o,l,m),d==="le"&&this._initArray(this.toArray(),l,d)))},a.prototype._initNumber=function(o,l,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(n(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),l,d)},a.prototype._initArray=function(o,l,d){if(n(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _,b,w=0;if(d==="be")for(m=o.length-1,_=0;m>=0;m-=3)b=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);else if(d==="le")for(m=0,_=0;m<o.length;m+=3)b=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);return this._strip()};function p(o,l){var d=o.charCodeAt(l);if(d>=48&&d<=57)return d-48;if(d>=65&&d<=70)return d-55;if(d>=97&&d<=102)return d-87;n(!1,"Invalid character in "+o)}function g(o,l,d){var m=p(o,d);return d-1>=l&&(m|=p(o,d-1)<<4),m}a.prototype._parseHex=function(o,l,d){this.length=Math.ceil((o.length-l)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _=0,b=0,w;if(d==="be")for(m=o.length-1;m>=l;m-=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8;else{var f=o.length-l;for(m=f%2===0?l+1:l;m<o.length;m+=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8}this._strip()};function v(o,l,d,m){for(var _=0,b=0,w=Math.min(o.length,d),f=l;f<w;f++){var u=o.charCodeAt(f)-48;_*=m,u>=49?b=u-49+10:u>=17?b=u-17+10:b=u,n(u>=0&&b<m,"Invalid character"),_+=b}return _}a.prototype._parseBase=function(o,l,d){this.words=[0],this.length=1;for(var m=0,_=1;_<=67108863;_*=l)m++;m--,_=_/l|0;for(var b=o.length-d,w=b%m,f=Math.min(b,b-w)+d,u=0,M=d;M<f;M+=m)u=v(o,M,M+m,l),this.imuln(_),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(w!==0){var q=1;for(u=v(o,M,o.length,l),M=0;M<w;M++)q*=l;this.imuln(q),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},a.prototype.copy=function(o){o.words=new Array(this.length);for(var l=0;l<this.length;l++)o.words[l]=this.words[l];o.length=this.length,o.negative=this.negative,o.red=this.red};function y(o,l){o.words=l.words,o.length=l.length,o.negative=l.negative,o.red=l.red}if(a.prototype._move=function(o){y(o,this)},a.prototype.clone=function(){var o=new a(null);return this.copy(o),o},a.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{a.prototype.inspect=A}else a.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var k=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],U=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(o,l){o=o||10,l=l|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,_=0,b=0;b<this.length;b++){var w=this.words[b],f=((w<<m|_)&16777215).toString(16);_=w>>>24-m&16777215,m+=2,m>=26&&(m-=26,b--),_!==0||b!==this.length-1?d=k[6-f.length]+f+d:d=f+d}for(_!==0&&(d=_.toString(16)+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var u=U[o],M=P[o];d="";var q=this.clone();for(q.negative=0;!q.isZero();){var $=q.modrn(M).toString(o);q=q.idivn(M),q.isZero()?d=$+d:d=k[u-$.length]+$+d}for(this.isZero()&&(d="0"+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},a.prototype.toJSON=function(){return this.toString(16,2)},c&&(a.prototype.toBuffer=function(o,l){return this.toArrayLike(c,o,l)}),a.prototype.toArray=function(o,l){return this.toArrayLike(Array,o,l)};var W=function(o,l){return o.allocUnsafe?o.allocUnsafe(l):new o(l)};a.prototype.toArrayLike=function(o,l,d){this._strip();var m=this.byteLength(),_=d||Math.max(1,m);n(m<=_,"byte array longer than desired length"),n(_>0,"Requested array length <= 0");var b=W(o,_),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](b,m),b},a.prototype._toArrayLikeLE=function(o,l){for(var d=0,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d++]=w&255,d<o.length&&(o[d++]=w>>8&255),d<o.length&&(o[d++]=w>>16&255),b===6?(d<o.length&&(o[d++]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},a.prototype._toArrayLikeBE=function(o,l){for(var d=o.length-1,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d--]=w&255,d>=0&&(o[d--]=w>>8&255),d>=0&&(o[d--]=w>>16&255),b===6?(d>=0&&(o[d--]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?a.prototype._countBits=function(o){return 32-Math.clz32(o)}:a.prototype._countBits=function(o){var l=o,d=0;return l>=4096&&(d+=13,l>>>=13),l>=64&&(d+=7,l>>>=7),l>=8&&(d+=4,l>>>=4),l>=2&&(d+=2,l>>>=2),d+l},a.prototype._zeroBits=function(o){if(o===0)return 26;var l=o,d=0;return(l&8191)===0&&(d+=13,l>>>=13),(l&127)===0&&(d+=7,l>>>=7),(l&15)===0&&(d+=4,l>>>=4),(l&3)===0&&(d+=2,l>>>=2),(l&1)===0&&d++,d},a.prototype.bitLength=function(){var o=this.words[this.length-1],l=this._countBits(o);return(this.length-1)*26+l};function j(o){for(var l=new Array(o.bitLength()),d=0;d<l.length;d++){var m=d/26|0,_=d%26;l[d]=o.words[m]>>>_&1}return l}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,l=0;l<this.length;l++){var d=this._zeroBits(this.words[l]);if(o+=d,d!==26)break}return o},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},a.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]|o.words[l];return this._strip()},a.prototype.ior=function(o){return n((this.negative|o.negative)===0),this.iuor(o)},a.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},a.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},a.prototype.iuand=function(o){var l;this.length>o.length?l=o:l=this;for(var d=0;d<l.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=l.length,this._strip()},a.prototype.iand=function(o){return n((this.negative|o.negative)===0),this.iuand(o)},a.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},a.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},a.prototype.iuxor=function(o){var l,d;this.length>o.length?(l=this,d=o):(l=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=l.words[m]^d.words[m];if(this!==l)for(;m<l.length;m++)this.words[m]=l.words[m];return this.length=l.length,this._strip()},a.prototype.ixor=function(o){return n((this.negative|o.negative)===0),this.iuxor(o)},a.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},a.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},a.prototype.inotn=function(o){n(typeof o=="number"&&o>=0);var l=Math.ceil(o/26)|0,d=o%26;this._expand(l),d>0&&l--;for(var m=0;m<l;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},a.prototype.notn=function(o){return this.clone().inotn(o)},a.prototype.setn=function(o,l){n(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),l?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},a.prototype.iadd=function(o){var l;if(this.negative!==0&&o.negative===0)return this.negative=0,l=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,l=this.isub(o),o.negative=1,l._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var _=0,b=0;b<m.length;b++)l=(d.words[b]|0)+(m.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;for(;_!==0&&b<d.length;b++)l=(d.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;if(this.length=d.length,_!==0)this.words[this.length]=_,this.length++;else if(d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this},a.prototype.add=function(o){var l;return o.negative!==0&&this.negative===0?(o.negative=0,l=this.sub(o),o.negative^=1,l):o.negative===0&&this.negative!==0?(this.negative=0,l=o.sub(this),this.negative=1,l):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},a.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var l=this.iadd(o);return o.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,_;d>0?(m=this,_=o):(m=o,_=this);for(var b=0,w=0;w<_.length;w++)l=(m.words[w]|0)-(_.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;for(;b!==0&&w<m.length;w++)l=(m.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;if(b===0&&w<m.length&&m!==this)for(;w<m.length;w++)this.words[w]=m.words[w];return this.length=Math.max(this.length,w),m!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(o){return this.clone().isub(o)};function K(o,l,d){d.negative=l.negative^o.negative;var m=o.length+l.length|0;d.length=m,m=m-1|0;var _=o.words[0]|0,b=l.words[0]|0,w=_*b,f=w&67108863,u=w/67108864|0;d.words[0]=f;for(var M=1;M<m;M++){for(var q=u>>>26,$=u&67108863,z=Math.min(M,l.length-1),ie=Math.max(0,M-o.length+1);ie<=z;ie++){var C=M-ie|0;_=o.words[C]|0,b=l.words[ie]|0,w=_*b+$,q+=w/67108864|0,$=w&67108863}d.words[M]=$|0,u=q|0}return u!==0?d.words[M]=u|0:d.length--,d._strip()}var X=function(o,l,d){var m=o.words,_=l.words,b=d.words,w=0,f,u,M,q=m[0]|0,$=q&8191,z=q>>>13,ie=m[1]|0,C=ie&8191,T=ie>>>13,x=m[2]|0,F=x&8191,L=x>>>13,G=m[3]|0,B=G&8191,D=G>>>13,Z=m[4]|0,H=Z&8191,V=Z>>>13,ee=m[5]|0,te=ee&8191,le=ee>>>13,Ee=m[6]|0,ce=Ee&8191,pe=Ee>>>13,Ce=m[7]|0,ue=Ce&8191,Se=Ce>>>13,et=m[8]|0,fe=et&8191,Re=et>>>13,Ye=m[9]|0,he=Ye&8191,Ie=Ye>>>13,ze=_[0]|0,de=ze&8191,Ue=ze>>>13,ot=_[1]|0,me=ot&8191,je=ot>>>13,st=_[2]|0,ge=st&8191,qe=st>>>13,at=_[3]|0,_e=at&8191,$e=at>>>13,lt=_[4]|0,ve=lt&8191,He=lt>>>13,ut=_[5]|0,we=ut&8191,Ge=ut>>>13,ct=_[6]|0,be=ct&8191,Ve=ct>>>13,dt=_[7]|0,ye=dt&8191,Ze=dt>>>13,ht=_[8]|0,Me=ht&8191,Ke=ht>>>13,ft=_[9]|0,Ae=ft&8191,Be=ft>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,de),u=Math.imul($,Ue),u=u+Math.imul(z,de)|0,M=Math.imul(z,Ue);var Gt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,f=Math.imul(C,de),u=Math.imul(C,Ue),u=u+Math.imul(T,de)|0,M=Math.imul(T,Ue),f=f+Math.imul($,me)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(z,me)|0,M=M+Math.imul(z,je)|0;var Vt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,f=Math.imul(F,de),u=Math.imul(F,Ue),u=u+Math.imul(L,de)|0,M=Math.imul(L,Ue),f=f+Math.imul(C,me)|0,u=u+Math.imul(C,je)|0,u=u+Math.imul(T,me)|0,M=M+Math.imul(T,je)|0,f=f+Math.imul($,ge)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(z,ge)|0,M=M+Math.imul(z,qe)|0;var Zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,f=Math.imul(B,de),u=Math.imul(B,Ue),u=u+Math.imul(D,de)|0,M=Math.imul(D,Ue),f=f+Math.imul(F,me)|0,u=u+Math.imul(F,je)|0,u=u+Math.imul(L,me)|0,M=M+Math.imul(L,je)|0,f=f+Math.imul(C,ge)|0,u=u+Math.imul(C,qe)|0,u=u+Math.imul(T,ge)|0,M=M+Math.imul(T,qe)|0,f=f+Math.imul($,_e)|0,u=u+Math.imul($,$e)|0,u=u+Math.imul(z,_e)|0,M=M+Math.imul(z,$e)|0;var Kt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,f=Math.imul(H,de),u=Math.imul(H,Ue),u=u+Math.imul(V,de)|0,M=Math.imul(V,Ue),f=f+Math.imul(B,me)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(D,me)|0,M=M+Math.imul(D,je)|0,f=f+Math.imul(F,ge)|0,u=u+Math.imul(F,qe)|0,u=u+Math.imul(L,ge)|0,M=M+Math.imul(L,qe)|0,f=f+Math.imul(C,_e)|0,u=u+Math.imul(C,$e)|0,u=u+Math.imul(T,_e)|0,M=M+Math.imul(T,$e)|0,f=f+Math.imul($,ve)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,He)|0;var Wt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,f=Math.imul(te,de),u=Math.imul(te,Ue),u=u+Math.imul(le,de)|0,M=Math.imul(le,Ue),f=f+Math.imul(H,me)|0,u=u+Math.imul(H,je)|0,u=u+Math.imul(V,me)|0,M=M+Math.imul(V,je)|0,f=f+Math.imul(B,ge)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(D,ge)|0,M=M+Math.imul(D,qe)|0,f=f+Math.imul(F,_e)|0,u=u+Math.imul(F,$e)|0,u=u+Math.imul(L,_e)|0,M=M+Math.imul(L,$e)|0,f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,He)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ge)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ge)|0;var zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(zt>>>26)|0,zt&=67108863,f=Math.imul(ce,de),u=Math.imul(ce,Ue),u=u+Math.imul(pe,de)|0,M=Math.imul(pe,Ue),f=f+Math.imul(te,me)|0,u=u+Math.imul(te,je)|0,u=u+Math.imul(le,me)|0,M=M+Math.imul(le,je)|0,f=f+Math.imul(H,ge)|0,u=u+Math.imul(H,qe)|0,u=u+Math.imul(V,ge)|0,M=M+Math.imul(V,qe)|0,f=f+Math.imul(B,_e)|0,u=u+Math.imul(B,$e)|0,u=u+Math.imul(D,_e)|0,M=M+Math.imul(D,$e)|0,f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,He)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ge)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ge)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ve)|0;var Xt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,f=Math.imul(ue,de),u=Math.imul(ue,Ue),u=u+Math.imul(Se,de)|0,M=Math.imul(Se,Ue),f=f+Math.imul(ce,me)|0,u=u+Math.imul(ce,je)|0,u=u+Math.imul(pe,me)|0,M=M+Math.imul(pe,je)|0,f=f+Math.imul(te,ge)|0,u=u+Math.imul(te,qe)|0,u=u+Math.imul(le,ge)|0,M=M+Math.imul(le,qe)|0,f=f+Math.imul(H,_e)|0,u=u+Math.imul(H,$e)|0,u=u+Math.imul(V,_e)|0,M=M+Math.imul(V,$e)|0,f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,He)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ge)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ge)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,Ze)|0;var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(fe,de),u=Math.imul(fe,Ue),u=u+Math.imul(Re,de)|0,M=Math.imul(Re,Ue),f=f+Math.imul(ue,me)|0,u=u+Math.imul(ue,je)|0,u=u+Math.imul(Se,me)|0,M=M+Math.imul(Se,je)|0,f=f+Math.imul(ce,ge)|0,u=u+Math.imul(ce,qe)|0,u=u+Math.imul(pe,ge)|0,M=M+Math.imul(pe,qe)|0,f=f+Math.imul(te,_e)|0,u=u+Math.imul(te,$e)|0,u=u+Math.imul(le,_e)|0,M=M+Math.imul(le,$e)|0,f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,He)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ge)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ge)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,Ke)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(he,de),u=Math.imul(he,Ue),u=u+Math.imul(Ie,de)|0,M=Math.imul(Ie,Ue),f=f+Math.imul(fe,me)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(Re,me)|0,M=M+Math.imul(Re,je)|0,f=f+Math.imul(ue,ge)|0,u=u+Math.imul(ue,qe)|0,u=u+Math.imul(Se,ge)|0,M=M+Math.imul(Se,qe)|0,f=f+Math.imul(ce,_e)|0,u=u+Math.imul(ce,$e)|0,u=u+Math.imul(pe,_e)|0,M=M+Math.imul(pe,$e)|0,f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(le,ve)|0,M=M+Math.imul(le,He)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ge)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ge)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Be)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Be)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(he,me),u=Math.imul(he,je),u=u+Math.imul(Ie,me)|0,M=Math.imul(Ie,je),f=f+Math.imul(fe,ge)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(Re,ge)|0,M=M+Math.imul(Re,qe)|0,f=f+Math.imul(ue,_e)|0,u=u+Math.imul(ue,$e)|0,u=u+Math.imul(Se,_e)|0,M=M+Math.imul(Se,$e)|0,f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(pe,ve)|0,M=M+Math.imul(pe,He)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ge)|0,u=u+Math.imul(le,we)|0,M=M+Math.imul(le,Ge)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Be)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Be)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(he,ge),u=Math.imul(he,qe),u=u+Math.imul(Ie,ge)|0,M=Math.imul(Ie,qe),f=f+Math.imul(fe,_e)|0,u=u+Math.imul(fe,$e)|0,u=u+Math.imul(Re,_e)|0,M=M+Math.imul(Re,$e)|0,f=f+Math.imul(ue,ve)|0,u=u+Math.imul(ue,He)|0,u=u+Math.imul(Se,ve)|0,M=M+Math.imul(Se,He)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ge)|0,u=u+Math.imul(pe,we)|0,M=M+Math.imul(pe,Ge)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(le,be)|0,M=M+Math.imul(le,Ve)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Be)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Be)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(he,_e),u=Math.imul(he,$e),u=u+Math.imul(Ie,_e)|0,M=Math.imul(Ie,$e),f=f+Math.imul(fe,ve)|0,u=u+Math.imul(fe,He)|0,u=u+Math.imul(Re,ve)|0,M=M+Math.imul(Re,He)|0,f=f+Math.imul(ue,we)|0,u=u+Math.imul(ue,Ge)|0,u=u+Math.imul(Se,we)|0,M=M+Math.imul(Se,Ge)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(pe,be)|0,M=M+Math.imul(pe,Ve)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(le,ye)|0,M=M+Math.imul(le,Ze)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Be)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Be)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,ve),u=Math.imul(he,He),u=u+Math.imul(Ie,ve)|0,M=Math.imul(Ie,He),f=f+Math.imul(fe,we)|0,u=u+Math.imul(fe,Ge)|0,u=u+Math.imul(Re,we)|0,M=M+Math.imul(Re,Ge)|0,f=f+Math.imul(ue,be)|0,u=u+Math.imul(ue,Ve)|0,u=u+Math.imul(Se,be)|0,M=M+Math.imul(Se,Ve)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(pe,ye)|0,M=M+Math.imul(pe,Ze)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(le,Me)|0,M=M+Math.imul(le,Ke)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Be)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Be)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(he,we),u=Math.imul(he,Ge),u=u+Math.imul(Ie,we)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(fe,be)|0,u=u+Math.imul(fe,Ve)|0,u=u+Math.imul(Re,be)|0,M=M+Math.imul(Re,Ve)|0,f=f+Math.imul(ue,ye)|0,u=u+Math.imul(ue,Ze)|0,u=u+Math.imul(Se,ye)|0,M=M+Math.imul(Se,Ze)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(pe,Me)|0,M=M+Math.imul(pe,Ke)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Be)|0,u=u+Math.imul(le,Ae)|0,M=M+Math.imul(le,Be)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(he,be),u=Math.imul(he,Ve),u=u+Math.imul(Ie,be)|0,M=Math.imul(Ie,Ve),f=f+Math.imul(fe,ye)|0,u=u+Math.imul(fe,Ze)|0,u=u+Math.imul(Re,ye)|0,M=M+Math.imul(Re,Ze)|0,f=f+Math.imul(ue,Me)|0,u=u+Math.imul(ue,Ke)|0,u=u+Math.imul(Se,Me)|0,M=M+Math.imul(Se,Ke)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Be)|0,u=u+Math.imul(pe,Ae)|0,M=M+Math.imul(pe,Be)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(he,ye),u=Math.imul(he,Ze),u=u+Math.imul(Ie,ye)|0,M=Math.imul(Ie,Ze),f=f+Math.imul(fe,Me)|0,u=u+Math.imul(fe,Ke)|0,u=u+Math.imul(Re,Me)|0,M=M+Math.imul(Re,Ke)|0,f=f+Math.imul(ue,Ae)|0,u=u+Math.imul(ue,Be)|0,u=u+Math.imul(Se,Ae)|0,M=M+Math.imul(Se,Be)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(he,Me),u=Math.imul(he,Ke),u=u+Math.imul(Ie,Me)|0,M=Math.imul(Ie,Ke),f=f+Math.imul(fe,Ae)|0,u=u+Math.imul(fe,Be)|0,u=u+Math.imul(Re,Ae)|0,M=M+Math.imul(Re,Be)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(he,Ae),u=Math.imul(he,Be),u=u+Math.imul(Ie,Ae)|0,M=Math.imul(Ie,Be);var rr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(rr>>>26)|0,rr&=67108863,b[0]=Gt,b[1]=Vt,b[2]=Zt,b[3]=Kt,b[4]=Wt,b[5]=zt,b[6]=Xt,b[7]=Jt,b[8]=Yt,b[9]=Qt,b[10]=ei,b[11]=ti,b[12]=ii,b[13]=ri,b[14]=ni,b[15]=oi,b[16]=si,b[17]=ai,b[18]=rr,w!==0&&(b[19]=w,d.length++),d};Math.imul||(X=K);function Q(o,l,d){d.negative=l.negative^o.negative,d.length=o.length+l.length;for(var m=0,_=0,b=0;b<d.length-1;b++){var w=_;_=0;for(var f=m&67108863,u=Math.min(b,l.length-1),M=Math.max(0,b-o.length+1);M<=u;M++){var q=b-M,$=o.words[q]|0,z=l.words[M]|0,ie=$*z,C=ie&67108863;w=w+(ie/67108864|0)|0,C=C+f|0,f=C&67108863,w=w+(C>>>26)|0,_+=w>>>26,w&=67108863}d.words[b]=f,m=w,w=_}return m!==0?d.words[b]=m:d.length--,d._strip()}function se(o,l,d){return Q(o,l,d)}a.prototype.mulTo=function(o,l){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=X(this,o,l):m<63?d=K(this,o,l):m<1024?d=Q(this,o,l):d=se(this,o,l),d};function Y(o,l){this.x=o,this.y=l}Y.prototype.makeRBT=function(o){for(var l=new Array(o),d=a.prototype._countBits(o)-1,m=0;m<o;m++)l[m]=this.revBin(m,d,o);return l},Y.prototype.revBin=function(o,l,d){if(o===0||o===d-1)return o;for(var m=0,_=0;_<l;_++)m|=(o&1)<<l-_-1,o>>=1;return m},Y.prototype.permute=function(o,l,d,m,_,b){for(var w=0;w<b;w++)m[w]=l[o[w]],_[w]=d[o[w]]},Y.prototype.transform=function(o,l,d,m,_,b){this.permute(b,o,l,d,m,_);for(var w=1;w<_;w<<=1)for(var f=w<<1,u=Math.cos(2*Math.PI/f),M=Math.sin(2*Math.PI/f),q=0;q<_;q+=f)for(var $=u,z=M,ie=0;ie<w;ie++){var C=d[q+ie],T=m[q+ie],x=d[q+ie+w],F=m[q+ie+w],L=$*x-z*F;F=$*F+z*x,x=L,d[q+ie]=C+x,m[q+ie]=T+F,d[q+ie+w]=C-x,m[q+ie+w]=T-F,ie!==f&&(L=u*$-M*z,z=u*z+M*$,$=L)}},Y.prototype.guessLen13b=function(o,l){var d=Math.max(l,o)|1,m=d&1,_=0;for(d=d/2|0;d;d=d>>>1)_++;return 1<<_+1+m},Y.prototype.conjugate=function(o,l,d){if(!(d<=1))for(var m=0;m<d/2;m++){var _=o[m];o[m]=o[d-m-1],o[d-m-1]=_,_=l[m],l[m]=-l[d-m-1],l[d-m-1]=-_}},Y.prototype.normalize13b=function(o,l){for(var d=0,m=0;m<l/2;m++){var _=Math.round(o[2*m+1]/l)*8192+Math.round(o[2*m]/l)+d;o[m]=_&67108863,_<67108864?d=0:d=_/67108864|0}return o},Y.prototype.convert13b=function(o,l,d,m){for(var _=0,b=0;b<l;b++)_=_+(o[b]|0),d[2*b]=_&8191,_=_>>>13,d[2*b+1]=_&8191,_=_>>>13;for(b=2*l;b<m;++b)d[b]=0;n(_===0),n((_&-8192)===0)},Y.prototype.stub=function(o){for(var l=new Array(o),d=0;d<o;d++)l[d]=0;return l},Y.prototype.mulp=function(o,l,d){var m=2*this.guessLen13b(o.length,l.length),_=this.makeRBT(m),b=this.stub(m),w=new Array(m),f=new Array(m),u=new Array(m),M=new Array(m),q=new Array(m),$=new Array(m),z=d.words;z.length=m,this.convert13b(o.words,o.length,w,m),this.convert13b(l.words,l.length,M,m),this.transform(w,b,f,u,m,_),this.transform(M,b,q,$,m,_);for(var ie=0;ie<m;ie++){var C=f[ie]*q[ie]-u[ie]*$[ie];u[ie]=f[ie]*$[ie]+u[ie]*q[ie],f[ie]=C}return this.conjugate(f,u,m),this.transform(f,u,z,b,m,_),this.conjugate(z,b,m),this.normalize13b(z,m),d.negative=o.negative^l.negative,d.length=o.length+l.length,d._strip()},a.prototype.mul=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),this.mulTo(o,l)},a.prototype.mulf=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),se(this,o,l)},a.prototype.imul=function(o){return this.clone().mulTo(o,this)},a.prototype.imuln=function(o){var l=o<0;l&&(o=-o),n(typeof o=="number"),n(o<67108864);for(var d=0,m=0;m<this.length;m++){var _=(this.words[m]|0)*o,b=(_&67108863)+(d&67108863);d>>=26,d+=_/67108864|0,d+=b>>>26,this.words[m]=b&67108863}return d!==0&&(this.words[m]=d,this.length++),this.length=o===0?1:this.length,l?this.ineg():this},a.prototype.muln=function(o){return this.clone().imuln(o)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(o){var l=j(o);if(l.length===0)return new a(1);for(var d=this,m=0;m<l.length&&l[m]===0;m++,d=d.sqr());if(++m<l.length)for(var _=d.sqr();m<l.length;m++,_=_.sqr())l[m]!==0&&(d=d.mul(_));return d},a.prototype.iushln=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=67108863>>>26-l<<26-l,_;if(l!==0){var b=0;for(_=0;_<this.length;_++){var w=this.words[_]&m,f=(this.words[_]|0)-w<<l;this.words[_]=f|b,b=w>>>26-l}b&&(this.words[_]=b,this.length++)}if(d!==0){for(_=this.length-1;_>=0;_--)this.words[_+d]=this.words[_];for(_=0;_<d;_++)this.words[_]=0;this.length+=d}return this._strip()},a.prototype.ishln=function(o){return n(this.negative===0),this.iushln(o)},a.prototype.iushrn=function(o,l,d){n(typeof o=="number"&&o>=0);var m;l?m=(l-l%26)/26:m=0;var _=o%26,b=Math.min((o-_)/26,this.length),w=67108863^67108863>>>_<<_,f=d;if(m-=b,m=Math.max(0,m),f){for(var u=0;u<b;u++)f.words[u]=this.words[u];f.length=b}if(b!==0)if(this.length>b)for(this.length-=b,u=0;u<this.length;u++)this.words[u]=this.words[u+b];else this.words[0]=0,this.length=1;var M=0;for(u=this.length-1;u>=0&&(M!==0||u>=m);u--){var q=this.words[u]|0;this.words[u]=M<<26-_|q>>>_,M=q&w}return f&&M!==0&&(f.words[f.length++]=M),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(o,l,d){return n(this.negative===0),this.iushrn(o,l,d)},a.prototype.shln=function(o){return this.clone().ishln(o)},a.prototype.ushln=function(o){return this.clone().iushln(o)},a.prototype.shrn=function(o){return this.clone().ishrn(o)},a.prototype.ushrn=function(o){return this.clone().iushrn(o)},a.prototype.testn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return!1;var _=this.words[d];return!!(_&m)},a.prototype.imaskn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(l!==0&&d++,this.length=Math.min(d,this.length),l!==0){var m=67108863^67108863>>>l<<l;this.words[this.length-1]&=m}return this._strip()},a.prototype.maskn=function(o){return this.clone().imaskn(o)},a.prototype.iaddn=function(o){return n(typeof o=="number"),n(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},a.prototype._iaddn=function(o){this.words[0]+=o;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},a.prototype.isubn=function(o){if(n(typeof o=="number"),n(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},a.prototype.addn=function(o){return this.clone().iaddn(o)},a.prototype.subn=function(o){return this.clone().isubn(o)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(o,l,d){var m=o.length+d,_;this._expand(m);var b,w=0;for(_=0;_<o.length;_++){b=(this.words[_+d]|0)+w;var f=(o.words[_]|0)*l;b-=f&67108863,w=(b>>26)-(f/67108864|0),this.words[_+d]=b&67108863}for(;_<this.length-d;_++)b=(this.words[_+d]|0)+w,w=b>>26,this.words[_+d]=b&67108863;if(w===0)return this._strip();for(n(w===-1),w=0,_=0;_<this.length;_++)b=-(this.words[_]|0)+w,w=b>>26,this.words[_]=b&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(o,l){var d=this.length-o.length,m=this.clone(),_=o,b=_.words[_.length-1]|0,w=this._countBits(b);d=26-w,d!==0&&(_=_.ushln(d),m.iushln(d),b=_.words[_.length-1]|0);var f=m.length-_.length,u;if(l!=="mod"){u=new a(null),u.length=f+1,u.words=new Array(u.length);for(var M=0;M<u.length;M++)u.words[M]=0}var q=m.clone()._ishlnsubmul(_,1,f);q.negative===0&&(m=q,u&&(u.words[f]=1));for(var $=f-1;$>=0;$--){var z=(m.words[_.length+$]|0)*67108864+(m.words[_.length+$-1]|0);for(z=Math.min(z/b|0,67108863),m._ishlnsubmul(_,z,$);m.negative!==0;)z--,m.negative=0,m._ishlnsubmul(_,1,$),m.isZero()||(m.negative^=1);u&&(u.words[$]=z)}return u&&u._strip(),m._strip(),l!=="div"&&d!==0&&m.iushrn(d),{div:u||null,mod:m}},a.prototype.divmod=function(o,l,d){if(n(!o.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var m,_,b;return this.negative!==0&&o.negative===0?(b=this.neg().divmod(o,l),l!=="mod"&&(m=b.div.neg()),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.iadd(o)),{div:m,mod:_}):this.negative===0&&o.negative!==0?(b=this.divmod(o.neg(),l),l!=="mod"&&(m=b.div.neg()),{div:m,mod:b.mod}):(this.negative&o.negative)!==0?(b=this.neg().divmod(o.neg(),l),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.isub(o)),{div:b.div,mod:_}):o.length>this.length||this.cmp(o)<0?{div:new a(0),mod:this}:o.length===1?l==="div"?{div:this.divn(o.words[0]),mod:null}:l==="mod"?{div:null,mod:new a(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new a(this.modrn(o.words[0]))}:this._wordDiv(o,l)},a.prototype.div=function(o){return this.divmod(o,"div",!1).div},a.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},a.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},a.prototype.divRound=function(o){var l=this.divmod(o);if(l.mod.isZero())return l.div;var d=l.div.negative!==0?l.mod.isub(o):l.mod,m=o.ushrn(1),_=o.andln(1),b=d.cmp(m);return b<0||_===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},a.prototype.modrn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=(1<<26)%o,m=0,_=this.length-1;_>=0;_--)m=(d*m+(this.words[_]|0))%o;return l?-m:m},a.prototype.modn=function(o){return this.modrn(o)},a.prototype.idivn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var _=(this.words[m]|0)+d*67108864;this.words[m]=_/o|0,d=_%o}return this._strip(),l?this.ineg():this},a.prototype.divn=function(o){return this.clone().idivn(o)},a.prototype.egcd=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=new a(0),w=new a(1),f=0;l.isEven()&&d.isEven();)l.iushrn(1),d.iushrn(1),++f;for(var u=d.clone(),M=l.clone();!l.isZero();){for(var q=0,$=1;(l.words[0]&$)===0&&q<26;++q,$<<=1);if(q>0)for(l.iushrn(q);q-- >0;)(m.isOdd()||_.isOdd())&&(m.iadd(u),_.isub(M)),m.iushrn(1),_.iushrn(1);for(var z=0,ie=1;(d.words[0]&ie)===0&&z<26;++z,ie<<=1);if(z>0)for(d.iushrn(z);z-- >0;)(b.isOdd()||w.isOdd())&&(b.iadd(u),w.isub(M)),b.iushrn(1),w.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(b),_.isub(w)):(d.isub(l),b.isub(m),w.isub(_))}return{a:b,b:w,gcd:d.iushln(f)}},a.prototype._invmp=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=d.clone();l.cmpn(1)>0&&d.cmpn(1)>0;){for(var w=0,f=1;(l.words[0]&f)===0&&w<26;++w,f<<=1);if(w>0)for(l.iushrn(w);w-- >0;)m.isOdd()&&m.iadd(b),m.iushrn(1);for(var u=0,M=1;(d.words[0]&M)===0&&u<26;++u,M<<=1);if(u>0)for(d.iushrn(u);u-- >0;)_.isOdd()&&_.iadd(b),_.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(_)):(d.isub(l),_.isub(m))}var q;return l.cmpn(1)===0?q=m:q=_,q.cmpn(0)<0&&q.iadd(o),q},a.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var l=this.clone(),d=o.clone();l.negative=0,d.negative=0;for(var m=0;l.isEven()&&d.isEven();m++)l.iushrn(1),d.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;d.isEven();)d.iushrn(1);var _=l.cmp(d);if(_<0){var b=l;l=d,d=b}else if(_===0||d.cmpn(1)===0)break;l.isub(d)}while(!0);return d.iushln(m)},a.prototype.invm=function(o){return this.egcd(o).a.umod(o)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(o){return this.words[0]&o},a.prototype.bincn=function(o){n(typeof o=="number");var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var _=m,b=d;_!==0&&b<this.length;b++){var w=this.words[b]|0;w+=_,_=w>>>26,w&=67108863,this.words[b]=w}return _!==0&&(this.words[b]=_,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(o){var l=o<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var d;if(this.length>1)d=1;else{l&&(o=-o),n(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},a.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var l=this.ucmp(o);return this.negative!==0?-l|0:l},a.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var l=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,_=o.words[d]|0;if(m!==_){m<_?l=-1:m>_&&(l=1);break}}return l},a.prototype.gtn=function(o){return this.cmpn(o)===1},a.prototype.gt=function(o){return this.cmp(o)===1},a.prototype.gten=function(o){return this.cmpn(o)>=0},a.prototype.gte=function(o){return this.cmp(o)>=0},a.prototype.ltn=function(o){return this.cmpn(o)===-1},a.prototype.lt=function(o){return this.cmp(o)===-1},a.prototype.lten=function(o){return this.cmpn(o)<=0},a.prototype.lte=function(o){return this.cmp(o)<=0},a.prototype.eqn=function(o){return this.cmpn(o)===0},a.prototype.eq=function(o){return this.cmp(o)===0},a.red=function(o){return new S(o)},a.prototype.toRed=function(o){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},a.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(o){return this.red=o,this},a.prototype.forceRed=function(o){return n(!this.red,"Already a number in reduction context"),this._forceRed(o)},a.prototype.redAdd=function(o){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},a.prototype.redIAdd=function(o){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},a.prototype.redSub=function(o){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},a.prototype.redISub=function(o){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},a.prototype.redShl=function(o){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},a.prototype.redMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},a.prototype.redIMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},a.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(o){return n(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var ae={k256:null,p224:null,p192:null,p25519:null};function E(o,l){this.name=o,this.p=new a(l,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}E.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},E.prototype.ireduce=function(o){var l=o,d;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),d=l.bitLength();while(d>this.n);var m=d<this.n?-1:l.ucmp(this.p);return m===0?(l.words[0]=0,l.length=1):m>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},E.prototype.split=function(o,l){o.iushrn(this.n,0,l)},E.prototype.imulK=function(o){return o.imul(this.k)};function I(){E.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(I,E),I.prototype.split=function(o,l){for(var d=4194303,m=Math.min(o.length,9),_=0;_<m;_++)l.words[_]=o.words[_];if(l.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var b=o.words[9];for(l.words[l.length++]=b&d,_=10;_<o.length;_++){var w=o.words[_]|0;o.words[_-10]=(w&d)<<4|b>>>22,b=w}b>>>=22,o.words[_-10]=b,b===0&&o.length>10?o.length-=10:o.length-=9},I.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var l=0,d=0;d<o.length;d++){var m=o.words[d]|0;l+=m*977,o.words[d]=l&67108863,l=m*64+(l/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function O(){E.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(O,E);function R(){E.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(R,E);function N(){E.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(N,E),N.prototype.imulK=function(o){for(var l=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+l,_=m&67108863;m>>>=26,o.words[d]=_,l=m}return l!==0&&(o.words[o.length++]=l),o},a._prime=function(o){if(ae[o])return ae[o];var l;if(o==="k256")l=new I;else if(o==="p224")l=new O;else if(o==="p192")l=new R;else if(o==="p25519")l=new N;else throw new Error("Unknown prime "+o);return ae[o]=l,l};function S(o){if(typeof o=="string"){var l=a._prime(o);this.m=l.p,this.prime=l}else n(o.gtn(1),"modulus must be greater than 1"),this.m=o,this.prime=null}S.prototype._verify1=function(o){n(o.negative===0,"red works only with positives"),n(o.red,"red works only with red numbers")},S.prototype._verify2=function(o,l){n((o.negative|l.negative)===0,"red works only with positives"),n(o.red&&o.red===l.red,"red works only with red numbers")},S.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(y(o,o.umod(this.m)._forceRed(this)),o)},S.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},S.prototype.add=function(o,l){this._verify2(o,l);var d=o.add(l);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},S.prototype.iadd=function(o,l){this._verify2(o,l);var d=o.iadd(l);return d.cmp(this.m)>=0&&d.isub(this.m),d},S.prototype.sub=function(o,l){this._verify2(o,l);var d=o.sub(l);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},S.prototype.isub=function(o,l){this._verify2(o,l);var d=o.isub(l);return d.cmpn(0)<0&&d.iadd(this.m),d},S.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},S.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},S.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},S.prototype.isqr=function(o){return this.imul(o,o.clone())},S.prototype.sqr=function(o){return this.mul(o,o)},S.prototype.sqrt=function(o){if(o.isZero())return o.clone();var l=this.m.andln(3);if(n(l%2===1),l===3){var d=this.m.add(new a(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),_=0;!m.isZero()&&m.andln(1)===0;)_++,m.iushrn(1);n(!m.isZero());var b=new a(1).toRed(this),w=b.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new a(2*u*u).toRed(this);this.pow(u,f).cmp(w)!==0;)u.redIAdd(w);for(var M=this.pow(u,m),q=this.pow(o,m.addn(1).iushrn(1)),$=this.pow(o,m),z=_;$.cmp(b)!==0;){for(var ie=$,C=0;ie.cmp(b)!==0;C++)ie=ie.redSqr();n(C<z);var T=this.pow(M,new a(1).iushln(z-C-1));q=q.redMul(T),M=T.redSqr(),$=$.redMul(M),z=C}return q},S.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},S.prototype.pow=function(o,l){if(l.isZero())return new a(1).toRed(this);if(l.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new a(1).toRed(this),m[1]=o;for(var _=2;_<m.length;_++)m[_]=this.mul(m[_-1],o);var b=m[0],w=0,f=0,u=l.bitLength()%26;for(u===0&&(u=26),_=l.length-1;_>=0;_--){for(var M=l.words[_],q=u-1;q>=0;q--){var $=M>>q&1;if(b!==m[0]&&(b=this.sqr(b)),$===0&&w===0){f=0;continue}w<<=1,w|=$,f++,!(f!==d&&(_!==0||q!==0))&&(b=this.mul(b,m[w]),f=0,w=0)}u=26}return b},S.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},S.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},a.mont=function(o){return new h(o)};function h(o){S.call(this,o),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(h,S),h.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},h.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},h.prototype.imul=function(o,l){if(o.isZero()||l.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},h.prototype.mul=function(o,l){if(o.isZero()||l.isZero())return new a(0)._forceRed(this);var d=o.mul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},h.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,e)}),vu="3.7.8",Tp=vu,Br=typeof Buffer=="function",ql=typeof TextDecoder=="function"?new TextDecoder:void 0,$l=typeof TextEncoder=="function"?new TextEncoder:void 0,Op="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Qr=Array.prototype.slice.call(Op),Gn=(e=>{let t={};return e.forEach((i,r)=>t[i]=r),t})(Qr),Pp=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Tt=String.fromCharCode.bind(String),Hl=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),wu=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),bu=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),yu=e=>{let t,i,r,n,s="",a=e.length%3;for(let c=0;c<e.length;){if((i=e.charCodeAt(c++))>255||(r=e.charCodeAt(c++))>255||(n=e.charCodeAt(c++))>255)throw new TypeError("invalid character found");t=i<<16|r<<8|n,s+=Qr[t>>18&63]+Qr[t>>12&63]+Qr[t>>6&63]+Qr[t&63]}return a?s.slice(0,a-3)+"===".substring(a):s},Us=typeof btoa=="function"?e=>btoa(e):Br?e=>Buffer.from(e,"binary").toString("base64"):yu,Os=Br?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let i=0,r=e.length;i<r;i+=4096)t.push(Tt.apply(null,e.subarray(i,i+4096)));return Us(t.join(""))},eo=(e,t=!1)=>t?wu(Os(e)):Os(e),xp=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?Tt(192|t>>>6)+Tt(128|t&63):Tt(224|t>>>12&15)+Tt(128|t>>>6&63)+Tt(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return Tt(240|t>>>18&7)+Tt(128|t>>>12&63)+Tt(128|t>>>6&63)+Tt(128|t&63)}},Np=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Mu=e=>e.replace(Np,xp),Gl=Br?e=>Buffer.from(e,"utf8").toString("base64"):$l?e=>Os($l.encode(e)):e=>Us(Mu(e)),xr=(e,t=!1)=>t?wu(Gl(e)):Gl(e),Vl=e=>xr(e,!0),Rp=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Lp=e=>{switch(e.length){case 4:var t=(7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3),i=t-65536;return Tt((i>>>10)+55296)+Tt((i&1023)+56320);case 3:return Tt((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return Tt((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Au=e=>e.replace(Rp,Lp),Su=e=>{if(e=e.replace(/\s+/g,""),!Pp.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(e.length&3));let t,i,r,n=[];for(let s=0;s<e.length;)t=Gn[e.charAt(s++)]<<18|Gn[e.charAt(s++)]<<12|(i=Gn[e.charAt(s++)])<<6|(r=Gn[e.charAt(s++)]),i===64?n.push(Tt(t>>16&255)):r===64?n.push(Tt(t>>16&255,t>>8&255)):n.push(Tt(t>>16&255,t>>8&255,t&255));return n.join("")},js=typeof atob=="function"?e=>atob(bu(e)):Br?e=>Buffer.from(e,"base64").toString("binary"):Su,Cu=Br?e=>Hl(Buffer.from(e,"base64")):e=>Hl(js(e).split("").map(t=>t.charCodeAt(0))),Eu=e=>Cu(Iu(e)),Fp=Br?e=>Buffer.from(e,"base64").toString("utf8"):ql?e=>ql.decode(Cu(e)):e=>Au(js(e)),Iu=e=>bu(e.replace(/[-_]/g,t=>t=="-"?"+":"/")),Ps=e=>Fp(Iu(e)),Dp=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)},ku=e=>({value:e,enumerable:!1,writable:!0,configurable:!0}),Tu=function(){let e=(t,i)=>Object.defineProperty(String.prototype,t,ku(i));e("fromBase64",function(){return Ps(this)}),e("toBase64",function(t){return xr(this,t)}),e("toBase64URI",function(){return xr(this,!0)}),e("toBase64URL",function(){return xr(this,!0)}),e("toUint8Array",function(){return Eu(this)})},Ou=function(){let e=(t,i)=>Object.defineProperty(Uint8Array.prototype,t,ku(i));e("toBase64",function(t){return eo(this,t)}),e("toBase64URI",function(){return eo(this,!0)}),e("toBase64URL",function(){return eo(this,!0)})},Bp=()=>{Tu(),Ou()},ps={version:vu,VERSION:Tp,atob:js,atobPolyfill:Su,btoa:Us,btoaPolyfill:yu,fromBase64:Ps,toBase64:xr,encode:xr,encodeURI:Vl,encodeURL:Vl,utob:Mu,btou:Au,decode:Ps,isValid:Dp,fromUint8Array:eo,toUint8Array:Eu,extendString:Tu,extendUint8Array:Ou,extendBuiltins:Bp},jp=(e=>(e.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",e.ZeroTradableAmount="ZeroTradableAmount",e.AmountOutBelowMinimum="AmountOutBelowMinimum",e.AmountInAboveMaximum="AmountInAboveMaximum",e.NextTickNotFound="NextTickNotFound",e.TickArraySequenceInvalid="TickArraySequenceInvalid",e.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",e.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",e.ParamsLengthNotEqual="ParamsLengthNotEqual",e))(jp||{}),qp=(e=>(e.InvalidTickEvent="InvalidTickEvent",e.InvalidPositionObject="InvalidPositionObject",e.InvalidPositionRewardObject="InvalidPositionRewardObject",e.InvalidParams="InvalidParams",e.FetchError="FetchError",e))(qp||{}),$p=(e=>(e.InvalidCoinTypeSequence="InvalidCoinTypeSequence",e.InvalidTickIndex="InvalidTickIndex",e.InvalidPoolObject="InvalidPoolObject",e.InvalidTickObjectId="InvalidTickObjectId",e.InvalidTickObject="InvalidTickObject",e.InvalidTickFields="InvalidTickFields",e.PoolsNotFound="PoolsNotFound",e.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",e.FetchError="FetchError",e))($p||{}),Hp=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(Hp||{}),Gp=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(Gp||{}),Vp=(e=>(e.InvalidConfig="InvalidConfig",e.InvalidConfigHandle="InvalidConfigHandle",e.InvalidSimulateAccount="InvalidSimulateAccount",e))(Vp||{}),Zp=(e=>(e.InvalidSendAddress="InvalidSendAddress",e.InvalidRecipientAddress="InvalidRecipientAddress",e.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",e.InsufficientBalance="InsufficientBalance",e.InvalidTarget="InvalidTarget",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e))(Zp||{}),Kp=(e=>(e.InvalidCoin="InvalidCoin",e.NotFoundPath="NotFoundPath",e.NoDowngradeNeedParams="NoDowngradeNeedParams",e.InvalidSwapCountUrl="InvalidSwapCountUrl",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e.InvalidServerResponse="InvalidServerResponse",e))(Kp||{}),Wp=(e=>(e.InvalidType="InvalidType",e))(Wp||{}),Pu=class extends Up{constructor(e,t,i){super(e,t||"UnknownError",i)}static isVaultsErrorCode(e,t){return this.isErrorCode(e,t)}},Ri=(e,t,i)=>{throw new Pu(t.message,e,i)},Je=(e,t,i)=>{throw new Pu(t,e,i)},zp=class{constructor(e){this._cache={},this._sdk=e}get sdk(){return this._sdk}setTokenListCache(e){let{coin_list_handle:t}=zi(this.sdk.sdkOptions.cetus_config),i=`${t}_getCoinConfigs`,r=this.getCache(i),n=r?[...r,...e]:e;this.updateCache(i,n)}async getTokenListByCoinTypes(e){let t={},{coin_list_handle:i}=zi(this.sdk.sdkOptions.cetus_config),r=`${i}_getCoinConfigs`,n=this.getCache(r);if(n!==void 0){let a=n;for(let c of e)for(let p of a)if(jl(c)===jl(p.address)){t[c]=p;continue}}let s=e.filter(a=>t[a]===void 0);for(let a of s){let c=`${a}_metadata`,p=this.getCache(c);if(p!==void 0)t[a]=p;else{let g=await this._sdk.FullClient.getCoinMetadata({coinType:a});if(g){let v={id:g.id,pyth_id:"",name:g.name,symbol:g.symbol,official_symbol:g.symbol,coingecko_id:"",decimals:g.decimals,project_url:"",logo_url:g.iconUrl,address:a};t[a]=v,this.updateCache(c,v,fi)}else console.log(`not found ${a}`)}}return t}async getCoinConfigs(e=!1,t=!0){let{coin_list_handle:i}=zi(this.sdk.sdkOptions.cetus_config),r=`${i}_getCoinConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&Je("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCoinConfigs"});let g=this.buildCoinConfig(p,t);this.updateCache(`${i}_${g.address}_getCoinConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getCoinConfig(e,t=!1,i=!0){let{coin_list_handle:r}=zi(this.sdk.sdkOptions.cetus_config),n=`${r}_${e}_getCoinConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"0x1::type_name::TypeName",value:{name:Ep(e)}}});(a.error!=null||a.data?.content?.dataType!=="moveObject")&&Je("FetchError",`when getCoinConfig get object error: ${a.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCoinConfig"});let c=this.buildCoinConfig(a,i);return this.updateCache(n,c,fi),c}buildCoinConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};return r.id=fs(e),r.address=hs(i.coin_type.fields.name).full_address,i.pyth_id&&(r.pyth_id=ds(i.pyth_id)),this.transformExtensions(r,i.extension_fields.fields.contents,t),delete r.coin_type,r}async getClmmPoolConfigs(e=!1,t=!0){let{clmm_pools_handle:i}=zi(this.sdk.sdkOptions.cetus_config),r=`${i}_getClmmPoolConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&Je("FetchError",`when getClmmPoolsConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getClmmPoolConfigs"});let g=this.buildClmmPoolConfig(p,t);this.updateCache(`${g.pool_address}_getClmmPoolConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getClmmPoolConfig(e,t=!1,i=!0){let{clmm_pools_handle:r}=zi(this.sdk.sdkOptions.cetus_config),n=`${e}_getClmmPoolConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"address",value:e}}),c=this.buildClmmPoolConfig(a,i);return this.updateCache(n,c,fi),c}buildClmmPoolConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};return r.id=fs(e),r.pool_address=ds(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t),r}async getLaunchpadPoolConfigs(e=!1,t=!0){let{launchpad_pools_handle:i}=zi(this.sdk.sdkOptions.cetus_config),r=`${i}_getLaunchpadPoolConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&Je("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getLaunchpadPoolConfigs"});let g=this.buildLaunchpadPoolConfig(p,t);this.updateCache(`${g.pool_address}_getLaunchpadPoolConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getLaunchpadPoolConfig(e,t=!1,i=!0){let{launchpad_pools_handle:r}=zi(this.sdk.sdkOptions.cetus_config),n=`${e}_getLaunchpadPoolConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"address",value:e}}),c=this.buildLaunchpadPoolConfig(a,i);return this.updateCache(n,c,fi),c}buildLaunchpadPoolConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};r.id=fs(e),r.pool_address=ds(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t);let n=[];i.social_media.fields.contents.forEach(s=>{n.push({name:s.fields.value.fields.name,link:s.fields.value.fields.link})}),r.social_media=n;try{r.regulation=decodeURIComponent(ps.decode(r.regulation).replace(/%/g,"%25"))}catch{r.regulation=ps.decode(r.regulation)}return r}transformExtensions(e,t,i=!0){let r=[];for(let n of t){let{key:s}=n.fields,{value:a}=n.fields;if(s==="labels")try{let c=decodeURIComponent(ps.decode(a));try{a=JSON.parse(c)}catch{a=c}}catch{}i&&(e[s]=a),r.push({key:s,value:a})}delete e.extension_fields,i||(e.extensions=r)}async getCetusConfig(e=!1){let t=this._sdk.sdkOptions.cetus_config.package_id,i=`${t}_getCetusConfig`,r=this.getCache(i,e);if(r!==void 0)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showPreviousTransaction:!0}}),s=Ip(n),a=await this._sdk.FullClient.queryEventsByPage({Transaction:s}),c={coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"",global_config_id:"",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""};if(a.data.length>0)for(let p of a.data)switch(hs(p.type).name){case"InitCoinListEvent":c.coin_list_id=p.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":c.launchpad_pools_id=p.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":c.clmm_pools_id=p.parsedJson.pools_id;break;case"InitConfigEvent":c.global_config_id=p.parsedJson.global_config_id,c.admin_cap_id=p.parsedJson.admin_cap_id;break;default:break}return c=await this.getCetusConfigHandle(c),c.clmm_pools_id.length>0&&this.updateCache(i,c,fi),c}async getCetusConfigHandle(e){let t=[e.clmm_pools_id,e.coin_list_id,e.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:t,options:{showContent:!0}})).forEach(i=>{(i.error!=null||i.data?.content?.dataType!=="moveObject")&&Je("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${i.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCetusConfigHandle"});let r=Hn(i),n=kp(i);switch(hs(n).name){case"ClmmPools":e.clmm_pools_handle=r.pools.fields.id.id;break;case"CoinList":e.coin_list_handle=r.coins.fields.id.id;break;case"LaunchpadPools":e.launchpad_pools_handle=r.pools.fields.id.id;break;default:break}}),e}updateCache(e,t,i=Sp){let r=this._cache[e];r?(r.overdue_time=Ul(i),r.value=t):r=new Cp(t,Ul(i)),this._cache[e]=r}getCache(e,t=!1){try{let i=this._cache[e];if(!i)return;if(t||!i.isValid()){delete this._cache[e];return}return i.value}catch(i){console.error(`Error accessing cache for key ${e}:`,i);return}}},Xp=Li(Fi()),Yp="position_liquidity_snapshot",Qp=(e=>(e.Deleted="Deleted",e.Exists="Exists",e.NotExists="NotExists",e))(Qp||{}),em=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],Ai=Li(Fi()),rm=Li(Fi()),um="partner",Kn="pool_script",Nr="pool_script_v2",xu="pool_script_v3",Nu="router",cm="router_with_partner",Lr="fetcher_script";var dm="utils";var hm=Li(Fi()),Pr=9e15,ir=1e9,xs="0123456789abcdef",no="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",oo="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ns={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Pr,maxE:Pr,crypto:!1},Ru,Ni,De=!0,lo="[DecimalError] ",tr=lo+"Invalid argument: ",Lu=lo+"Precision limit exceeded",Fu=lo+"crypto unavailable",Du="[object Decimal]",Nt=Math.floor,Mt=Math.pow,mm=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,gm=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,_m=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Bu=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,gi=1e7,Ne=7,vm=9007199254740991,wm=no.length-1,Rs=oo.length-1,oe={toStringTag:Du};oe.absoluteValue=oe.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Oe(e)};oe.ceil=function(){return Oe(new this.constructor(this),this.e+1,2)};oe.clampedTo=oe.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(tr+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};oe.comparedTo=oe.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};oe.cosine=oe.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Ne,r.rounding=1,i=bm(r,Hu(r,i)),r.precision=e,r.rounding=t,Oe(Ni==2||Ni==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};oe.cubeRoot=oe.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for(De=!1,s=v.s*Mt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Ot(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=Mt(i,1/3),e=Nt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=nt(g.plus(v).times(c),g.plus(p),a+2,1),Ot(c.d).slice(0,a)===(i=Ot(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Oe(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(Oe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return De=!0,Oe(r,e,y.rounding,t)};oe.decimalPlaces=oe.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-Nt(this.e/Ne))*Ne,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};oe.dividedBy=oe.div=function(e){return nt(this,new this.constructor(e))};oe.dividedToIntegerBy=oe.divToInt=function(e){var t=this,i=t.constructor;return Oe(nt(t,new i(e),0,1,1),i.precision,i.rounding)};oe.equals=oe.eq=function(e){return this.cmp(e)===0};oe.floor=function(){return Oe(new this.constructor(this),this.e+1,3)};oe.greaterThan=oe.gt=function(e){return this.cmp(e)>0};oe.greaterThanOrEqualTo=oe.gte=function(e){var t=this.cmp(e);return t==1||t===0};oe.hyperbolicCosine=oe.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/co(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=Fr(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return Oe(s,a.precision=i,a.rounding=r,!0)};oe.hyperbolicSine=oe.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=Fr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/co(5,e)),n=Fr(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,Oe(n,t,i,!0)};oe.hyperbolicTangent=oe.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,nt(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};oe.inverseCosine=oe.acos=function(){var e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?Si(t,r,n):new t(0):new t(NaN):e.isZero()?Si(t,r+4,n).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=n,e.times(2))};oe.inverseHyperbolicCosine=oe.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,De=!1,i=i.times(i).minus(1).sqrt().plus(i),De=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};oe.inverseHyperbolicSine=oe.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,De=!1,i=i.times(i).plus(1).sqrt().plus(i),De=!0,r.precision=e,r.rounding=t,i.ln())};oe.inverseHyperbolicTangent=oe.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?Oe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=nt(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};oe.inverseSine=oe.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=Si(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};oe.inverseTangent=oe.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=Rs)return a=Si(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=Rs)return a=Si(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/Ne+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(De=!1,t=Math.ceil(c/Ne),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),De=!0,Oe(a,v.precision=y,v.rounding=A,!0)};oe.isFinite=function(){return!!this.d};oe.isInteger=oe.isInt=function(){return!!this.d&&Nt(this.e/Ne)>this.d.length-2};oe.isNaN=function(){return!this.s};oe.isNegative=oe.isNeg=function(){return this.s<0};oe.isPositive=oe.isPos=function(){return this.s>0};oe.isZero=function(){return!!this.d&&this.d[0]===0};oe.lessThan=oe.lt=function(e){return this.cmp(e)<0};oe.lessThanOrEqualTo=oe.lte=function(e){return this.cmp(e)<1};oe.logarithm=oe.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if(De=!1,c=y+k,a=er(g,c),r=t?so(v,c+10):er(e,c),p=nt(a,r,c,1),en(p.d,n=y,A))do if(c+=10,a=er(g,c),r=t?so(v,c+10):er(e,c),p=nt(a,r,c,1),!s){+Ot(p.d).slice(n+1,n+15)+1==1e14&&(p=Oe(p,y+1,0));break}while(en(p.d,n+=10,A));return De=!0,Oe(p,y,A)};oe.minus=oe.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return De?Oe(e,c,p):e}if(i=Nt(e.e/Ne),v=Nt(k.e/Ne),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/Ne),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=gi-1;--g[n],g[r]+=gi}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=uo(g,i),De?Oe(e,c,p):e):new U(p===3?-0:0)};oe.modulo=oe.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?Oe(new r(i),r.precision,r.rounding):(De=!1,r.modulo==9?(t=nt(i,e.abs(),0,3,1),t.s*=e.s):t=nt(i,e,0,r.modulo,1),t=t.times(e),De=!0,i.minus(t))};oe.naturalExponential=oe.exp=function(){return Ls(this)};oe.naturalLogarithm=oe.ln=function(){return er(this)};oe.negated=oe.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Oe(e)};oe.plus=oe.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),De?Oe(e,c,p):e;if(s=Nt(y.e/Ne),r=Nt(e.e/Ne),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/Ne),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/gi|0,g[n]%=gi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=uo(g,r),De?Oe(e,c,p):e};oe.precision=oe.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(tr+e);return i.d?(t=Uu(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};oe.round=function(){var e=this,t=e.constructor;return Oe(new t(e),e.e+1,t.rounding)};oe.sine=oe.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Ne,r.rounding=1,i=Mm(r,Hu(r,i)),r.precision=e,r.rounding=t,Oe(Ni>2?i.neg():i,e,t,!0)):new r(NaN)};oe.squareRoot=oe.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for(De=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Ot(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Nt((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(nt(a,s,i+2,1)).times(.5),Ot(s.d).slice(0,i)===(t=Ot(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Oe(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Oe(r,p+1,1),e=!r.times(r).eq(a));break}return De=!0,Oe(r,p,v.rounding,e)};oe.tangent=oe.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=nt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Oe(Ni==2||Ni==4?i.neg():i,e,t,!0)):new r(NaN)};oe.times=oe.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=Nt(v.e/Ne)+Nt(e.e/Ne),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%gi|0,t=c/gi|0;s[n]=(s[n]+t)%gi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=uo(s,i),De?Oe(e,y.precision,y.rounding):e};oe.toBinary=function(e,t){return qs(this,2,e,t)};oe.toDecimalPlaces=oe.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Dt(e,0,ir),t===void 0?t=r.rounding:Dt(t,0,8),Oe(i,e+i.e+1,t))};oe.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,!0):(Dt(e,0,ir),t===void 0?t=n.rounding:Dt(t,0,8),r=Oe(new n(r),e+1,t),i=Ci(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};oe.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=Ci(n):(Dt(e,0,ir),t===void 0?t=s.rounding:Dt(t,0,8),r=Oe(new s(n),e+n.e+1,t),i=Ci(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};oe.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=Uu(U)-k.e-1,a=s%Ne,t.d[0]=Mt(10,a<0?Ne+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(tr+c);e=c.gt(t)?s>0?t:g:c}for(De=!1,c=new P(Ot(U)),v=P.precision,P.precision=s=U.length*Ne*2;y=nt(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=nt(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=nt(g,r,s,1).minus(k).abs().cmp(nt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,De=!0,A};oe.toHexadecimal=oe.toHex=function(e,t){return qs(this,16,e,t)};oe.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Dt(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(De=!1,i=nt(i,e,0,t,1).times(e),De=!0,Oe(i)):(e.s=i.s,i=e),i};oe.toNumber=function(){return+this};oe.toOctal=function(e,t){return qs(this,8,e,t)};oe.toPower=oe.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(Mt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Oe(c,r,s);if(t=Nt(e.e/Ne),t>=e.d.length-1&&(i=g<0?-g:g)<=vm)return n=ju(p,c,i,r),e.s<0?new p(1).div(n):Oe(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=Mt(+c,g),t=i==0||!isFinite(i)?Nt(g*(Math.log("0."+Ot(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):(De=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Ls(e.times(er(c,r+i)),r),n.d&&(n=Oe(n,r+5,1),en(n.d,r,s)&&(t=r+10,n=Oe(Ls(e.times(er(c,t+i)),t),t+5,1),+Ot(n.d).slice(r+1,r+15)+1==1e14&&(n=Oe(n,r+1,0)))),n.s=a,De=!0,p.rounding=s,Oe(n,r,s))};oe.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Dt(e,1,ir),t===void 0?t=n.rounding:Dt(t,0,8),r=Oe(new n(r),e,t),i=Ci(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};oe.toSignificantDigits=oe.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Dt(e,1,ir),t===void 0?t=r.rounding:Dt(t,0,8)),Oe(new r(i),e,t)};oe.toString=function(){var e=this,t=e.constructor,i=Ci(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};oe.truncated=oe.trunc=function(){return Oe(new this.constructor(this),this.e+1,1)};oe.valueOf=oe.toJSON=function(){var e=this,t=e.constructor,i=Ci(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Ot(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=Ne-r.length,i&&(s+=Qi(i)),s+=r;a=e[t],r=a+"",i=Ne-r.length,i&&(s+=Qi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Dt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(tr+e)}function en(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Ne,n=0):(n=Math.ceil((t+1)/Ne),t%=Ne),s=Mt(10,Ne-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==Mt(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==Mt(10,t-3)-1,a}function to(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=xs.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function bm(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/co(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=Fr(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var nt=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,ae,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=gi,k=Ne,v=Nt(r.e/k)-Nt(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,Ru=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Oe(j,c?s+j.e+1:s,a,U)}return j}})();function Oe(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=Ne,a=t,v=y[A=0],p=v/Mt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Ne),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Ne,a=s-Ne+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Ne,a=s-Ne+n,p=a<0?0:v/Mt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%Mt(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/Mt(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=Mt(10,(Ne-t%Ne)%Ne),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=Mt(10,Ne-s),y[A]=a>0?(v/Mt(10,n-a)%Mt(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==gi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=gi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return De&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Ci(e,t,i){if(!e.isFinite())return $u(e);var r,n=e.e,s=Ot(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Qi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Qi(-n-1)+s,i&&(r=i-a)>0&&(s+=Qi(r))):n>=a?(s+=Qi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Qi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Qi(r))),s}function uo(e,t){var i=e[0];for(t*=Ne;i>=10;i/=10)t++;return t}function so(e,t,i){if(t>wm)throw De=!0,i&&(e.precision=i),Error(Lu);return Oe(new e(no),t,1,!0)}function Si(e,t,i){if(t>Rs)throw Error(Lu);return Oe(new e(oo),t,i,!0)}function Uu(e){var t=e.length-1,i=t*Ne+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function Qi(e){for(var t="";e--;)t+="0";return t}function ju(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Ne+4);for(De=!1;;){if(i%2&&(s=s.times(t),Ql(s.d,a)&&(n=!0)),i=Nt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),Ql(t.d,a)}return De=!0,s}function Yl(e){return e.d[e.d.length-1]&1}function qu(e,t,i){for(var r,n,s=new e(t[0]),a=0;++a<t.length;){if(n=new e(t[a]),!n.s){s=n;break}r=s.cmp(n),(r===i||r===0&&s.s===i)&&(s=n)}return s}function Ls(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(De=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(Mt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Oe(s.times(e),p,1),i=i.times(++v),c=a.plus(nt(s,i,p,1)),Ot(c.d).slice(0,p)===Ot(a.d).slice(0,p)){for(n=y;n--;)a=Oe(a.times(a),p,1);if(t==null)if(g<3&&en(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Oe(a,A.precision=U,k,De=!0);else return A.precision=U,a}a=c}}function er(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?(De=!1,v=X):v=t,j.precision=v+=U,i=Ot(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=Ot(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=so(j,v+2,X).times(s+""),P=er(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Oe(P,X,K,De=!0):P;for(y=P,p=a=P=nt(P.minus(1),P.plus(1),v,1),A=Oe(P.times(P),v,1),n=3;;){if(a=Oe(a.times(A),v,1),g=p.plus(nt(a,new j(n),v,1)),Ot(g.d).slice(0,v)===Ot(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(so(j,v+2,X).times(s+""))),p=nt(p,new j(k),v,1),t==null)if(en(p.d,v-U,K,c))j.precision=v+=U,g=a=P=nt(y.minus(1),y.plus(1),v,1),A=Oe(P.times(P),v,1),n=c=1;else return Oe(p,j.precision=X,K,De=!0);else return j.precision=X,p;p=g,n+=2}}function $u(e){return String(e.s*e.s/0)}function io(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%Ne,i<0&&(r+=Ne),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Ne;r<n;)e.d.push(+t.slice(r,r+=Ne));t=t.slice(r),r=Ne-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),De&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function ym(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Bu.test(t))return io(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(gm.test(t))i=16,t=t.toLowerCase();else if(mm.test(t))i=2;else if(_m.test(t))i=8;else throw Error(tr+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=ju(r,new r(i),s,s*2)),g=to(t,i,gi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=uo(g,v),e.d=g,De=!1,a&&(e=nt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?Mt(2,p):tn.pow(2,p))),De=!0,e)}function Mm(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:Fr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/co(5,i)),t=Fr(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function Fr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Ne);for(De=!1,p=i.times(i),c=new e(r);;){if(a=nt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=nt(a.times(p),new e(t++*t++),v,1),a=c.plus(r),a.d[y]!==void 0){for(s=y;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s,g++}return De=!0,a.d.length=y+1,a}function co(e,t){for(var i=e;--t;)i*=e;return i}function Hu(e,t){var i,r=t.s<0,n=Si(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ni=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ni=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ni=Yl(i)?r?2:3:r?4:1,t;Ni=Yl(i)?r?1:4:r?3:2}return t.minus(n).abs()}function qs(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Dt(i,1,ir),r===void 0?r=k.rounding:Dt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=$u(e);else{for(v=Ci(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=to(Ci(A),10,n),A.e=A.d.length),y=to(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=nt(e,A,i,r,0,n),y=e.d,s=e.e,g=Ru),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=xs.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=to(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=xs.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function Ql(e,t){if(e.length>t)return e.length=t,!0}function Am(e){return new this(e).abs()}function Sm(e){return new this(e).acos()}function Cm(e){return new this(e).acosh()}function Em(e,t){return new this(e).plus(t)}function Im(e){return new this(e).asin()}function km(e){return new this(e).asinh()}function Tm(e){return new this(e).atan()}function Om(e){return new this(e).atanh()}function Pm(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=Si(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?Si(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=Si(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(nt(e,t,s,1)),t=Si(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(nt(e,t,s,1)),i}function xm(e){return new this(e).cbrt()}function Nm(e){return Oe(e=new this(e),e.e+1,2)}function Rm(e,t,i){return new this(e).clamp(t,i)}function Lm(e){if(!e||typeof e!="object")throw Error(lo+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,ir,"rounding",0,8,"toExpNeg",-Pr,0,"toExpPos",0,Pr,"maxE",0,Pr,"minE",-Pr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=Ns[i]),(r=e[i])!==void 0)if(Nt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(tr+i+": "+r);if(i="crypto",n&&(this[i]=Ns[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(Fu);else this[i]=!1;else throw Error(tr+i+": "+r);return this}function Fm(e){return new this(e).cos()}function Dm(e){return new this(e).cosh()}function Gu(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,eu(s)){g.s=s.s,De?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;De?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return io(g,s.toString())}if(p==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Bu.test(s)?io(g,s):ym(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,io(g,s.toString());throw Error(tr+s)}if(n.prototype=oe,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=Lm,n.clone=Gu,n.isDecimal=eu,n.abs=Am,n.acos=Sm,n.acosh=Cm,n.add=Em,n.asin=Im,n.asinh=km,n.atan=Tm,n.atanh=Om,n.atan2=Pm,n.cbrt=xm,n.ceil=Nm,n.clamp=Rm,n.cos=Fm,n.cosh=Dm,n.div=Bm,n.exp=Um,n.floor=jm,n.hypot=qm,n.ln=$m,n.log=Hm,n.log10=Vm,n.log2=Gm,n.max=Zm,n.min=Km,n.mod=Wm,n.mul=zm,n.pow=Xm,n.random=Jm,n.round=Ym,n.sign=Qm,n.sin=e1,n.sinh=t1,n.sqrt=i1,n.sub=r1,n.sum=n1,n.tan=o1,n.tanh=s1,n.trunc=a1,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function Bm(e,t){return new this(e).div(t)}function Um(e){return new this(e).exp()}function jm(e){return Oe(e=new this(e),e.e+1,3)}function qm(){var e,t,i=new this(0);for(De=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return De=!0,new this(1/0);i=t}return De=!0,i.sqrt()}function eu(e){return e instanceof tn||e&&e.toStringTag===Du||!1}function $m(e){return new this(e).ln()}function Hm(e,t){return new this(e).log(t)}function Gm(e){return new this(e).log(2)}function Vm(e){return new this(e).log(10)}function Zm(){return qu(this,arguments,-1)}function Km(){return qu(this,arguments,1)}function Wm(e,t){return new this(e).mod(t)}function zm(e,t){return new this(e).mul(t)}function Xm(e,t){return new this(e).pow(t)}function Jm(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Dt(e,1,ir),r=Math.ceil(e/Ne),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(Fu);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Ne,r&&e&&(n=Mt(10,Ne-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=Ne)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Ne&&(i-=Ne-r)}return a.e=i,a.d=c,a}function Ym(e){return Oe(e=new this(e),e.e+1,this.rounding)}function Qm(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function e1(e){return new this(e).sin()}function t1(e){return new this(e).sinh()}function i1(e){return new this(e).sqrt()}function r1(e,t){return new this(e).sub(t)}function n1(){var e=0,t=arguments,i=new this(t[e]);for(De=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return De=!0,Oe(i,this.precision,this.rounding)}function o1(e){return new this(e).tan()}function s1(e){return new this(e).tanh()}function a1(e){return Oe(e=new this(e),e.e+1,1)}oe[Symbol.for("nodejs.util.inspect.custom")]=oe.toString;oe[Symbol.toStringTag]="Decimal";var tn=oe.constructor=Gu(Ns);no=new tn(no);oo=new tn(oo);var St=tn;function ao(e){let t=jt.isSuiCoin(e.coin_type_a),i=jt.isSuiCoin(e.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:i}}function l1(e,t){return St.ceil(St(e).div(1+t)).toString()}var ur=class{static createCollectRewarderAndFeeParams(e,t,i,r,n,s){n===void 0&&(n=[...r]),s===void 0&&(s=[...r]);let a=_s(i.coin_type_a),c=_s(i.coin_type_b);if(i.collect_fee){let g=jt.buildCoinForAmount(t,n,BigInt(0),a,!1);n=g.remain_coins;let v=jt.buildCoinForAmount(t,s,BigInt(0),c,!1);s=v.remain_coins,t=e.Position.createCollectFeePayload({pool_id:i.pool_id,pos_id:i.pos_id,coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b},t,g.target_coin,v.target_coin)}let p=[];return i.rewarder_coin_types.forEach(g=>{switch(_s(g)){case a:p.push(jt.buildCoinForAmount(t,n,BigInt(0),g,!1).target_coin);break;case c:p.push(jt.buildCoinForAmount(t,s,BigInt(0),g,!1).target_coin);break;default:p.push(jt.buildCoinForAmount(t,r,BigInt(0),g,!1).target_coin);break}}),t=e.Rewarder.createCollectRewarderPayload(i,t,p),t}static async adjustTransactionForGas(e,t,i,r){r.setSender(e.getSenderAddress());let n=jt.selectCoinAssetGreaterThanOrEqual(t,i).selected_coins,s=jt.calculateTotalBalance(t);if(n.length===0&&Je("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${s}`),s-i>1e9)return{fixAmount:i};let a=await e.FullClient.calculationTxGas(gs.from(r));if(jt.selectCoinAssetGreaterThanOrEqual(t,BigInt(a),n.map(c=>c.coin_object_id)).selected_coins.length===0){let c=BigInt(a)+BigInt(500);if(s-i<c){i-=c,i<0&&Je("InsufficientBalance","gas Insufficient balance");let p=new gs;return{fixAmount:i,newTx:p}}}return{fixAmount:i}}static async buildAddLiquidityFixTokenForGas(e,t,i,r,n,s,a){n=await this.buildAddLiquidityFixToken(e,t,i,n,s,a);let{is_adjust_coin_a:c}=ao(i),p=c?i.amount_a:i.amount_b,g=await this.adjustTransactionForGas(e,jt.getCoinAssets(c?i.coin_type_a:i.coin_type_b,t),BigInt(p),n),{fixAmount:v}=g,y=g.newTx;if(y!=null){let A,k;if(c)i.amount_a=Number(v),A=this.buildAddLiquidityFixTokenCoinInput(y,!i.fix_amount_a,v.toString(),i.slippage,i.coin_type_a,t,!1,!0),k=this.buildAddLiquidityFixTokenCoinInput(y,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,t,!1,!0);else return i.amount_b=Number(v),A=this.buildAddLiquidityFixTokenCoinInput(y,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,t,!1,!0),k=this.buildAddLiquidityFixTokenCoinInput(y,i.fix_amount_a,v.toString(),i.slippage,i.coin_type_b,t,!1,!0),i=this.fixAddLiquidityFixTokenParams(i,r.slippage,r.cur_sqrt_price),this.buildAddLiquidityFixTokenArgs(y,e,t,i,A,k)}return n}static async buildAddLiquidityFixToken(e,t,i,r,n,s){r=r||new gs;let a,c;return n==null||s==null?(a=this.buildAddLiquidityFixTokenCoinInput(r,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,t,!1,!0),c=this.buildAddLiquidityFixTokenCoinInput(r,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,t,!1,!0)):(a={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},c={target_coin:s,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),r=this.buildAddLiquidityFixTokenArgs(r,e,t,i,a,c),r}static buildAddLiquidityFixTokenCoinInput(e,t,i,r,n,s,a=!0,c=!0){return t?jt.buildCoinForAmountInterval(e,s,{amount_second:BigInt(l1(i,r)),amount_first:BigInt(i)},n,a,c):jt.buildCoinForAmount(e,s,BigInt(i),n,a,c)}static fixAddLiquidityFixTokenParams(e,t,i){let r=e.fix_amount_a?e.amount_a:e.amount_b,n=fm.estLiquidityAndCoinAmountFromOneAmounts(Number(e.tick_lower),Number(e.tick_upper),new hm.default(r),e.fix_amount_a,!0,t,i);return e.amount_a=e.fix_amount_a?e.amount_a:n.coin_amount_limit_a,e.amount_b=e.fix_amount_a?n.coin_amount_limit_b:e.amount_b,e}static buildAddLiquidityFixTokenArgs(e,t,i,r,n,s){let a=[r.coin_type_a,r.coin_type_b],c=r.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:p,integrate:g}=t.sdkOptions;r.is_open||(e=this.createCollectRewarderAndFeeParams(t,e,r,i,n.remain_coins,s.remain_coins));let v=pm(p),y=r.is_open?[e.object(v.global_config_id),e.object(r.pool_id),e.pure.u32(Number(Xl(BigInt(r.tick_lower)).toString())),e.pure.u32(Number(Xl(BigInt(r.tick_upper)).toString())),n.target_coin,s.target_coin,e.pure.u64(r.amount_a),e.pure.u64(r.amount_b),e.pure.bool(r.fix_amount_a),e.object(Jl)]:[e.object(v.global_config_id),e.object(r.pool_id),e.object(r.pos_id),n.target_coin,s.target_coin,e.pure.u64(r.amount_a),e.pure.u64(r.amount_b),e.pure.bool(r.fix_amount_a),e.object(Jl)];return e.moveCall({target:`${g.published_at}::${Nr}::${c}`,typeArguments:a,arguments:y}),e}static checkCoinThreshold(e,t,i,r,n,s){t&&i.moveCall({target:`${e.sdkOptions.integrate.published_at}::${Nu}::check_coin_threshold`,typeArguments:[s],arguments:[r,i.pure.u64(n)]})}},Or=class Yi{static getDefaultSqrtPriceLimit(t){return new rm.default(t?sm:om)}static getDefaultOtherAmountThreshold(t){return t?lm:am}static async buildSwapTransactionForGas(t,i,r,n){let s=this.buildSwapTransaction(t,i,r);s.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,Ut.getCoinAssets(i.a2b?i.coin_type_a:i.coin_type_b,r),BigInt(i.by_amount_in?i.amount:i.amount_limit),s),{fixAmount:c,newTx:p}=a;if(p!==void 0){p.setSender(t.getSenderAddress()),i.by_amount_in?i.amount=c.toString():i.amount_limit=c.toString(),i=await this.fixSwapParams(t,i,n);let g=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a),v=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b);s=this.buildSwapTransactionArgs(p,i,t.sdkOptions,g,v)}return s}static buildSwapTransactionArgs(t,i,r,n,s){let{clmm_pool:a,integrate:c}=r,p=Yi.getDefaultSqrtPriceLimit(i.a2b),g=[i.coin_type_a,i.coin_type_b],{global_config_id:v}=zl(a);v===void 0&&Je("InvalidConfig","clmm.config.global_config_id is undefined");let y=i.swap_partner!==void 0,A=y?i.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":i.a2b?"swap_a2b":"swap_b2a",k=y?[t.object(v),t.object(i.pool_id),t.object(i.swap_partner),n.target_coin,s.target_coin,t.pure.bool(i.by_amount_in),t.pure.u64(i.amount),t.pure.u64(i.amount_limit),t.pure.u128(p.toString()),t.object(Zn)]:[t.object(v),t.object(i.pool_id),n.target_coin,s.target_coin,t.pure.bool(i.by_amount_in),t.pure.u64(i.amount),t.pure.u64(i.amount_limit),t.pure.u128(p.toString()),t.object(Zn)];return t.moveCall({target:`${c.published_at}::${Nr}::${A}`,typeArguments:g,arguments:k}),t}static async adjustTransactionForGas(t,i,r,n){n.setSender(t.getSenderAddress());let s=Ut.selectCoinAssetGreaterThanOrEqual(i,r).selected_coins,a=Ut.calculateTotalBalance(i);if(s.length===0&&Je("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${a}`),a-r>1e9)return{fixAmount:r};let c=await t.FullClient.calculationTxGas(n);if(Ut.selectCoinAssetGreaterThanOrEqual(i,BigInt(c),s.map(p=>p.coin_object_id)).selected_coins.length===0){let p=BigInt(c)+BigInt(500);if(a-r<p){r-=p,r<0&&Je("InsufficientBalance","gas Insufficient balance");let g=new ms;return{fixAmount:r,newTx:g}}}return{fixAmount:r}}static buildSwapTransaction(t,i,r){let n=new ms;n.setSender(t.getSenderAddress());let s=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1),a=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1);return n=this.buildSwapTransactionArgs(n,i,t.sdkOptions,s,a),n}static async fixSwapParams(t,i,r){let{current_pool:n}=r;try{let s=await t.Swap.preSwap({decimals_a:r.decimals_a,decimals_b:r.decimals_b,a2b:i.a2b,by_amount_in:i.by_amount_in,amount:i.amount,pool:n,current_sqrt_price:n.current_sqrt_price,coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b}),a=r.by_amount_in?s.estimated_amount_out:s.estimated_amount_in,c=nm(a,r.slippage,!r.by_amount_in);i.amount_limit=c.toString()}catch(s){Ri("InvalidConfig",s)}return i}static async buildSwapTransactionWithoutTransferCoinsForGas(t,i,r,n){let{tx:s,coin_ab_s:a}=Yi.buildSwapTransactionWithoutTransferCoins(t,i,r);s.setSender(t.getSenderAddress());let c=await Yi.adjustTransactionForGas(t,Ut.getCoinAssets(i.a2b?i.coin_type_a:i.coin_type_b,r),BigInt(i.by_amount_in?i.amount:i.amount_limit),s),{fixAmount:p,newTx:g}=c;if(g!==void 0){g.setSender(t.getSenderAddress()),i.by_amount_in?i.amount=p.toString():i.amount_limit=p.toString(),i=await Yi.fixSwapParams(t,i,n);let v=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),y=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),A=Yi.buildSwapTransactionWithoutTransferCoinArgs(t,g,i,t.sdkOptions,v,y);s=A.tx,a=A.txRes}return{tx:s,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,i,r){let n=new ms;n.setSender(t.getSenderAddress());let s=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),a=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),c=Yi.buildSwapTransactionWithoutTransferCoinArgs(t,n,i,t.sdkOptions,s,a);return{tx:c.tx,coin_ab_s:c.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(t,i,r,n,s,a){let{clmm_pool:c,integrate:p}=n,g=Yi.getDefaultSqrtPriceLimit(r.a2b),{global_config_id:v}=zl(c);v===void 0&&Je("InvalidConfig","clmm.config.global_config_id is undefined");let y=r.swap_partner!==void 0,A=y?"swap_with_partner":"swap",k=y?cm:Nu,U=y?[i.object(v),i.object(r.pool_id),i.object(r.swap_partner),s.target_coin,a.target_coin,i.pure.bool(r.a2b),i.pure.bool(r.by_amount_in),i.pure.u64(r.amount),i.pure.u128(g.toString()),i.pure.bool(!1),i.object(Zn)]:[i.object(v),i.object(r.pool_id),s.target_coin,a.target_coin,i.pure.bool(r.a2b),i.pure.bool(r.by_amount_in),i.pure.u64(r.amount),i.pure.u128(g.toString()),i.pure.bool(!1),i.object(Zn)],P=[r.coin_type_a,r.coin_type_b],W=i.moveCall({target:`${p.published_at}::${k}::${A}`,typeArguments:P,arguments:U});if(r.by_amount_in){let j=r.a2b?r.coin_type_b:r.coin_type_a,K=r.a2b?W[1]:W[0],X=Number(r.amount_limit);ur.checkCoinThreshold(t,r.by_amount_in,i,K,X,j)}return{tx:i,txRes:W}}};function u1(e){return{coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,current_sqrt_price:new Ai.default(e.current_sqrt_price),current_tick_index:e.current_tick_index,fee_growth_global_a:new Ai.default(e.fee_growth_global_a),fee_growth_global_b:new Ai.default(e.fee_growth_global_b),fee_protocol_coin_a:new Ai.default(e.fee_protocol_coin_a),fee_protocol_coin_b:new Ai.default(e.fee_protocol_coin_b),fee_rate:new Ai.default(e.fee_rate),liquidity:new Ai.default(e.liquidity),tick_indexes:[],tick_spacing:Number(e.tick_spacing),ticks:[],collection_name:""}}function c1(e,t,i,r,n,s){if(i===pi)return{amount_in:pi,amount_out:pi,next_sqrt_price:t,fee_amount:pi};let a=e.gte(t),c,p,g,v;if(s){let y=lr.checkMulDivFloor(r,lr.checkUnsignedSub(Vn,n),Vn,64),A=Wl(e,t,i,a);A.gt(y)?(c=y,v=lr.checkUnsignedSub(r,y),g=tm(e,i,y,a)):(c=A,v=lr.checkMulDivCeil(c,n,Vn.sub(n),64),g=t),p=Kl(e,g,i,a)}else{let y=Kl(e,t,i,a);y.gt(r)?(p=r,g=im(e,i,r,a)):(p=y,g=t),c=Wl(e,g,i,a),v=lr.checkMulDivCeil(c,n,Vn.sub(n),64)}return{amount_in:c,amount_out:p,next_sqrt_price:g,fee_amount:v}}function d1(e,t,i,r,n){let s=i,a=r.liquidity,{current_sqrt_price:c}=r,p={amount_in:pi,amount_out:pi,fee_amount:pi,ref_amount:pi,next_sqrt_price:pi,cross_tick_num:0},g,v,y=Or.getDefaultSqrtPriceLimit(e);for(let A of n){if(e&&r.current_tick_index<A.index||!e&&r.current_tick_index>=A.index||A===null)continue;e&&y.gt(A.sqrt_price)||!e&&y.lt(A.sqrt_price)?g=y:g=A.sqrt_price;let k=c1(c,g,a,s,r.fee_rate,t);if(k.amount_in.eq(pi)||(s=t?s.sub(k.amount_in.add(k.fee_amount)):s.sub(k.amount_out)),p.amount_in=p.amount_in.add(k.amount_in),p.amount_out=p.amount_out.add(k.amount_out),p.fee_amount=p.fee_amount.add(k.fee_amount),k.next_sqrt_price.eq(A.sqrt_price)?(v=A.liquidity_net.mul(new Ai.default(-1)),e?lr.is_neg(v)?a=a.add(new Ai.default(Zl(BigInt(v.toString()),128))):a=a.add(v):lr.is_neg(v)?a=a.sub(new Ai.default(Zl(BigInt(v.toString()),128))):a=a.sub(v),c=A.sqrt_price):c=k.next_sqrt_price,p.cross_tick_num+=1,s.eq(pi))break}return p.amount_in=p.amount_in.add(p.fee_amount),p.next_sqrt_price=c,p}var mi=Li(Fi());function _1(e,t,i){let r=Dr(e).name,n=Dr(t).name;return`${r}-${n}[${i}]`}function vs(e){let t=Vu(e),i=Dr(t),r=$s(e);r==null&&Je("InvalidPoolObject",`Pool id ${Fs(e)} not exists.`,{[ho.METHOD_NAME]:"buildPool"});let n=[];r.rewarder_manager.fields.rewarders.forEach(p=>{let{emissions_per_second:g}=p.fields,v=g1.fromX64(new mi.default(g)),y=Math.floor(v.toNumber()*60*60*24);n.push({emissions_per_second:g,coin_type:Dr(p.fields.reward_coin.fields.name).source_address,growth_global:p.fields.growth_global,emissions_every_day:y})});let s=r.is_pause,a={disable_add_liquidity:s,disable_remove_liquidity:s,disable_swap:s,disable_flash_loan:s,disable_collect_fee:s,disable_collect_reward:s},c={id:Fs(e),pool_type:t,coin_type_a:i.type_arguments[0],coin_type_b:i.type_arguments[1],coin_amount_a:r.coin_a,coin_amount_b:r.coin_b,current_sqrt_price:r.current_sqrt_price,current_tick_index:cr(BigInt(r.current_tick_index.fields.bits)),fee_growth_global_a:r.fee_growth_global_a,fee_growth_global_b:r.fee_growth_global_b,fee_protocol_coin_a:r.fee_protocol_coin_a,fee_protocol_coin_b:r.fee_protocol_coin_b,fee_rate:r.fee_rate,pool_status:a,liquidity:r.liquidity,position_manager:{positions_handle:r.position_manager.fields.positions.fields.id.id,size:r.position_manager.fields.positions.fields.size},rewarder_infos:n,rewarder_last_updated_time:r.rewarder_manager.fields.last_updated_time,tick_spacing:r.tick_spacing,ticks_handle:r.tick_manager.fields.ticks.fields.id.id,uri:r.url,index:Number(r.index),name:""};return c.name=_1(c.coin_type_a,c.coin_type_b,c.tick_spacing),c}function ws(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&Je("InvalidPositionObject",`Position not exists. Get Position error:${e.error}`,{[ho.METHOD_NAME]:"buildPosition"});let t={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},i={...t,pos_object_id:"",owner:"",type:"",coin_type_a:"",coin_type_b:"",liquidity:"",tick_lower_index:0,tick_upper_index:0,index:0,pool:"",reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"},r=$s(e);if(r){let a=Vu(e),c=m1(e);"nft"in r?(r=r.nft.fields,t.description=r.description,t.name=r.name,t.link=r.url):t=h1(e),i={...t,pos_object_id:r.id.id,owner:c.AddressOwner,type:a,liquidity:r.liquidity,coin_type_a:r.coin_type_a.fields.name,coin_type_b:r.coin_type_b.fields.name,tick_lower_index:cr(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:cr(BigInt(r.tick_upper_index.fields.bits)),index:r.index,pool:r.pool,reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"}}let n=f1(e);n&&(i.pos_object_id=n.objectId,i.position_status="Deleted");let s=p1(e);return s&&(i.pos_object_id=s,i.position_status="NotExists"),i}function Ds(e){let t={reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0"};e="fields"in e?e.fields:e,e.rewards.forEach((n,s)=>{let{amount_owned:a,growth_inside:c}="fields"in n?n.fields:n;s===0?(t.reward_amount_owned_0=a,t.reward_growth_inside_0=c):s===1?(t.reward_amount_owned_1=a,t.reward_growth_inside_1=c):s===2&&(t.reward_amount_owned_2=a,t.reward_growth_inside_2=c)});let i="fields"in e.tick_lower_index?e.tick_lower_index.fields.bits:e.tick_lower_index.bits,r="fields"in e.tick_upper_index?e.tick_upper_index.fields.bits:e.tick_upper_index.bits;return{liquidity:e.liquidity,tick_lower_index:cr(BigInt(i)),tick_upper_index:cr(BigInt(r)),...t,fee_growth_inside_a:e.fee_growth_inside_a,fee_owned_a:e.fee_owned_a,fee_growth_inside_b:e.fee_growth_inside_b,fee_owned_b:e.fee_owned_b,pos_object_id:e.position_id}}function bs(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&Je("InvalidTickObject",`Tick not exists. Get tick data error:${e.error}`,{[ho.METHOD_NAME]:"buildTickData"});let t=$s(e).value.fields.value.fields;return{object_id:Fs(e),index:cr(BigInt(t.index.fields.bits)),sqrt_price:new mi.default(t.sqrt_price),liquidity_net:new mi.default(t.liquidity_net.fields.bits),liquidity_gross:new mi.default(t.liquidity_gross),fee_growth_outside_a:new mi.default(t.fee_growth_outside_a),fee_growth_outside_b:new mi.default(t.fee_growth_outside_b),rewarders_growth_outside:t.rewards_growth_outside}}function v1(e){(!e||!e.index||!e.sqrt_price||!e.liquidity_net||!e.liquidity_gross||!e.fee_growth_outside_a||!e.fee_growth_outside_b)&&Je("InvalidTickFields","Invalid tick fields.",{[ho.METHOD_NAME]:"buildTickDataByEvent"});let t=cr(BigInt(e.index.bits)),i=new mi.default(e.sqrt_price),r=new mi.default(e.liquidity_net.bits),n=new mi.default(e.liquidity_gross),s=new mi.default(e.fee_growth_outside_a),a=new mi.default(e.fee_growth_outside_b),c=e.rewards_growth_outside||[];return{object_id:"",index:t,sqrt_price:i,liquidity_net:r,liquidity_gross:n,fee_growth_outside_a:s,fee_growth_outside_b:a,rewarders_growth_outside:c}}function w1(e,t,i){let r=[],{timestampMs:n,events:s}=e,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((c,p)=>{let g=Dr(c.type).name;if(a.includes(g)){let v={tx_digest:c.id.txDigest,package_id:c.packageId,transaction_module:c.transactionModule,sender:c.sender,type:c.type,timestamp_ms:n||"0",parsed_json:c.parsedJson,index:`${t}_${p}`};switch(g){case"CollectFeeEvent":i.includes(v.parsed_json.position)&&(Yr(v.parsed_json.amount_a).gt(0)||Yr(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":(Yr(v.parsed_json.amount_a).gt(0)||Yr(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(i.includes(v.parsed_json.position)||i.includes(v.parsed_json.wrapped_position_id))&&Yr(v.parsed_json.amount).gt(0)&&r.push(v);break;default:break}}}),r}function b1(e,t,i,r){let n=[],{timestampMs:s,events:a}=e;return a?.forEach((c,p)=>{let{name:g,address:v}=Dr(c.type);if(em.includes(g)&&v===i&&r===c.parsedJson.pool){let y={tx:c.id.txDigest,sender:c.sender,type:c.type,block_time:s||"0",index:`${t}_${p}`,parsed_json:c.parsedJson};n.push(y)}}),n}function Bs(e,t,i,r){t.moveCall({target:`${e.sdkOptions.integrate.published_at}::${dm}::transfer_coin_to_sender`,typeArguments:[r],arguments:[i]})}function y1(e,t,i,r,n){n!=null?t.transferObjects([i],t.pure.address(n)):Bs(e,t,i,r)}var T1=1e4,Rr=class{static parseClmmVestInfo(e){let t=As(e),i=k1(e),r=I1(i),n=t.global_vesting_periods.map(s=>({period:s.fields.period,release_time:s.fields.release_time,redeemed_amount:s.fields.redeemed_amount,percentage:ou(s.fields.percentage).div(T1).toNumber()}));return{id:t.id.id,balance:t.balance,global_vesting_periods:n,total_value:t.total_value,total_cetus_amount:t.total_cetus_amount,redeemed_amount:t.redeemed_amount,start_time:t.start_time,type:r.full_address,positions:{id:t.positions.fields.id,size:t.positions.fields.size}}}static parsePositionVesting(e){return{position_id:e.position_id,cetus_amount:e.cetus_amount,redeemed_amount:e.redeemed_amount,is_paused:e.is_paused,impaired_a:e.impaired_a,impaired_b:e.impaired_b,period_details:e.period_details,coin_type_a:su(e.coin_a.name,!1),coin_type_b:su(e.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(e){let t=As(e);return{current_sqrt_price:t.current_sqrt_price,remove_percent:ou(t.remove_percent).div(1e6).toString(),snapshots:{id:t.snapshots.fields.id.id,size:t.snapshots.fields.size}}}static parsePositionSnapshot(e){let t=As(e),i=t.value.fields.value.fields;return{position_id:t.name,liquidity:i.liquidity,tick_lower_index:nu(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:nu(BigInt(i.tick_upper_index.fields.bits)),fee_owned_a:i.fee_owned_a,fee_owned_b:i.fee_owned_b,value_cut:i.value_cut,rewards:i.rewards}}},O1=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getPositionList(e,t="all"){let i={data:[],has_next_page:!0},r=await this._sdk.FullClient.getDynamicFieldsByPage(e,t);i.has_next_page=r.has_next_page,i.next_cursor=r.next_cursor;let n=r.data.map(a=>(a.error!=null&&Je("InvalidConfig",`when getPositionList get position objects error: ${a.error}, please check the rpc, contracts address config and position id.`,{[rt.METHOD_NAME]:"getPositionList"}),a.name.value)),s=await this._sdk.Position.getSimplePositionList(n);return i.data=s,i}async getPoolImmutablesWithPage(e="all",t=!1){let{package_id:i}=this._sdk.sdkOptions.clmm_pool,r=[],n={data:[],has_next_page:!1},s=e==="all",a=`${i}_getPoolImmutables`;if(s){let c=this._sdk.getCache(a,t);c&&r.push(...c)}if(r.length===0)try{let c=`${i}::factory::CreatePoolEvent`,p=await this._sdk.FullClient.queryEventsByPage({MoveEventType:c},e);n.has_next_page=p.has_next_page,n.next_cursor=p.next_cursor,p.data.forEach(g=>{let v=g.parsedJson;v&&r.push({id:v.pool_id,tick_spacing:v.tick_spacing,coin_type_a:Sr(v.coin_type_a).full_address,coin_type_b:Sr(v.coin_type_b).full_address})})}catch(c){return Ri("FetchError",c,{[rt.METHOD_NAME]:"getPoolImmutables"})}return n.data=r,s&&this._sdk.updateCache(`${i}_getPoolImmutables`,r,Wn),n}async getPoolsWithPage(e="all",t=!1){let i={data:[],has_next_page:!1},r=await this.getPoolImmutablesWithPage(e,t),n=await this._sdk.FullClient.batchGetObjects(r.data.map(s=>s.id),{showContent:!0,showType:!0});for(let s of n){(s.error!=null||s.data?.content?.dataType!=="moveObject")&&Je("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[rt.METHOD_NAME]:"getPoolsWithPage"});let a=vs(s);i.data.push(a);let c=`${a.id}_getPoolObject`;this._sdk.updateCache(c,a,Wn)}return i.has_next_page=r.has_next_page,i.next_cursor=r.next_cursor,i}async getPoolLiquiditySnapshot(e,t=!1){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x1::string::String",value:Yp}}),r=Rr.parsePoolLiquiditySnapshot(i);if(t){let n=(await this._sdk.FullClient.getDynamicFieldsByPage(r.snapshots.id)).data.map(s=>s.objectId);if(n.length>0){let s=await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0}),a=[];s.forEach(c=>{let p=Rr.parsePositionSnapshot(c);a.push(p)}),r.position_snapshots=a}}return r}catch(i){return Ri("InvalidPoolObject",i,{[rt.METHOD_NAME]:"getPoolLiquiditySnapshot",[rt.REQUEST_PARAMS]:e})}}async getPositionSnapshot(e,t){let i=await this._sdk.FullClient.getDynamicFieldObjects(e,t,"0x2::object::ID","address"),r=[];return i.forEach(n=>{try{let s=Rr.parsePositionSnapshot(n);r.push(s)}catch(s){console.log("getPositionSnapshot error: ",s)}}),r}async getAssignPools(e){if(e.length===0)return[];let t=[],i=await this._sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0});for(let r of i){(r.error!=null||r.data?.content?.dataType!=="moveObject")&&Je("InvalidPoolObject",`getPools error code: ${r.error?.code??"unknown error"}, please check config and object ids`,{[rt.METHOD_NAME]:"getAssignPools"});let n=vs(r);t.push(n);let s=`${n.id}_getPoolObject`;this._sdk.updateCache(s,n,Wn)}return t}async getPool(e,t=!0,i=!1){let r=`${e}_getPoolObject`,n=this._sdk.getCache(r,t);if(n!==void 0)return n;let s=await this._sdk.FullClient.getObject({id:e,options:{showType:!0,showContent:!0}});(s.error!=null||s.data?.content?.dataType!=="moveObject")&&Je("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[rt.METHOD_NAME]:"getPool"});let a=vs(s);if(i){let c=await this.getPoolStatus(e);c&&(a.pool_status=c)}return this._sdk.updateCache(r,a),a}async getPoolByCoins(e,t){if(e.length===0)return[];for(let c=0;c<e.length;c++)e[c]==="0x2::sui::SUI"&&(e[c]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let i=this._sdk.sdkOptions.stats_pools_url;i||Je("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[rt.METHOD_NAME]:"getPoolByCoins"}),i+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${e.join(",")}`;let r=await fetch(i),n;try{n=await r.json()}catch(c){Ri("FetchError",c,{[rt.METHOD_NAME]:"getPoolByCoins",[rt.REQUEST_PARAMS]:i})}let s=n.data.lp_list,a=[];for(let c of s)e.includes(c.coin_a_address)&&e.includes(c.coin_b_address)&&(t!=null?c.object.feeRate===t&&a.push(c.address):a.push(c.address));return a.length>0?await this.getAssignPools(a):[]}async createPoolPayload(e,t){if(iu(yr(e.coin_type_a),yr(e.coin_type_b))){let i=e.coin_type_b;e.coin_type_b=e.coin_type_a,e.coin_type_a=i;let r=e.metadata_b;e.metadata_b=e.metadata_a,e.metadata_a=r}return await this.createPoolAndAddLiquidity(e,t)}async createPoolRowPayload(e,t){if(iu(yr(e.coin_type_a),yr(e.coin_type_b))){let i=e.coin_type_b;e.coin_type_b=e.coin_type_a,e.coin_type_a=i;let r=e.metadata_b;e.metadata_b=e.metadata_a,e.metadata_a=r}return await this.createPoolAndAddLiquidityRow(e,t)}async getClmmConfigs(e=!1){let{package_id:t}=this._sdk.sdkOptions.clmm_pool,i=`${t}_getInitEvent`,r=this._sdk.getCache(i,e);if(r!==void 0)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showPreviousTransaction:!0}}),s=C1(n),a=(await this._sdk.FullClient.queryEventsByPage({Transaction:s})).data,c={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return a.length>0&&(a.forEach(p=>{let g=p.parsedJson;if(p.type)switch(Sr(p.type).full_address){case`${t}::config::InitConfigEvent`:c.global_config_id=g.global_config_id,c.admin_cap_id=g.admin_cap_id;break;case`${t}::factory::InitFactoryEvent`:c.pools_id=g.pools_id;break;case`${t}::rewarder::RewarderInitEvent`:c.global_vault_id=g.global_vault_id;break;case`${t}::partner::InitPartnerEvent`:c.partners_id=g.partners_id;break;default:break}}),this._sdk.updateCache(i,c,Wn)),c}async getPoolTransactionList({pool_id:e,pagination_args:t,order:i="descending",full_rpc_url:r}){let{FullClient:n,sdkOptions:s}=this._sdk,a;r?a=A1(new Jp({url:r})):a=n;let c={data:[],has_next_page:!1},p=50,g=t,v=t.limit||10;do{let y=await a.queryTransactionBlocksByPage({ChangedObject:e},{...g,limit:50},i);y.data.forEach((A,k)=>{c.next_cursor=y.next_cursor;let U=b1(A,k,s.clmm_pool.package_id,e);c.data=[...c.data,...U]}),c.has_next_page=y.has_next_page,c.next_cursor=y.next_cursor,g.cursor=y.next_cursor}while(c.data.length<v&&c.has_next_page);return c.data.length>v&&(c.data=c.data.slice(0,v),c.next_cursor=c.data[c.data.length-1].tx),c}async calculateCreatePoolWithPrice(e){let{current_price:t,slippage:i,tick_spacing:r,add_mode_params:n,price_base_coin:s,coin_decimals_a:a,coin_decimals_b:c}=e,p=Ms.priceToSqrtPriceX64(s==="coin_a"?Ar(t):Ar(1).div(t),a,c),g=0,v=0;if(n.is_full_range)g=ru.getMinIndex(r),v=ru.getMaxIndex(r);else{let{min_price:K,max_price:X}=n;g=Ms.priceToInitializeTickIndex(s==="coin_a"?Ar(K):Ar(1).div(X),a,c,r),v=Ms.priceToInitializeTickIndex(s==="coin_a"?Ar(X):Ar(1).div(K),a,c,r)}let{coin_amount:y,fix_amount_a:A}=e,{coin_amount_limit_a:k,coin_amount_limit_b:U,liquidity_amount:P,coin_amount_a:W,coin_amount_b:j}=M1.estLiquidityAndCoinAmountFromOneAmounts(g,v,new Xp.default(y),A,!0,i,p);return{coin_amount_a:W,coin_amount_b:j,coin_amount_limit_a:k,coin_amount_limit_b:U,liquidity:P,initialize_sqrt_price:p.toString(),tick_lower:g,tick_upper:v,fix_amount_a:A}}async createPoolAndAddLiquidity(e,t){t=t||new Jr,t.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:r}=this.sdk.sdkOptions,n=ys(r),s=n.global_config_id,a=n.pools_id,c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),p=zn.buildCoinForAmount(t,c,BigInt(e.amount_a),e.coin_type_a,!1,!0),g=zn.buildCoinForAmount(t,c,BigInt(e.amount_b),e.coin_type_b,!1,!0),v=[t.object(s),t.object(a),t.pure.u32(e.tick_spacing),t.pure.u128(e.initialize_sqrt_price),t.pure.string(e.uri),t.pure.u32(Number(Mr(BigInt(e.tick_lower)).toString())),t.pure.u32(Number(Mr(BigInt(e.tick_upper)).toString())),p.target_coin,g.target_coin,t.object(e.metadata_a),t.object(e.metadata_b),t.pure.bool(e.fix_amount_a),t.object(tu)];return t.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:v}),Bs(this._sdk,t,p.target_coin,e.coin_type_a),Bs(this._sdk,t,g.target_coin,e.coin_type_b),t}async createPoolAndAddLiquidityRow(e,t){t=t||new Jr;let{clmm_pool:i}=this.sdk.sdkOptions,r=ys(i),n=r.global_config_id,s=r.pools_id,a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=zn.buildCoinForAmount(t,a,BigInt(e.amount_a),e.coin_type_a,!1,!0),p=zn.buildCoinForAmount(t,a,BigInt(e.amount_b),e.coin_type_b,!1,!0),g=[t.object(n),t.object(s),t.pure.u32(e.tick_spacing),t.pure.u128(e.initialize_sqrt_price),t.pure.string(e.uri),t.pure.u32(Number(Mr(BigInt(e.tick_lower)).toString())),t.pure.u32(Number(Mr(BigInt(e.tick_upper)).toString())),c.target_coin,p.target_coin,t.object(e.metadata_a),t.object(e.metadata_b),t.pure.bool(e.fix_amount_a),t.object(tu)],v=t.moveCall({target:`${i.published_at}::pool_creator::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:g});return{tx:t,pos_id:v[0],remain_coin_a:v[1],remain_coin_b:v[2],remain_coin_type_a:e.coin_type_a,remain_coin_type_b:e.coin_type_b}}async createPoolWithPriceReturnPositionPayload(e,t){let{coin_type_a:i,coin_type_b:r,tick_spacing:n,uri:s,calculate_result:a}=e,{initialize_sqrt_price:c,tick_lower:p,tick_upper:g,liquidity:v,coin_amount_a:y,coin_amount_b:A,fix_amount_a:k,coin_amount_limit_a:U,coin_amount_limit_b:P}=a,W=await this._sdk.FullClient.fetchCoinMetadata(i),j=await this._sdk.FullClient.fetchCoinMetadata(r);if(W===null)return Je("FetchError",`fetch coin ${i} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});if(j===null)return Je("FetchError",`fetch coin ${r} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});let K=W.id,X=j.id;return this.createPoolRowPayload({tick_spacing:n,initialize_sqrt_price:c,uri:s||"",coin_type_a:i,coin_type_b:r,amount_a:k?y:U,amount_b:k?P:A,fix_amount_a:k,tick_lower:p,tick_upper:g,metadata_a:K,metadata_b:X},t)}async createPoolWithPricePayload(e){let{coin_type_a:t,coin_type_b:i,tick_spacing:r,uri:n,calculate_result:s}=e,{initialize_sqrt_price:a,tick_lower:c,tick_upper:p,liquidity:g,coin_amount_a:v,coin_amount_b:y,fix_amount_a:A,coin_amount_limit_a:k,coin_amount_limit_b:U}=s,P=await this._sdk.FullClient.fetchCoinMetadata(t),W=await this._sdk.FullClient.fetchCoinMetadata(i);if(P===null)return Je("FetchError",`fetch coin ${t} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});if(W===null)return Je("FetchError",`fetch coin ${i} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});let j=P.id,K=W.id;return this.createPoolPayload({tick_spacing:r,initialize_sqrt_price:a,uri:n||"",coin_type_a:t,coin_type_b:i,amount_a:A?v:k,amount_b:A?U:y,fix_amount_a:A,tick_lower:c,tick_upper:p,metadata_a:j,metadata_b:K})}async fetchTicks(e){let t=[],i=[];for(;;){let r=await this.getTicks({pool_id:e.pool_id,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,start:i,limit:512});if(t=[...t,...r],r.length<512)break;i=[Number(Mr(BigInt(r[r.length-1].index)))]}return t}async getTicks(e){let{integrate:t}=this.sdk.sdkOptions,i=[],r=[e.coin_type_a,e.coin_type_b],n=new Jr,s=n.makeMoveVec({elements:e.start.map(p=>n.pure.u32(p)),type:"u32"}),a=[n.object(e.pool_id),s,n.pure.u64(e.limit.toString())];n.moveCall({target:`${t.published_at}::${Lr}::fetch_ticks`,arguments:a,typeArguments:r});let c=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:yr("0x0")});return c.error!=null&&Je("InvalidTickObjectId",`getTicks error code: ${c.error??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTicks",[rt.REQUEST_PARAMS]:e}),c.events?.forEach(p=>{Sr(p.type).name==="FetchTicksResultEvent"&&p.parsedJson.ticks.forEach(g=>{i.push(v1(g))})}),i}async fetchPoolPositionInfoList(e){let{integrate:t}=this.sdk.sdkOptions,i=[],r=[],n=512;for(;;){let s=[e.coin_type_a,e.coin_type_b],a=new Jr,c=a.pure.vector("id",r.map(y=>y)),p=[a.object(e.pool_id),c,a.pure.u64(n)];a.moveCall({target:`${t.published_at}::${Lr}::fetch_positions`,arguments:p,typeArguments:s});let g=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:yr("0x0")});g.error!=null&&Je("InvalidPositionRewardObject",`fetch position info error code: ${g.error??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"fetchPoolPositionInfoList",[rt.REQUEST_PARAMS]:e});let v=[];if(g?.events?.forEach(y=>{Sr(y.type).name==="FetchPositionsEvent"&&y.parsedJson.positions.forEach(A=>{let k=Ds(A);v.push(k)})}),i.push(...v),v.length<n)break;r=[v[v.length-1].pos_object_id]}return i}async fetchTicksByRpc(e){let t=[],i=null,r=50;for(;;){let n=[],s=await this.sdk.FullClient.getDynamicFields({parentId:e,cursor:i,limit:r});if(i=s.nextCursor,s.data.forEach(a=>{Sr(a.objectType).module==="skip_list"&&n.push(a.objectId)}),t=[...t,...await this.getTicksByRpc(n)],!s.hasNextPage)break}return t}async getTicksByRpc(e){let t=[],i=await this.sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0});for(let r of i){(r.error!=null||r.data?.content?.dataType!=="moveObject")&&Je("InvalidTickObjectId",`getTicksByRpc error code: ${r.error?.code??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTicksByRpc"});let n=bs(r);n!=null&&t.push(n)}return t}async getTickDataByIndex(e,t){let i={type:"u64",value:Mr(BigInt(E1(t).toString())).toString()},r=await this.sdk.FullClient.getDynamicFieldObject({parentId:e,name:i});return(r.error!=null||r.data?.content?.dataType!=="moveObject")&&Je("InvalidTickIndex",`get tick by index: ${t} error: ${r.error}`,{[rt.METHOD_NAME]:"getTickDataByIndex"}),bs(r)}async getTickDataByObjectId(e){let t=await this.sdk.FullClient.getObject({id:e,options:{showContent:!0}});return(t.error!=null||t.data?.content?.dataType!=="moveObject")&&Je("InvalidTickObjectId",`getTicksByRpc error code: ${t.error?.code??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTickDataByObjectId"}),bs(t)}async getPartnerRefFeeAmount(e,t=!0){let i=await this._sdk.FullClient.batchGetObjects([e],{showOwner:!0,showContent:!0,showDisplay:t,showType:!0});i[0].data?.content?.dataType!=="moveObject"&&Je("NotFoundPartnerObject",`get partner by object id: ${e} error: ${i[0].error}`,{[rt.METHOD_NAME]:"getPartnerRefFeeAmount"});let r=i[0].data.content.fields.balances,n=await this._sdk.FullClient.getDynamicFieldsByPage(r.fields.id.id),s=[];n.data.forEach(c=>{c.objectId!=null&&s.push(c.objectId)});let a=[];return(await this._sdk.FullClient.batchGetObjects(s,{showOwner:!0,showContent:!0,showDisplay:t,showType:!0})).forEach(c=>{(c.error!=null||c.data?.content?.dataType!=="moveObject")&&Je("InvalidPartnerRefFeeFields",`get coin by object id: ${c.data.objectId} error: ${c.error}`,{[rt.METHOD_NAME]:"getPartnerRefFeeAmount"});let p={coin_type:c.data.content.fields.name,coin_object_id:c.data.objectId,balance:BigInt(c.data.content.fields.value)};a.push(p)}),a}async claimPartnerRefFeePayload(e,t,i){let r=new Jr,{clmm_pool:n}=this.sdk.sdkOptions,{global_config_id:s}=ys(n),a=[i],c=[r.object(s),r.object(e),r.object(t)];return r.moveCall({target:`${n.published_at}::${um}::claim_ref_fee`,arguments:c,typeArguments:a}),r}async getPoolStatus(e){try{let t=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x1::string::String",value:"pool_status"}}),i=S1(t).position.fields.status;if(i)return i}catch(t){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",t)}}},Xn=Li(Fi()),D1=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.clmm_pool.package_id}::position::Position`}async getPositionTransactionList({pos_id:e,origin_pos_id:t,full_rpc_url:i,pagination_args:r="all",order:n="ascending"}){let{FullClient:s}=this._sdk,a=[e];t&&a.push(t);let c;i?c=L1(new P1({url:i})):c=s;let p={data:[],has_next_page:!1};try{let g=await c.queryTransactionBlocksByPage({ChangedObject:e},r,n);return g.data.forEach((v,y)=>{let A=w1(v,y,a);p.data=[...p.data,...A]}),p.has_next_page=g.has_next_page,p.next_cursor=g.next_cursor,p}catch(g){Ri("FetchError",g,{[Xi.METHOD_NAME]:"getPositionTransactionList"})}return p}async getPositionList(e,t=[],i=!0){let r=[],n=await this._sdk.FullClient.getOwnedObjectsByPage(e,{options:{showType:!0,showContent:!0,showDisplay:i,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),s=t.length>0;for(let a of n.data)if(R1(a.data.type).full_address===this.buildPositionType()){let c=ws(a),p=`${c.pos_object_id}_getPositionList`;this._sdk.updateCache(p,c),s?t.includes(c.pool)&&r.push(c):r.push(c)}return r}async getPosition(e,t,i=!0,r=!0){let n=await this.getSimplePosition(t,r);return i&&(n=await this.updatePositionInfo(e,n)),n}async getPositionById(e,t=!0,i=!0){let r=await this.getSimplePosition(e,i);if(t){let n=await this._sdk.Pool.getPool(r.pool,!1);return await this.updatePositionInfo(n.position_manager.positions_handle,r)}return r}async getSimplePosition(e,t=!0){let i=`${e}_getPositionList`,r=this.getSimplePositionByCache(e);if(r===void 0){let n=await this.sdk.FullClient.getObject({id:e,options:{showContent:!0,showType:!0,showDisplay:t,showOwner:!0}});r=ws(n),this._sdk.updateCache(i,r)}return r}getSimplePositionByCache(e){let t=`${e}_getPositionList`;return this._sdk.getCache(t)}async getSimplePositionList(e,t=!0){let i=[],r=[];return e.forEach(n=>{let s=this.getSimplePositionByCache(n);s?i.push(s):r.push(n)}),r.length>0&&(await this._sdk.FullClient.batchGetObjects(r,{showOwner:!0,showContent:!0,showDisplay:t,showType:!0})).forEach(n=>{if(n.error==null){let s=ws(n);i.push(s);let a=`${s.pos_object_id}_getPositionList`;this._sdk.updateCache(a,s)}}),i}async updatePositionInfo(e,t){let i=await this.getPositionInfo(e,t.pos_object_id);return{...t,...i}}async getPositionInfo(e,t){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x2::object::ID",value:t}}),r=lu(i.data).value.fields.value;return Ds(r)}catch(i){return Ri("FetchError",i,{[Xi.METHOD_NAME]:"getPositionInfo",[Xi.REQUEST_PARAMS]:{position_handle:e,position_id:t}})}}async getPositionInfoList(e){try{let t=[],i=[];return e.forEach(async r=>{let{position_handle:n,position_ids:s}=r;s.forEach(a=>{let c=F1(n,a,"0x2::object::ID","address");i.push(c)})}),i.length===0?[]:((await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0,showOwner:!0})).forEach(r=>{try{let n=lu(r.data).value.fields.value,s=Ds(n);t.push(s)}catch(n){console.log("getPositionInfoList error",n)}}),t)}catch(t){return Ri("FetchError",t,{[Xi.METHOD_NAME]:"getPositionInfoList",[Xi.REQUEST_PARAMS]:{options:e}})}}buildFetchPosFee(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n=[e.coin_type_a,e.coin_type_b],s=[t.object(xi(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id)];t.moveCall({target:`${r.published_at}::${Lr}::fetch_position_fees`,arguments:s,typeArguments:n})}parsedPosFeeData(e){let t={},i=e.events?.filter(r=>r.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let r=0;r<i.length;r+=1){let{parsedJson:n}=i[r],s={position_id:n.position_id,fee_owned_a:n.fee_owned_a,fee_owned_b:n.fee_owned_b};t[n.position_id]=s}return t}async fetchPosFeeAmount(e){let{clmm_pool:t,integrate:i}=this.sdk.sdkOptions,r=new Pi;for(let c of e)this.buildFetchPosFee(c,r);let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:N1("0x0")});n.error!=null&&Je("InvalidPoolObject",`fetch position fee error code: ${n.error??"unknown error"}, please check config and position and pool object ids`,{[Xi.METHOD_NAME]:"fetchPosFeeAmount"});let s=[],a=this.parsedPosFeeData(n);for(let c=0;c<e.length;c+=1){let p=a[e[c].position_id];if(p){let g={fee_owned_a:p.fee_owned_a,fee_owned_b:p.fee_owned_b,position_id:e[c].position_id};s.push(g)}}return s}async batchFetchPositionFees(e){let t=[];for(let r of e){let n=await this._sdk.Position.getPositionById(r,!1),s=await this._sdk.Pool.getPool(n.pool,!1);t.push({pool_id:s.id,position_id:n.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b})}let i={};if(t.length>0){let r=await this.fetchPosFeeAmount(t);for(let n of r)i[n.position_id]=n;return i}return i}async createAddLiquidityFixTokenPayload(e,t,i,r,n){let s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:a,is_adjust_coin_b:c}=ao(e);if(e=e,e.fix_amount_a&&a||!e.fix_amount_a&&c)return i=await ur.buildAddLiquidityFixTokenForGas(this._sdk,s,e,t,i,r,n),i}return ur.buildAddLiquidityFixToken(this._sdk,s,e,i,r,n)}async createAddLiquidityPayload(e,t,i,r){let{integrate:n,clmm_pool:s}=this._sdk.sdkOptions,a=Cr(BigInt(e.tick_lower)).toString(),c=Cr(BigInt(e.tick_upper)).toString(),p=[e.coin_type_a,e.coin_type_b];t=t||new Pi;let g=!x1(e.pos_id),v=BigInt(e.max_amount_a),y=BigInt(e.max_amount_b),A,k;if(i==null||r==null){let U=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());A=Yn.buildCoinForAmount(t,U,v,e.coin_type_a,!1,!0),k=Yn.buildCoinForAmount(t,U,y,e.coin_type_b,!1,!0)}else A={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},k={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(g)t.moveCall({target:`${n.published_at}::${Nr}::open_position_with_liquidity`,typeArguments:p,arguments:[t.object(xi(s).global_config_id),t.object(e.pool_id),t.pure.u32(Number(a)),t.pure.u32(Number(c)),A.target_coin,k.target_coin,t.pure.u64(e.max_amount_a),t.pure.u64(e.max_amount_b),t.pure.u128(e.delta_liquidity),t.object(Jn)]});else{let U=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,U,A.remain_coins,k.remain_coins),t.moveCall({target:`${n.published_at}::${Nr}::add_liquidity`,typeArguments:p,arguments:[t.object(xi(s).global_config_id),t.object(e.pool_id),t.object(e.pos_id),A.target_coin,k.target_coin,t.pure.u64(e.max_amount_a),t.pure.u64(e.max_amount_b),t.pure.u128(e.delta_liquidity),t.object(Jn)]})}return t}async removeLiquidityPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n="remove_liquidity";t=t||new Pi;let s=[e.coin_type_a,e.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,a);let c=[t.object(xi(i).global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.pure.u128(e.delta_liquidity),t.pure.u64(e.min_amount_a),t.pure.u64(e.min_amount_b),t.object(Jn)];return t.moveCall({target:`${r.published_at}::${Kn}::${n}`,typeArguments:s,arguments:c}),t}async closePositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new Pi;let n=[e.coin_type_a,e.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,s),t.moveCall({target:`${r.published_at}::${Kn}::close_position`,typeArguments:n,arguments:[t.object(xi(i).global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.pure.u64(e.min_amount_a),t.pure.u64(e.min_amount_b),t.object(Jn)]}),t}openPositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new Pi;let n=[e.coin_type_a,e.coin_type_b],s=Cr(BigInt(e.tick_lower)).toString(),a=Cr(BigInt(e.tick_upper)).toString(),c=[t.object(xi(i).global_config_id),t.object(e.pool_id),t.pure.u32(Number(s)),t.pure.u32(Number(a))];return t.moveCall({target:`${r.published_at}::${Kn}::open_position`,typeArguments:n,arguments:c}),t}async openPositionWithPricePayload(e,t){let{pool_id:i}=e,{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;t=t||new Pi;let s=await this.sdk.Pool.getPool(i,!1),a=Number(s.tick_spacing),c=0,p=0;if(e.is_full_range)c=Qn.getMinIndex(a),p=Qn.getMaxIndex(a);else{let{price_base_coin:y,min_price:A,max_price:k}=e;c=Er.priceToInitializeTickIndex(y==="coin_a"?Mi(A):Mi(1).div(k),e.coin_decimals_a,e.coin_decimals_b,a),p=Er.priceToInitializeTickIndex(y==="coin_a"?Mi(k):Mi(1).div(A),e.coin_decimals_a,e.coin_decimals_b,a)}let g=[s.coin_type_a,s.coin_type_b],v=[t.object(xi(r).global_config_id),t.object(e.pool_id),t.pure.u32(Number(Cr(BigInt(c)))),t.pure.u32(Number(Cr(BigInt(p))))];return t.moveCall({target:`${n.published_at}::${Kn}::open_position`,typeArguments:g,arguments:v}),t}async collectFeePayload(e,t,i,r){t=t||new Pi;let n=i||Yn.buildCoinWithBalance(BigInt(0),e.coin_type_a,t),s=r||Yn.buildCoinWithBalance(BigInt(0),e.coin_type_b,t);return this.createCollectFeePayload(e,t,n,s),t}createCollectFeePayload(e,t,i,r){let{clmm_pool:n,integrate:s}=this.sdk.sdkOptions,a=[e.coin_type_a,e.coin_type_b],c=[t.object(xi(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Nr}::collect_fee`,typeArguments:a,arguments:c}),t}async calculateAddLiquidityResultWithPrice(e){let{pool_id:t,slippage:i,refresh_pool_price:r,add_mode_params:n}=e,s=await this.sdk.Pool.getPool(t,r),a=Number(s.tick_spacing),c=0,p=0;if(n.is_full_range)c=Qn.getMinIndex(a),p=Qn.getMaxIndex(a);else{let{price_base_coin:W,min_price:j,max_price:K}=n;c=Er.priceToInitializeTickIndex(W==="coin_a"?Mi(j):Mi(1).div(K),n.coin_decimals_a,n.coin_decimals_b,a),p=Er.priceToInitializeTickIndex(W==="coin_a"?Mi(K):Mi(1).div(j),n.coin_decimals_a,n.coin_decimals_b,a)}if("liquidity"in e){let{liquidity:W}=e,j=Er.tickIndexToSqrtPriceX64(c),K=Er.tickIndexToSqrtPriceX64(p),{coin_amount_a:X,coin_amount_b:Q}=au.getCoinAmountFromLiquidity(new Xn.default(W),new Xn.default(s.current_sqrt_price),j,K,!1),se=Mi(X).mul(1+i).toFixed(0,St.ROUND_UP),Y=Mi(Q).mul(1+i).toFixed(0,St.ROUND_UP);return{coin_amount_a:X,coin_amount_b:Q,coin_amount_limit_a:se,coin_amount_limit_b:Y,liquidity:W,tick_lower:c,tick_upper:p}}let{coin_amount:g,fix_amount_a:v}=e,{coin_amount_limit_a:y,coin_amount_limit_b:A,liquidity_amount:k,coin_amount_a:U,coin_amount_b:P}=au.estLiquidityAndCoinAmountFromOneAmounts(c,p,new Xn.default(g),v,!0,i,new Xn.default(s.current_sqrt_price));return{coin_amount_a:U,coin_amount_b:P,coin_amount_limit_a:y,coin_amount_limit_b:A,liquidity:k,tick_lower:c,tick_upper:p,fix_amount_a:v}}async addLiquidityWithPricePayload(e,t,i,r){let{pool_id:n,calculate_result:s}=e,{coin_amount_limit_a:a,coin_amount_limit_b:c,liquidity:p,tick_lower:g,tick_upper:v}=s;t=t||new Pi;let y=await this.sdk.Pool.getPool(n,!1);return await this.createAddLiquidityPayload({delta_liquidity:p,max_amount_a:a,max_amount_b:c,tick_lower:g,tick_upper:v,collect_fee:!1,rewarder_coin_types:[],coin_type_a:y.coin_type_a,coin_type_b:y.coin_type_b,pool_id:n,pos_id:""},t,i,r),t}async createAddLiquidityFixCoinWithPricePayload(e,t,i,r){let{pool_id:n,calculate_result:s}=e,{coin_amount_limit_a:a,coin_amount_limit_b:c,liquidity:p,tick_lower:g,tick_upper:v,fix_amount_a:y,coin_amount_a:A,coin_amount_b:k}=s;if(y===void 0)throw Je("InvalidParams","fix_amount_a is undefined",{[Xi.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[Xi.REQUEST_PARAMS]:e});t=t||new Pi;let U=await this.sdk.Pool.getPool(n,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:y?A:a,amount_b:y?c:k,slippage:0,fix_amount_a:y,is_open:!0,tick_lower:g,tick_upper:v,collect_fee:!1,rewarder_coin_types:[],coin_type_a:U.coin_type_a,coin_type_b:U.coin_type_b,pool_id:n,pos_id:""},void 0,t,i,r),t}createCollectFeeNoSendPayload(e,t,i,r){let{clmm_pool:n,integrate:s}=this.sdk.sdkOptions,a=[e.coin_type_a,e.coin_type_b],c=[t.object(xi(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${xu}::collect_fee`,typeArguments:a,arguments:c}),t}},uu=Li(Fi()),j1=class{constructor(e){this._sdk=e,this.growthGlobal=[Ir,Ir,Ir]}get sdk(){return this._sdk}async emissionsEveryDay(e){let t=(await this.sdk.Pool.getPool(e)).rewarder_infos;if(!t)return null;let i=[];for(let r of t){let n=U1.fromX64(new uu.default(r.emissions_per_second));i.push({emissions:Math.floor(n.toNumber()*60*60*24),coin_type:r.coin_type})}return i}async batchFetchPositionRewarders(e){let t=[];for(let r of e){let n=await this._sdk.Position.getPositionById(r,!1),s=await this._sdk.Pool.getPool(n.pool,!1);t.push({pool_id:s.id,position_id:n.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b,rewarder_types:s.rewarder_infos.map(a=>a.coin_type)})}let i={};if(t.length>0){let r=await this.fetchPosRewardersAmount(t);for(let n of r)i[n.position_id]=n.rewarder_amounts;return i}return i}async fetchPositionRewarders(e,t){let i={pool_id:e.id,position_id:t,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,rewarder_types:e.rewarder_infos.map(r=>r.coin_type)};return(await this.fetchPosRewardersAmount([i]))[0].rewarder_amounts}async batchFetchPositionFees(e){return await this._sdk.Position.batchFetchPositionFees(e)}async fetchPosFeeAmount(e){return await this._sdk.Position.fetchPosFeeAmount(e)}buildFetchPosReward(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n=[e.coin_type_a,e.coin_type_b],s=[t.object(Is(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id),t.object(Cs)];t.moveCall({target:`${r.published_at}::${Lr}::fetch_position_rewards`,arguments:s,typeArguments:n})}async fetchPosRewardersAmount(e){let t=new Ss;for(let s of e)this.buildFetchPosReward(s,t);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:B1("0x")});i.error!=null&&Je("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[cu.METHOD_NAME]:"fetchPosRewardersAmount",[cu.REQUEST_PARAMS]:{params:e}});let r=this.parsedPosRewardData(i),n=[];for(let s=0;s<e.length;s+=1){let a=r[e[s].position_id];if(a){let c={pool_id:e[s].pool_id,position_id:e[s].position_id,rewarder_amounts:a.rewarder_amount.map((p,g)=>({amount_owned:p,coin_type:e[s].rewarder_types[g]}))};n.push(c)}}return n}parsedPosRewardData(e){let t={},i=e.events?.filter(r=>r.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let r=0;r<i.length;r+=1){let{parsedJson:n}=i[r],s={position_id:n.position_id,rewarder_amount:n.data};t[n.position_id]=s}return t}async fetchPoolRewardersAmount(e,t){let i=await this.sdk.Pool.getPool(t),r=await this.sdk.Position.getPositionList(e,[t]),n=[];for(let c of r)n.push({pool_id:i.id,position_id:c.pos_object_id,rewarder_types:i.rewarder_infos.map(p=>p.coin_type),coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b});let s=await this.fetchPosRewardersAmount(n),a=[Ir,Ir,Ir];if(s!=null)for(let c of s)for(let p=0;p<c.rewarder_amounts.length;p+=1)a[p]=a[p].add(new uu.default(c.rewarder_amounts[p].amount_owned));return a}async getPoolLowerAndUpperTicks(e,t){let i=[],r=[];for(let n of t){let s=await this.sdk.Pool.getTickDataByIndex(e,n.tick_lower_index),a=await this.sdk.Pool.getTickDataByIndex(e,n.tick_upper_index);i.push(s),r.push(a)}return[i,r]}async collectRewarderPayload(e){let t=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),i=new Ss;return i=ur.createCollectRewarderAndFeeParams(this._sdk,i,e,t),i}async batchCollectRewardsPayload(e,t,i,r){let n=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);t=t||new Ss;let s={};return e.forEach(a=>{let c=ks(a.coin_type_a),p=ks(a.coin_type_b);if(a.collect_fee){let v=s[c];v==null&&(i==null?v=Es.buildCoinForAmount(t,n,BigInt(0),c,!1):v={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[c]=v);let y=s[p];y==null&&(r==null?y=Es.buildCoinForAmount(t,n,BigInt(0),p,!1):y={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[p]=y),t=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:a.pool_id,pos_id:a.pos_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b},t,v.target_coin,y.target_coin)}let g=[];a.rewarder_coin_types.forEach(v=>{let y=ks(v),A=s[v];A===void 0&&(A=Es.buildCoinForAmount(t,n,BigInt(0),y,!1),s[y]=A),g.push(A.target_coin)}),t=this.createCollectRewarderNoSendPayload(a,t,g)}),Object.keys(s).forEach(a=>{let c=s[a];c.is_mint_zero_coin&&y1(this.sdk,t,c.target_coin,a,this.sdk.getSenderAddress())}),t}createCollectRewarderPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=Is(r),a=[e.coin_type_a,e.coin_type_b];return e.rewarder_coin_types.forEach((c,p)=>{t&&t.moveCall({target:`${n.published_at}::${Nr}::collect_reward`,typeArguments:[...a,c],arguments:[t.object(s.global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.object(s.global_vault_id),i[p],t.object(Cs)]})}),t}createCollectRewarderNoSendPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=Is(r),a=[e.coin_type_a,e.coin_type_b];return e.rewarder_coin_types.forEach((c,p)=>{t&&t.moveCall({target:`${n.published_at}::${xu}::collect_reward`,typeArguments:[...a,c],arguments:[t.object(s.global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.object(s.global_vault_id),i[p],t.object(Cs)]})}),t}},kr=Li(Fi());var H1=class{constructor(e){this.calculateSingleImpact=(t,i)=>i.minus(t).div(i).mul(100),this._sdk=e}get sdk(){return this._sdk}calculateSwapFee(e){let t=Tr(0);return e.forEach(i=>{let r=i.base_paths.length;if(r>0){let n=i.base_paths[0],s=n.label==="Cetus"?new St(n.fee_rate).div(10**6):new St(n.fee_rate).div(10**9),a=Tr(n.input_amount).div(10**n.from_decimal).mul(s);if(t=t.add(a),r>1){let c=i.base_paths[1],p=n.direction?n.current_price:new St(1).div(n.current_price),g=c.direction?c.current_price:new St(1).div(c.current_price),v=c.label==="Cetus"?new St(c.fee_rate).div(10**6):new St(c.fee_rate).div(10**9),y=Tr(c.output_amount).div(10**c.to_decimal).mul(v).div(p.mul(g));t=t.add(y)}}}),t.toString()}calculateSwapPriceImpact(e){let t=Tr(0);return e.forEach(i=>{let r=i.base_paths.length;if(r===1){let n=i.base_paths[0],s=Tr(n.output_amount).div(10**n.to_decimal),a=Tr(n.input_amount).div(10**n.from_decimal),c=s.div(a),p=n.direction?new St(n.current_price):new St(1).div(n.current_price);t=t.add(this.calculateSingleImpact(c,p))}if(r===2){let n=i.base_paths[0],s=i.base_paths[1],a=n.direction?new St(n.current_price):new St(1).div(n.current_price),c=s.direction?new St(s.current_price):new St(1).div(s.current_price),p=a.mul(c),g=new St(s.output_amount).div(10**s.to_decimal),v=new St(n.input_amount).div(10**n.from_decimal),y=g.div(v);t=t.add(this.calculateSingleImpact(y,p))}}),t.toString()}async preSwapWithMultiPool(e){let{integrate:t}=this.sdk.sdkOptions,i=new du,r=[e.coin_type_a,e.coin_type_b];for(let p=0;p<e.pool_ids.length;p+=1){let g=[i.object(e.pool_ids[p]),i.pure.bool(e.a2b),i.pure.bool(e.by_amount_in),i.pure.u64(e.amount)];i.moveCall({target:`${t.published_at}::${Lr}::calculate_swap_result`,arguments:g,typeArguments:r})}let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:hu("0x0")});n.error!=null&&Je("InvalidConfig",`pre swap with multi pools error code: ${n.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwapWithMultiPool",[Ji.REQUEST_PARAMS]:{params:e}});let s=n.events?.filter(p=>fu(p.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==e.pool_ids.length&&Je("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[Ji.METHOD_NAME]:"preSwapWithMultiPool",[Ji.REQUEST_PARAMS]:{params:e}});let a=e.by_amount_in?$1:q1,c=0;for(let p=0;p<s.length;p+=1)if(!s[p].parsedJson.data.is_exceed)if(e.by_amount_in){let g=new kr.default(s[p].parsedJson.data.amount_out);g.gt(a)&&(c=p,a=g)}else{let g=new kr.default(s[p].parsedJson.data.amount_out);g.lt(a)&&(c=p,a=g)}return this.transformSwapWithMultiPoolData({pool_address:e.pool_ids[c],a2b:e.a2b,by_amount_in:e.by_amount_in,amount:e.amount,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b},s[c].parsedJson)}async preSwap(e){let{integrate:t}=this.sdk.sdkOptions,i=new du,r=[e.coin_type_a,e.coin_type_b],n=[i.object(e.pool.id),i.pure.bool(e.a2b),i.pure.bool(e.by_amount_in),i.pure.u64(e.amount)];i.moveCall({target:`${t.published_at}::${Lr}::calculate_swap_result`,arguments:n,typeArguments:r});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:hu("0x0")});if(s.error!=null)return Je("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwap",[Ji.REQUEST_PARAMS]:{params:e}});let a=s.events?.filter(c=>fu(c.type).name==="CalculatedSwapResultEvent");return a.length===0?Je("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwap",[Ji.REQUEST_PARAMS]:{params:e}}):this.transformSwapData(e,a[0].parsedJson.data)}transformSwapData(e,t){let i=t.amount_in&&t.fee_amount?new kr.default(t.amount_in).add(new kr.default(t.fee_amount)).toString():"";return{pool_address:e.pool.id,current_sqrt_price:e.current_sqrt_price,estimated_amount_in:i,estimated_amount_out:t.amount_out,estimated_end_sqrt_price:t.after_sqrt_price,estimated_fee_amount:t.fee_amount,is_exceed:t.is_exceed,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in}}transformSwapWithMultiPoolData(e,t){let{data:i}=t;console.log("json data. ",i);let r=i.amount_in&&i.fee_amount?new kr.default(i.amount_in).add(new kr.default(i.fee_amount)).toString():"";return{pool_address:e.pool_address,estimated_amount_in:r,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.after_sqrt_price,estimated_start_sqrt_price:i.step_results[0].current_sqrt_price,estimated_fee_amount:i.fee_amount,is_exceed:i.is_exceed,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in}}calculateRates(e){let{current_pool:t}=e,i=u1(t),r;e.a2b?r=e.swap_ticks.sort((y,A)=>A.index-y.index):r=e.swap_ticks.sort((y,A)=>y.index-A.index);let n=d1(e.a2b,e.by_amount_in,e.amount,i,r),s=!1;e.by_amount_in?s=n.amount_in.lt(e.amount):s=n.amount_out.lt(e.amount);let a=Or.getDefaultSqrtPriceLimit(e.a2b);e.a2b&&n.next_sqrt_price.lt(a)&&(s=!0),!e.a2b&&n.next_sqrt_price.gt(a)&&(s=!0);let c=0;n.cross_tick_num>6&&n.cross_tick_num<40&&(c=22e3*(n.cross_tick_num-6)),n.cross_tick_num>40&&(s=!0);let p=pu.sqrtPriceX64ToPrice(i.current_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),g=pu.sqrtPriceX64ToPrice(n.next_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),v=Math.abs(p-g)/p*100;return{estimated_amount_in:n.amount_in,estimated_amount_out:n.amount_out,estimated_end_sqrt_price:n.next_sqrt_price,estimated_fee_amount:n.fee_amount,is_exceed:s,extra_compute_limit:c,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in,price_impact_pct:v}}async createSwapPayload(e,t){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:r,is_adjust_coin_b:n}=ao(e);if(e.a2b&&r||!e.a2b&&n)return await Or.buildSwapTransactionForGas(this._sdk,e,i,t)}return Or.buildSwapTransaction(this.sdk,e,i)}async createSwapWithoutTransferCoinsPayload(e,t){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:r,is_adjust_coin_b:n}=ao(e);if(e.a2b&&r||!e.a2b&&n)return await Or.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,e,i,t)}return Or.buildSwapTransactionWithoutTransferCoins(this.sdk,e,i)}},K1=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getClmmVestInfoList(){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"getClmmVestInfo"});let t=[];try{let i=`${e.package_id}::clmm_vester::CreateEvent`,r=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:i})).data.map(n=>n.parsedJson.clmm_vester_id);return r.length>0&&(await this._sdk.FullClient.batchGetObjects(r,{showContent:!0,showType:!0})).forEach(n=>{let s=Rr.parseClmmVestInfo(n),a=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(a,s),t.push(s)}),t}catch(i){Ri("ClmmVestFetchError",i,{[ar.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(e=!0){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=Ts(t),r=`${i}-ClmmVestInfo`,n=this._sdk.getCache(r,e);if(n)return n;try{let s=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0,showType:!0}}),a=Rr.parseClmmVestInfo(s);return this._sdk.updateCache(r,a),a}catch(s){return Ri("ClmmVestFetchError",s,{[ar.METHOD_NAME]:"getClmmVestInfo",[ar.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(e){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"getPositionVesting"});if(e.length===0)return[];let{clmm_vest_id:i}=Ts(t),r=new mu;e.forEach(a=>{let{clmm_pool_id:c,coin_type_a:p,coin_type_b:g,clmm_position_ids:v}=a;r.moveCall({package:t.published_at,module:"clmm_vester",function:"get_positions_vesting",typeArguments:[p,g],arguments:[r.object(i),r.object(c),r.pure.vector("id",v)]})});let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:Z1("0x0")}),s=[];return n.events?.forEach(a=>{if(a.type.includes("clmm_vester::GetPositionsVestingEvent")){let{parsedJson:c}=a;s.push(...c.position_vestings.map(p=>Rr.parsePositionVesting(p)))}}),s}buildRedeemPayload(e,t){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:r,clmm_vest_id:n,cetus_coin_type:s}=Ts(i);return t=t||new mu,e.forEach(a=>{let{clmm_pool_id:c,clmm_position_id:p,coin_type_a:g,coin_type_b:v,period:y}=a,A=t.moveCall({package:i.published_at,module:"clmm_vester",function:"redeem",arguments:[t.object(r),t.object(n),t.object(c),typeof p=="string"?t.object(p):p,t.pure.u16(y),t.object(G1)],typeArguments:[g,v]}),k=V1.fromBalance(A,s,t);t.transferObjects([k],this._sdk.getSenderAddress())}),t}},gu={clmmConfig:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"},cetusConfig:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},z1={env:"mainnet",full_rpc_url:W1,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:gu.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:gu.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d",version:12},stats_pools_url:"https://api-sui.cetus.zone/v2/sui/stats_pools",clmm_vest:{package_id:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",published_at:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",version:1,config:{clmm_vest_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",versioned_id:"0x4f6f2f638362505836114f313809b834dafd58e3910df5110f6e54e4e35c929b",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"}}},J1={env:"testnet",full_rpc_url:X1,cetus_config:{package_id:"0x2933975c3f74ef7c31f512edead6c6ce3f58f8e8fdbea78770ec8d5abd8ff700",published_at:"0xb50a626294f743b40ea51c9cb75190f0e38c71f580981b5613aef910b67a2691",config:{coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"0x774656a83f4f625fcc4e4dbf103eb77caf2d8b8f114ad33f55b848be068267b9",global_config_id:"0x95275a022123c66682278e9df6b5bac4da9abcc29ab698b7b2a6213262a592fe",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""}},clmm_pool:{package_id:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",published_at:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",config:{pools_id:"0x20a086e6fa0741b3ca77d033a65faf0871349b986ddbdde6fa1d85d78a5f4222",global_config_id:"0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a",global_vault_id:"0x71e74a999dd7959e483f758ddf573e85fa4c24944db33ff6763c9d85a9c045fe",admin_cap_id:"0xbf4c48590f403c38351de0e8aa13d6d91bf78fd8c04e93ac1d0269c44d70ae02",partners_id:"0xb5ae5ed3f403654ae1307aadc0140f746db41efb7bda92235257c84d90a1397e"}},integrate:{package_id:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",published_at:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",version:1},stats_pools_url:"https://api-sui.devcetus.com/v2/sui/stats_pools",clmm_vest:{package_id:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",published_at:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",config:{clmm_vest_id:"0x308b24963e5992f699e32db2f7088b812566a0cae580317fd3b8bf61de7f5508",versioned_id:"0x1cfb684d8ff581416a56caba2aa419bee45fe98a23cbf28e2c6c1021b14cab7c",cetus_coin_type:"0xc6c51938da9a5cf6d6dca692783ea7bdf4478f7b1fef693f58947848f84bcf89::cetus::CETUS"}}},Zu=class ro extends Ap{constructor(t){super(t),this._swap=new H1(this),this._pool=new O1(this),this._position=new D1(this),this._config=new zp(this),this._rewarder=new j1(this),this._vest=new K1(this)}get Pool(){return this._pool}get Position(){return this._position}get CetusConfig(){return this._config}get Rewarder(){return this._rewarder}get Swap(){return this._swap}get Vest(){return this._vest}static createSDK(t){let{env:i="mainnet"}=t;return i==="mainnet"?ro.createCustomSDK({...z1,...t}):ro.createCustomSDK({...J1,...t})}static createCustomSDK(t){return new ro(t)}},fo=Li(Fi()),uv=new fo.default(365),cv=new fo.default(24),dv=new fo.default(3600),hv=new fo.default(.5);import{SuiPriceServiceConnection as tg}from"@pythnetwork/pyth-sui-js";var po=class e extends Y1{constructor(t,i){super(t),this._suilendModule=new un(this),this._leverageModules=new vn(this),this._aggregatorClient=new rn.AggregatorClient({signer:Q1("0x0"),client:t.sui_client||new eg({url:t.full_rpc_url}),env:t.env==="testnet"?rn.Env.Testnet:rn.Env.Mainnet,pythUrls:t.pyth_urls}),this._clmmSDK=i||Zu.createSDK({env:t.env,full_rpc_url:t.full_rpc_url}),this._pythConnection=new tg("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(t){return e.createCustomSDK({...Vs,...t})}static createCustomSDK(t){return new e(t)}};var Lv=po;export{po as CetusLeverageSDK,Lv as default,Vs as leverage_mainnet};
1
+ var GT=Object.create;var p_=Object.defineProperty;var HT=Object.getOwnPropertyDescriptor;var WT=Object.getOwnPropertyNames;var KT=Object.getPrototypeOf,XT=Object.prototype.hasOwnProperty;var xr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var be=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var JT=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of WT(e))!XT.call(t,i)&&i!==r&&p_(t,i,{get:()=>e[i],enumerable:!(n=HT(e,i))||n.enumerable});return t};var m_=(t,e,r)=>(r=t!=null?GT(KT(t)):{},JT(e||!t||!t.__esModule?p_(r,"default",{value:t,enumerable:!0}):r,t));var xv=be((Tv,Kh)=>{"use strict";(function(t,e){"use strict";function r(k,m){if(!k)throw new Error(m||"Assertion failed")}function n(k,m){k.super_=m;var a=function(){};a.prototype=m.prototype,k.prototype=new a,k.prototype.constructor=k}function i(k,m,a){if(i.isBN(k))return k;this.negative=0,this.words=null,this.length=0,this.red=null,k!==null&&((m==="le"||m==="be")&&(a=m,m=10),this._init(k||0,m||10,a||"be"))}typeof t=="object"?t.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=xr("buffer").Buffer}catch{}i.isBN=function(m){return m instanceof i?!0:m!==null&&typeof m=="object"&&m.constructor.wordSize===i.wordSize&&Array.isArray(m.words)},i.max=function(m,a){return m.cmp(a)>0?m:a},i.min=function(m,a){return m.cmp(a)<0?m:a},i.prototype._init=function(m,a,l){if(typeof m=="number")return this._initNumber(m,a,l);if(typeof m=="object")return this._initArray(m,a,l);a==="hex"&&(a=16),r(a===(a|0)&&a>=2&&a<=36),m=m.toString().replace(/\s+/g,"");var h=0;m[0]==="-"&&(h++,this.negative=1),h<m.length&&(a===16?this._parseHex(m,h,l):(this._parseBase(m,a,h),l==="le"&&this._initArray(this.toArray(),a,l)))},i.prototype._initNumber=function(m,a,l){m<0&&(this.negative=1,m=-m),m<67108864?(this.words=[m&67108863],this.length=1):m<4503599627370496?(this.words=[m&67108863,m/67108864&67108863],this.length=2):(r(m<9007199254740992),this.words=[m&67108863,m/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),a,l)},i.prototype._initArray=function(m,a,l){if(r(typeof m.length=="number"),m.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(m.length/3),this.words=new Array(this.length);for(var h=0;h<this.length;h++)this.words[h]=0;var y,v,M=0;if(l==="be")for(h=m.length-1,y=0;h>=0;h-=3)v=m[h]|m[h-1]<<8|m[h-2]<<16,this.words[y]|=v<<M&67108863,this.words[y+1]=v>>>26-M&67108863,M+=24,M>=26&&(M-=26,y++);else if(l==="le")for(h=0,y=0;h<m.length;h+=3)v=m[h]|m[h+1]<<8|m[h+2]<<16,this.words[y]|=v<<M&67108863,this.words[y+1]=v>>>26-M&67108863,M+=24,M>=26&&(M-=26,y++);return this._strip()};function o(k,m){var a=k.charCodeAt(m);if(a>=48&&a<=57)return a-48;if(a>=65&&a<=70)return a-55;if(a>=97&&a<=102)return a-87;r(!1,"Invalid character in "+k)}function u(k,m,a){var l=o(k,a);return a-1>=m&&(l|=o(k,a-1)<<4),l}i.prototype._parseHex=function(m,a,l){this.length=Math.ceil((m.length-a)/6),this.words=new Array(this.length);for(var h=0;h<this.length;h++)this.words[h]=0;var y=0,v=0,M;if(l==="be")for(h=m.length-1;h>=a;h-=2)M=u(m,a,h)<<y,this.words[v]|=M&67108863,y>=18?(y-=18,v+=1,this.words[v]|=M>>>26):y+=8;else{var w=m.length-a;for(h=w%2===0?a+1:a;h<m.length;h+=2)M=u(m,a,h)<<y,this.words[v]|=M&67108863,y>=18?(y-=18,v+=1,this.words[v]|=M>>>26):y+=8}this._strip()};function c(k,m,a,l){for(var h=0,y=0,v=Math.min(k.length,a),M=m;M<v;M++){var w=k.charCodeAt(M)-48;h*=l,w>=49?y=w-49+10:w>=17?y=w-17+10:y=w,r(w>=0&&y<l,"Invalid character"),h+=y}return h}i.prototype._parseBase=function(m,a,l){this.words=[0],this.length=1;for(var h=0,y=1;y<=67108863;y*=a)h++;h--,y=y/a|0;for(var v=m.length-l,M=v%h,w=Math.min(v,v-M)+l,g=0,f=l;f<w;f+=h)g=c(m,f,f+h,a),this.imuln(y),this.words[0]+g<67108864?this.words[0]+=g:this._iaddn(g);if(M!==0){var S=1;for(g=c(m,f,m.length,a),f=0;f<M;f++)S*=a;this.imuln(S),this.words[0]+g<67108864?this.words[0]+=g:this._iaddn(g)}this._strip()},i.prototype.copy=function(m){m.words=new Array(this.length);for(var a=0;a<this.length;a++)m.words[a]=this.words[a];m.length=this.length,m.negative=this.negative,m.red=this.red};function d(k,m){k.words=m.words,k.length=m.length,k.negative=m.negative,k.red=m.red}if(i.prototype._move=function(m){d(m,this)},i.prototype.clone=function(){var m=new i(null);return this.copy(m),m},i.prototype._expand=function(m){for(;this.length<m;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=p}catch{i.prototype.inspect=p}else i.prototype.inspect=p;function p(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var _=["","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"],b=[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],O=[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];i.prototype.toString=function(m,a){m=m||10,a=a|0||1;var l;if(m===16||m==="hex"){l="";for(var h=0,y=0,v=0;v<this.length;v++){var M=this.words[v],w=((M<<h|y)&16777215).toString(16);y=M>>>24-h&16777215,h+=2,h>=26&&(h-=26,v--),y!==0||v!==this.length-1?l=_[6-w.length]+w+l:l=w+l}for(y!==0&&(l=y.toString(16)+l);l.length%a!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(m===(m|0)&&m>=2&&m<=36){var g=b[m],f=O[m];l="";var S=this.clone();for(S.negative=0;!S.isZero();){var V=S.modrn(f).toString(m);S=S.idivn(f),S.isZero()?l=V+l:l=_[g-V.length]+V+l}for(this.isZero()&&(l="0"+l);l.length%a!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var m=this.words[0];return this.length===2?m+=this.words[1]*67108864:this.length===3&&this.words[2]===1?m+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-m:m},i.prototype.toJSON=function(){return this.toString(16,2)},s&&(i.prototype.toBuffer=function(m,a){return this.toArrayLike(s,m,a)}),i.prototype.toArray=function(m,a){return this.toArrayLike(Array,m,a)};var T=function(m,a){return m.allocUnsafe?m.allocUnsafe(a):new m(a)};i.prototype.toArrayLike=function(m,a,l){this._strip();var h=this.byteLength(),y=l||Math.max(1,h);r(h<=y,"byte array longer than desired length"),r(y>0,"Requested array length <= 0");var v=T(m,y),M=a==="le"?"LE":"BE";return this["_toArrayLike"+M](v,h),v},i.prototype._toArrayLikeLE=function(m,a){for(var l=0,h=0,y=0,v=0;y<this.length;y++){var M=this.words[y]<<v|h;m[l++]=M&255,l<m.length&&(m[l++]=M>>8&255),l<m.length&&(m[l++]=M>>16&255),v===6?(l<m.length&&(m[l++]=M>>24&255),h=0,v=0):(h=M>>>24,v+=2)}if(l<m.length)for(m[l++]=h;l<m.length;)m[l++]=0},i.prototype._toArrayLikeBE=function(m,a){for(var l=m.length-1,h=0,y=0,v=0;y<this.length;y++){var M=this.words[y]<<v|h;m[l--]=M&255,l>=0&&(m[l--]=M>>8&255),l>=0&&(m[l--]=M>>16&255),v===6?(l>=0&&(m[l--]=M>>24&255),h=0,v=0):(h=M>>>24,v+=2)}if(l>=0)for(m[l--]=h;l>=0;)m[l--]=0},Math.clz32?i.prototype._countBits=function(m){return 32-Math.clz32(m)}:i.prototype._countBits=function(m){var a=m,l=0;return a>=4096&&(l+=13,a>>>=13),a>=64&&(l+=7,a>>>=7),a>=8&&(l+=4,a>>>=4),a>=2&&(l+=2,a>>>=2),l+a},i.prototype._zeroBits=function(m){if(m===0)return 26;var a=m,l=0;return(a&8191)===0&&(l+=13,a>>>=13),(a&127)===0&&(l+=7,a>>>=7),(a&15)===0&&(l+=4,a>>>=4),(a&3)===0&&(l+=2,a>>>=2),(a&1)===0&&l++,l},i.prototype.bitLength=function(){var m=this.words[this.length-1],a=this._countBits(m);return(this.length-1)*26+a};function x(k){for(var m=new Array(k.bitLength()),a=0;a<m.length;a++){var l=a/26|0,h=a%26;m[a]=k.words[l]>>>h&1}return m}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var m=0,a=0;a<this.length;a++){var l=this._zeroBits(this.words[a]);if(m+=l,l!==26)break}return m},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(m){return this.negative!==0?this.abs().inotn(m).iaddn(1):this.clone()},i.prototype.fromTwos=function(m){return this.testn(m-1)?this.notn(m).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(m){for(;this.length<m.length;)this.words[this.length++]=0;for(var a=0;a<m.length;a++)this.words[a]=this.words[a]|m.words[a];return this._strip()},i.prototype.ior=function(m){return r((this.negative|m.negative)===0),this.iuor(m)},i.prototype.or=function(m){return this.length>m.length?this.clone().ior(m):m.clone().ior(this)},i.prototype.uor=function(m){return this.length>m.length?this.clone().iuor(m):m.clone().iuor(this)},i.prototype.iuand=function(m){var a;this.length>m.length?a=m:a=this;for(var l=0;l<a.length;l++)this.words[l]=this.words[l]&m.words[l];return this.length=a.length,this._strip()},i.prototype.iand=function(m){return r((this.negative|m.negative)===0),this.iuand(m)},i.prototype.and=function(m){return this.length>m.length?this.clone().iand(m):m.clone().iand(this)},i.prototype.uand=function(m){return this.length>m.length?this.clone().iuand(m):m.clone().iuand(this)},i.prototype.iuxor=function(m){var a,l;this.length>m.length?(a=this,l=m):(a=m,l=this);for(var h=0;h<l.length;h++)this.words[h]=a.words[h]^l.words[h];if(this!==a)for(;h<a.length;h++)this.words[h]=a.words[h];return this.length=a.length,this._strip()},i.prototype.ixor=function(m){return r((this.negative|m.negative)===0),this.iuxor(m)},i.prototype.xor=function(m){return this.length>m.length?this.clone().ixor(m):m.clone().ixor(this)},i.prototype.uxor=function(m){return this.length>m.length?this.clone().iuxor(m):m.clone().iuxor(this)},i.prototype.inotn=function(m){r(typeof m=="number"&&m>=0);var a=Math.ceil(m/26)|0,l=m%26;this._expand(a),l>0&&a--;for(var h=0;h<a;h++)this.words[h]=~this.words[h]&67108863;return l>0&&(this.words[h]=~this.words[h]&67108863>>26-l),this._strip()},i.prototype.notn=function(m){return this.clone().inotn(m)},i.prototype.setn=function(m,a){r(typeof m=="number"&&m>=0);var l=m/26|0,h=m%26;return this._expand(l+1),a?this.words[l]=this.words[l]|1<<h:this.words[l]=this.words[l]&~(1<<h),this._strip()},i.prototype.iadd=function(m){var a;if(this.negative!==0&&m.negative===0)return this.negative=0,a=this.isub(m),this.negative^=1,this._normSign();if(this.negative===0&&m.negative!==0)return m.negative=0,a=this.isub(m),m.negative=1,a._normSign();var l,h;this.length>m.length?(l=this,h=m):(l=m,h=this);for(var y=0,v=0;v<h.length;v++)a=(l.words[v]|0)+(h.words[v]|0)+y,this.words[v]=a&67108863,y=a>>>26;for(;y!==0&&v<l.length;v++)a=(l.words[v]|0)+y,this.words[v]=a&67108863,y=a>>>26;if(this.length=l.length,y!==0)this.words[this.length]=y,this.length++;else if(l!==this)for(;v<l.length;v++)this.words[v]=l.words[v];return this},i.prototype.add=function(m){var a;return m.negative!==0&&this.negative===0?(m.negative=0,a=this.sub(m),m.negative^=1,a):m.negative===0&&this.negative!==0?(this.negative=0,a=m.sub(this),this.negative=1,a):this.length>m.length?this.clone().iadd(m):m.clone().iadd(this)},i.prototype.isub=function(m){if(m.negative!==0){m.negative=0;var a=this.iadd(m);return m.negative=1,a._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(m),this.negative=1,this._normSign();var l=this.cmp(m);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var h,y;l>0?(h=this,y=m):(h=m,y=this);for(var v=0,M=0;M<y.length;M++)a=(h.words[M]|0)-(y.words[M]|0)+v,v=a>>26,this.words[M]=a&67108863;for(;v!==0&&M<h.length;M++)a=(h.words[M]|0)+v,v=a>>26,this.words[M]=a&67108863;if(v===0&&M<h.length&&h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];return this.length=Math.max(this.length,M),h!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(m){return this.clone().isub(m)};function F(k,m,a){a.negative=m.negative^k.negative;var l=k.length+m.length|0;a.length=l,l=l-1|0;var h=k.words[0]|0,y=m.words[0]|0,v=h*y,M=v&67108863,w=v/67108864|0;a.words[0]=M;for(var g=1;g<l;g++){for(var f=w>>>26,S=w&67108863,V=Math.min(g,m.length-1),z=Math.max(0,g-k.length+1);z<=V;z++){var Z=g-z|0;h=k.words[Z]|0,y=m.words[z]|0,v=h*y+S,f+=v/67108864|0,S=v&67108863}a.words[g]=S|0,w=f|0}return w!==0?a.words[g]=w|0:a.length--,a._strip()}var R=function(m,a,l){var h=m.words,y=a.words,v=l.words,M=0,w,g,f,S=h[0]|0,V=S&8191,z=S>>>13,Z=h[1]|0,ce=Z&8191,E=Z>>>13,P=h[2]|0,j=P&8191,L=P>>>13,U=h[3]|0,W=U&8191,q=U>>>13,$=h[4]|0,X=$&8191,G=$>>>13,K=h[5]|0,ie=K&8191,oe=K>>>13,pe=h[6]|0,Fe=pe&8191,_e=pe>>>13,Ie=h[7]|0,Le=Ie&8191,me=Ie>>>13,Ue=h[8]|0,It=Ue&8191,Ee=Ue>>>13,tt=h[9]|0,kt=tt&8191,Oe=tt>>>13,Ve=y[0]|0,wt=Ve&8191,ve=Ve>>>13,lt=y[1]|0,Rt=lt&8191,Te=lt>>>13,ft=y[2]|0,Ut=ft&8191,xe=ft>>>13,dt=y[3]|0,Lt=dt&8191,Pe=dt>>>13,ht=y[4]|0,$t=ht&8191,Ce=ht>>>13,pt=y[5]|0,Ft=pt&8191,je=pt>>>13,mt=y[6]|0,qt=mt&8191,Ne=mt>>>13,gt=y[7]|0,Vt=gt&8191,De=gt>>>13,yt=y[8]|0,zt=yt&8191,Be=yt>>>13,_t=y[9]|0,Gt=_t&8191,Re=_t>>>13;l.negative=m.negative^a.negative,l.length=19,w=Math.imul(V,wt),g=Math.imul(V,ve),g=g+Math.imul(z,wt)|0,f=Math.imul(z,ve);var ct=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ct>>>26)|0,ct&=67108863,w=Math.imul(ce,wt),g=Math.imul(ce,ve),g=g+Math.imul(E,wt)|0,f=Math.imul(E,ve),w=w+Math.imul(V,Rt)|0,g=g+Math.imul(V,Te)|0,g=g+Math.imul(z,Rt)|0,f=f+Math.imul(z,Te)|0;var zn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(zn>>>26)|0,zn&=67108863,w=Math.imul(j,wt),g=Math.imul(j,ve),g=g+Math.imul(L,wt)|0,f=Math.imul(L,ve),w=w+Math.imul(ce,Rt)|0,g=g+Math.imul(ce,Te)|0,g=g+Math.imul(E,Rt)|0,f=f+Math.imul(E,Te)|0,w=w+Math.imul(V,Ut)|0,g=g+Math.imul(V,xe)|0,g=g+Math.imul(z,Ut)|0,f=f+Math.imul(z,xe)|0;var Gn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Gn>>>26)|0,Gn&=67108863,w=Math.imul(W,wt),g=Math.imul(W,ve),g=g+Math.imul(q,wt)|0,f=Math.imul(q,ve),w=w+Math.imul(j,Rt)|0,g=g+Math.imul(j,Te)|0,g=g+Math.imul(L,Rt)|0,f=f+Math.imul(L,Te)|0,w=w+Math.imul(ce,Ut)|0,g=g+Math.imul(ce,xe)|0,g=g+Math.imul(E,Ut)|0,f=f+Math.imul(E,xe)|0,w=w+Math.imul(V,Lt)|0,g=g+Math.imul(V,Pe)|0,g=g+Math.imul(z,Lt)|0,f=f+Math.imul(z,Pe)|0;var Hn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Hn>>>26)|0,Hn&=67108863,w=Math.imul(X,wt),g=Math.imul(X,ve),g=g+Math.imul(G,wt)|0,f=Math.imul(G,ve),w=w+Math.imul(W,Rt)|0,g=g+Math.imul(W,Te)|0,g=g+Math.imul(q,Rt)|0,f=f+Math.imul(q,Te)|0,w=w+Math.imul(j,Ut)|0,g=g+Math.imul(j,xe)|0,g=g+Math.imul(L,Ut)|0,f=f+Math.imul(L,xe)|0,w=w+Math.imul(ce,Lt)|0,g=g+Math.imul(ce,Pe)|0,g=g+Math.imul(E,Lt)|0,f=f+Math.imul(E,Pe)|0,w=w+Math.imul(V,$t)|0,g=g+Math.imul(V,Ce)|0,g=g+Math.imul(z,$t)|0,f=f+Math.imul(z,Ce)|0;var Wn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Wn>>>26)|0,Wn&=67108863,w=Math.imul(ie,wt),g=Math.imul(ie,ve),g=g+Math.imul(oe,wt)|0,f=Math.imul(oe,ve),w=w+Math.imul(X,Rt)|0,g=g+Math.imul(X,Te)|0,g=g+Math.imul(G,Rt)|0,f=f+Math.imul(G,Te)|0,w=w+Math.imul(W,Ut)|0,g=g+Math.imul(W,xe)|0,g=g+Math.imul(q,Ut)|0,f=f+Math.imul(q,xe)|0,w=w+Math.imul(j,Lt)|0,g=g+Math.imul(j,Pe)|0,g=g+Math.imul(L,Lt)|0,f=f+Math.imul(L,Pe)|0,w=w+Math.imul(ce,$t)|0,g=g+Math.imul(ce,Ce)|0,g=g+Math.imul(E,$t)|0,f=f+Math.imul(E,Ce)|0,w=w+Math.imul(V,Ft)|0,g=g+Math.imul(V,je)|0,g=g+Math.imul(z,Ft)|0,f=f+Math.imul(z,je)|0;var Kn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Kn>>>26)|0,Kn&=67108863,w=Math.imul(Fe,wt),g=Math.imul(Fe,ve),g=g+Math.imul(_e,wt)|0,f=Math.imul(_e,ve),w=w+Math.imul(ie,Rt)|0,g=g+Math.imul(ie,Te)|0,g=g+Math.imul(oe,Rt)|0,f=f+Math.imul(oe,Te)|0,w=w+Math.imul(X,Ut)|0,g=g+Math.imul(X,xe)|0,g=g+Math.imul(G,Ut)|0,f=f+Math.imul(G,xe)|0,w=w+Math.imul(W,Lt)|0,g=g+Math.imul(W,Pe)|0,g=g+Math.imul(q,Lt)|0,f=f+Math.imul(q,Pe)|0,w=w+Math.imul(j,$t)|0,g=g+Math.imul(j,Ce)|0,g=g+Math.imul(L,$t)|0,f=f+Math.imul(L,Ce)|0,w=w+Math.imul(ce,Ft)|0,g=g+Math.imul(ce,je)|0,g=g+Math.imul(E,Ft)|0,f=f+Math.imul(E,je)|0,w=w+Math.imul(V,qt)|0,g=g+Math.imul(V,Ne)|0,g=g+Math.imul(z,qt)|0,f=f+Math.imul(z,Ne)|0;var Xn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Xn>>>26)|0,Xn&=67108863,w=Math.imul(Le,wt),g=Math.imul(Le,ve),g=g+Math.imul(me,wt)|0,f=Math.imul(me,ve),w=w+Math.imul(Fe,Rt)|0,g=g+Math.imul(Fe,Te)|0,g=g+Math.imul(_e,Rt)|0,f=f+Math.imul(_e,Te)|0,w=w+Math.imul(ie,Ut)|0,g=g+Math.imul(ie,xe)|0,g=g+Math.imul(oe,Ut)|0,f=f+Math.imul(oe,xe)|0,w=w+Math.imul(X,Lt)|0,g=g+Math.imul(X,Pe)|0,g=g+Math.imul(G,Lt)|0,f=f+Math.imul(G,Pe)|0,w=w+Math.imul(W,$t)|0,g=g+Math.imul(W,Ce)|0,g=g+Math.imul(q,$t)|0,f=f+Math.imul(q,Ce)|0,w=w+Math.imul(j,Ft)|0,g=g+Math.imul(j,je)|0,g=g+Math.imul(L,Ft)|0,f=f+Math.imul(L,je)|0,w=w+Math.imul(ce,qt)|0,g=g+Math.imul(ce,Ne)|0,g=g+Math.imul(E,qt)|0,f=f+Math.imul(E,Ne)|0,w=w+Math.imul(V,Vt)|0,g=g+Math.imul(V,De)|0,g=g+Math.imul(z,Vt)|0,f=f+Math.imul(z,De)|0;var Jn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Jn>>>26)|0,Jn&=67108863,w=Math.imul(It,wt),g=Math.imul(It,ve),g=g+Math.imul(Ee,wt)|0,f=Math.imul(Ee,ve),w=w+Math.imul(Le,Rt)|0,g=g+Math.imul(Le,Te)|0,g=g+Math.imul(me,Rt)|0,f=f+Math.imul(me,Te)|0,w=w+Math.imul(Fe,Ut)|0,g=g+Math.imul(Fe,xe)|0,g=g+Math.imul(_e,Ut)|0,f=f+Math.imul(_e,xe)|0,w=w+Math.imul(ie,Lt)|0,g=g+Math.imul(ie,Pe)|0,g=g+Math.imul(oe,Lt)|0,f=f+Math.imul(oe,Pe)|0,w=w+Math.imul(X,$t)|0,g=g+Math.imul(X,Ce)|0,g=g+Math.imul(G,$t)|0,f=f+Math.imul(G,Ce)|0,w=w+Math.imul(W,Ft)|0,g=g+Math.imul(W,je)|0,g=g+Math.imul(q,Ft)|0,f=f+Math.imul(q,je)|0,w=w+Math.imul(j,qt)|0,g=g+Math.imul(j,Ne)|0,g=g+Math.imul(L,qt)|0,f=f+Math.imul(L,Ne)|0,w=w+Math.imul(ce,Vt)|0,g=g+Math.imul(ce,De)|0,g=g+Math.imul(E,Vt)|0,f=f+Math.imul(E,De)|0,w=w+Math.imul(V,zt)|0,g=g+Math.imul(V,Be)|0,g=g+Math.imul(z,zt)|0,f=f+Math.imul(z,Be)|0;var Zn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,w=Math.imul(kt,wt),g=Math.imul(kt,ve),g=g+Math.imul(Oe,wt)|0,f=Math.imul(Oe,ve),w=w+Math.imul(It,Rt)|0,g=g+Math.imul(It,Te)|0,g=g+Math.imul(Ee,Rt)|0,f=f+Math.imul(Ee,Te)|0,w=w+Math.imul(Le,Ut)|0,g=g+Math.imul(Le,xe)|0,g=g+Math.imul(me,Ut)|0,f=f+Math.imul(me,xe)|0,w=w+Math.imul(Fe,Lt)|0,g=g+Math.imul(Fe,Pe)|0,g=g+Math.imul(_e,Lt)|0,f=f+Math.imul(_e,Pe)|0,w=w+Math.imul(ie,$t)|0,g=g+Math.imul(ie,Ce)|0,g=g+Math.imul(oe,$t)|0,f=f+Math.imul(oe,Ce)|0,w=w+Math.imul(X,Ft)|0,g=g+Math.imul(X,je)|0,g=g+Math.imul(G,Ft)|0,f=f+Math.imul(G,je)|0,w=w+Math.imul(W,qt)|0,g=g+Math.imul(W,Ne)|0,g=g+Math.imul(q,qt)|0,f=f+Math.imul(q,Ne)|0,w=w+Math.imul(j,Vt)|0,g=g+Math.imul(j,De)|0,g=g+Math.imul(L,Vt)|0,f=f+Math.imul(L,De)|0,w=w+Math.imul(ce,zt)|0,g=g+Math.imul(ce,Be)|0,g=g+Math.imul(E,zt)|0,f=f+Math.imul(E,Be)|0,w=w+Math.imul(V,Gt)|0,g=g+Math.imul(V,Re)|0,g=g+Math.imul(z,Gt)|0,f=f+Math.imul(z,Re)|0;var Yn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,w=Math.imul(kt,Rt),g=Math.imul(kt,Te),g=g+Math.imul(Oe,Rt)|0,f=Math.imul(Oe,Te),w=w+Math.imul(It,Ut)|0,g=g+Math.imul(It,xe)|0,g=g+Math.imul(Ee,Ut)|0,f=f+Math.imul(Ee,xe)|0,w=w+Math.imul(Le,Lt)|0,g=g+Math.imul(Le,Pe)|0,g=g+Math.imul(me,Lt)|0,f=f+Math.imul(me,Pe)|0,w=w+Math.imul(Fe,$t)|0,g=g+Math.imul(Fe,Ce)|0,g=g+Math.imul(_e,$t)|0,f=f+Math.imul(_e,Ce)|0,w=w+Math.imul(ie,Ft)|0,g=g+Math.imul(ie,je)|0,g=g+Math.imul(oe,Ft)|0,f=f+Math.imul(oe,je)|0,w=w+Math.imul(X,qt)|0,g=g+Math.imul(X,Ne)|0,g=g+Math.imul(G,qt)|0,f=f+Math.imul(G,Ne)|0,w=w+Math.imul(W,Vt)|0,g=g+Math.imul(W,De)|0,g=g+Math.imul(q,Vt)|0,f=f+Math.imul(q,De)|0,w=w+Math.imul(j,zt)|0,g=g+Math.imul(j,Be)|0,g=g+Math.imul(L,zt)|0,f=f+Math.imul(L,Be)|0,w=w+Math.imul(ce,Gt)|0,g=g+Math.imul(ce,Re)|0,g=g+Math.imul(E,Gt)|0,f=f+Math.imul(E,Re)|0;var Qn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,w=Math.imul(kt,Ut),g=Math.imul(kt,xe),g=g+Math.imul(Oe,Ut)|0,f=Math.imul(Oe,xe),w=w+Math.imul(It,Lt)|0,g=g+Math.imul(It,Pe)|0,g=g+Math.imul(Ee,Lt)|0,f=f+Math.imul(Ee,Pe)|0,w=w+Math.imul(Le,$t)|0,g=g+Math.imul(Le,Ce)|0,g=g+Math.imul(me,$t)|0,f=f+Math.imul(me,Ce)|0,w=w+Math.imul(Fe,Ft)|0,g=g+Math.imul(Fe,je)|0,g=g+Math.imul(_e,Ft)|0,f=f+Math.imul(_e,je)|0,w=w+Math.imul(ie,qt)|0,g=g+Math.imul(ie,Ne)|0,g=g+Math.imul(oe,qt)|0,f=f+Math.imul(oe,Ne)|0,w=w+Math.imul(X,Vt)|0,g=g+Math.imul(X,De)|0,g=g+Math.imul(G,Vt)|0,f=f+Math.imul(G,De)|0,w=w+Math.imul(W,zt)|0,g=g+Math.imul(W,Be)|0,g=g+Math.imul(q,zt)|0,f=f+Math.imul(q,Be)|0,w=w+Math.imul(j,Gt)|0,g=g+Math.imul(j,Re)|0,g=g+Math.imul(L,Gt)|0,f=f+Math.imul(L,Re)|0;var ei=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(kt,Lt),g=Math.imul(kt,Pe),g=g+Math.imul(Oe,Lt)|0,f=Math.imul(Oe,Pe),w=w+Math.imul(It,$t)|0,g=g+Math.imul(It,Ce)|0,g=g+Math.imul(Ee,$t)|0,f=f+Math.imul(Ee,Ce)|0,w=w+Math.imul(Le,Ft)|0,g=g+Math.imul(Le,je)|0,g=g+Math.imul(me,Ft)|0,f=f+Math.imul(me,je)|0,w=w+Math.imul(Fe,qt)|0,g=g+Math.imul(Fe,Ne)|0,g=g+Math.imul(_e,qt)|0,f=f+Math.imul(_e,Ne)|0,w=w+Math.imul(ie,Vt)|0,g=g+Math.imul(ie,De)|0,g=g+Math.imul(oe,Vt)|0,f=f+Math.imul(oe,De)|0,w=w+Math.imul(X,zt)|0,g=g+Math.imul(X,Be)|0,g=g+Math.imul(G,zt)|0,f=f+Math.imul(G,Be)|0,w=w+Math.imul(W,Gt)|0,g=g+Math.imul(W,Re)|0,g=g+Math.imul(q,Gt)|0,f=f+Math.imul(q,Re)|0;var ti=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(kt,$t),g=Math.imul(kt,Ce),g=g+Math.imul(Oe,$t)|0,f=Math.imul(Oe,Ce),w=w+Math.imul(It,Ft)|0,g=g+Math.imul(It,je)|0,g=g+Math.imul(Ee,Ft)|0,f=f+Math.imul(Ee,je)|0,w=w+Math.imul(Le,qt)|0,g=g+Math.imul(Le,Ne)|0,g=g+Math.imul(me,qt)|0,f=f+Math.imul(me,Ne)|0,w=w+Math.imul(Fe,Vt)|0,g=g+Math.imul(Fe,De)|0,g=g+Math.imul(_e,Vt)|0,f=f+Math.imul(_e,De)|0,w=w+Math.imul(ie,zt)|0,g=g+Math.imul(ie,Be)|0,g=g+Math.imul(oe,zt)|0,f=f+Math.imul(oe,Be)|0,w=w+Math.imul(X,Gt)|0,g=g+Math.imul(X,Re)|0,g=g+Math.imul(G,Gt)|0,f=f+Math.imul(G,Re)|0;var ri=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(kt,Ft),g=Math.imul(kt,je),g=g+Math.imul(Oe,Ft)|0,f=Math.imul(Oe,je),w=w+Math.imul(It,qt)|0,g=g+Math.imul(It,Ne)|0,g=g+Math.imul(Ee,qt)|0,f=f+Math.imul(Ee,Ne)|0,w=w+Math.imul(Le,Vt)|0,g=g+Math.imul(Le,De)|0,g=g+Math.imul(me,Vt)|0,f=f+Math.imul(me,De)|0,w=w+Math.imul(Fe,zt)|0,g=g+Math.imul(Fe,Be)|0,g=g+Math.imul(_e,zt)|0,f=f+Math.imul(_e,Be)|0,w=w+Math.imul(ie,Gt)|0,g=g+Math.imul(ie,Re)|0,g=g+Math.imul(oe,Gt)|0,f=f+Math.imul(oe,Re)|0;var ni=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(kt,qt),g=Math.imul(kt,Ne),g=g+Math.imul(Oe,qt)|0,f=Math.imul(Oe,Ne),w=w+Math.imul(It,Vt)|0,g=g+Math.imul(It,De)|0,g=g+Math.imul(Ee,Vt)|0,f=f+Math.imul(Ee,De)|0,w=w+Math.imul(Le,zt)|0,g=g+Math.imul(Le,Be)|0,g=g+Math.imul(me,zt)|0,f=f+Math.imul(me,Be)|0,w=w+Math.imul(Fe,Gt)|0,g=g+Math.imul(Fe,Re)|0,g=g+Math.imul(_e,Gt)|0,f=f+Math.imul(_e,Re)|0;var ii=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(kt,Vt),g=Math.imul(kt,De),g=g+Math.imul(Oe,Vt)|0,f=Math.imul(Oe,De),w=w+Math.imul(It,zt)|0,g=g+Math.imul(It,Be)|0,g=g+Math.imul(Ee,zt)|0,f=f+Math.imul(Ee,Be)|0,w=w+Math.imul(Le,Gt)|0,g=g+Math.imul(Le,Re)|0,g=g+Math.imul(me,Gt)|0,f=f+Math.imul(me,Re)|0;var si=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(kt,zt),g=Math.imul(kt,Be),g=g+Math.imul(Oe,zt)|0,f=Math.imul(Oe,Be),w=w+Math.imul(It,Gt)|0,g=g+Math.imul(It,Re)|0,g=g+Math.imul(Ee,Gt)|0,f=f+Math.imul(Ee,Re)|0;var oi=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(kt,Gt),g=Math.imul(kt,Re),g=g+Math.imul(Oe,Gt)|0,f=Math.imul(Oe,Re);var ai=(M+w|0)+((g&8191)<<13)|0;return M=(f+(g>>>13)|0)+(ai>>>26)|0,ai&=67108863,v[0]=ct,v[1]=zn,v[2]=Gn,v[3]=Hn,v[4]=Wn,v[5]=Kn,v[6]=Xn,v[7]=Jn,v[8]=Zn,v[9]=Yn,v[10]=Qn,v[11]=ei,v[12]=ti,v[13]=ri,v[14]=ni,v[15]=ii,v[16]=si,v[17]=oi,v[18]=ai,M!==0&&(v[19]=M,l.length++),l};Math.imul||(R=F);function H(k,m,a){a.negative=m.negative^k.negative,a.length=k.length+m.length;for(var l=0,h=0,y=0;y<a.length-1;y++){var v=h;h=0;for(var M=l&67108863,w=Math.min(y,m.length-1),g=Math.max(0,y-k.length+1);g<=w;g++){var f=y-g,S=k.words[f]|0,V=m.words[g]|0,z=S*V,Z=z&67108863;v=v+(z/67108864|0)|0,Z=Z+M|0,M=Z&67108863,v=v+(Z>>>26)|0,h+=v>>>26,v&=67108863}a.words[y]=M,l=v,v=h}return l!==0?a.words[y]=l:a.length--,a._strip()}function J(k,m,a){return H(k,m,a)}i.prototype.mulTo=function(m,a){var l,h=this.length+m.length;return this.length===10&&m.length===10?l=R(this,m,a):h<63?l=F(this,m,a):h<1024?l=H(this,m,a):l=J(this,m,a),l};function ee(k,m){this.x=k,this.y=m}ee.prototype.makeRBT=function(m){for(var a=new Array(m),l=i.prototype._countBits(m)-1,h=0;h<m;h++)a[h]=this.revBin(h,l,m);return a},ee.prototype.revBin=function(m,a,l){if(m===0||m===l-1)return m;for(var h=0,y=0;y<a;y++)h|=(m&1)<<a-y-1,m>>=1;return h},ee.prototype.permute=function(m,a,l,h,y,v){for(var M=0;M<v;M++)h[M]=a[m[M]],y[M]=l[m[M]]},ee.prototype.transform=function(m,a,l,h,y,v){this.permute(v,m,a,l,h,y);for(var M=1;M<y;M<<=1)for(var w=M<<1,g=Math.cos(2*Math.PI/w),f=Math.sin(2*Math.PI/w),S=0;S<y;S+=w)for(var V=g,z=f,Z=0;Z<M;Z++){var ce=l[S+Z],E=h[S+Z],P=l[S+Z+M],j=h[S+Z+M],L=V*P-z*j;j=V*j+z*P,P=L,l[S+Z]=ce+P,h[S+Z]=E+j,l[S+Z+M]=ce-P,h[S+Z+M]=E-j,Z!==w&&(L=g*V-f*z,z=g*z+f*V,V=L)}},ee.prototype.guessLen13b=function(m,a){var l=Math.max(a,m)|1,h=l&1,y=0;for(l=l/2|0;l;l=l>>>1)y++;return 1<<y+1+h},ee.prototype.conjugate=function(m,a,l){if(!(l<=1))for(var h=0;h<l/2;h++){var y=m[h];m[h]=m[l-h-1],m[l-h-1]=y,y=a[h],a[h]=-a[l-h-1],a[l-h-1]=-y}},ee.prototype.normalize13b=function(m,a){for(var l=0,h=0;h<a/2;h++){var y=Math.round(m[2*h+1]/a)*8192+Math.round(m[2*h]/a)+l;m[h]=y&67108863,y<67108864?l=0:l=y/67108864|0}return m},ee.prototype.convert13b=function(m,a,l,h){for(var y=0,v=0;v<a;v++)y=y+(m[v]|0),l[2*v]=y&8191,y=y>>>13,l[2*v+1]=y&8191,y=y>>>13;for(v=2*a;v<h;++v)l[v]=0;r(y===0),r((y&-8192)===0)},ee.prototype.stub=function(m){for(var a=new Array(m),l=0;l<m;l++)a[l]=0;return a},ee.prototype.mulp=function(m,a,l){var h=2*this.guessLen13b(m.length,a.length),y=this.makeRBT(h),v=this.stub(h),M=new Array(h),w=new Array(h),g=new Array(h),f=new Array(h),S=new Array(h),V=new Array(h),z=l.words;z.length=h,this.convert13b(m.words,m.length,M,h),this.convert13b(a.words,a.length,f,h),this.transform(M,v,w,g,h,y),this.transform(f,v,S,V,h,y);for(var Z=0;Z<h;Z++){var ce=w[Z]*S[Z]-g[Z]*V[Z];g[Z]=w[Z]*V[Z]+g[Z]*S[Z],w[Z]=ce}return this.conjugate(w,g,h),this.transform(w,g,z,v,h,y),this.conjugate(z,v,h),this.normalize13b(z,h),l.negative=m.negative^a.negative,l.length=m.length+a.length,l._strip()},i.prototype.mul=function(m){var a=new i(null);return a.words=new Array(this.length+m.length),this.mulTo(m,a)},i.prototype.mulf=function(m){var a=new i(null);return a.words=new Array(this.length+m.length),J(this,m,a)},i.prototype.imul=function(m){return this.clone().mulTo(m,this)},i.prototype.imuln=function(m){var a=m<0;a&&(m=-m),r(typeof m=="number"),r(m<67108864);for(var l=0,h=0;h<this.length;h++){var y=(this.words[h]|0)*m,v=(y&67108863)+(l&67108863);l>>=26,l+=y/67108864|0,l+=v>>>26,this.words[h]=v&67108863}return l!==0&&(this.words[h]=l,this.length++),this.length=m===0?1:this.length,a?this.ineg():this},i.prototype.muln=function(m){return this.clone().imuln(m)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(m){var a=x(m);if(a.length===0)return new i(1);for(var l=this,h=0;h<a.length&&a[h]===0;h++,l=l.sqr());if(++h<a.length)for(var y=l.sqr();h<a.length;h++,y=y.sqr())a[h]!==0&&(l=l.mul(y));return l},i.prototype.iushln=function(m){r(typeof m=="number"&&m>=0);var a=m%26,l=(m-a)/26,h=67108863>>>26-a<<26-a,y;if(a!==0){var v=0;for(y=0;y<this.length;y++){var M=this.words[y]&h,w=(this.words[y]|0)-M<<a;this.words[y]=w|v,v=M>>>26-a}v&&(this.words[y]=v,this.length++)}if(l!==0){for(y=this.length-1;y>=0;y--)this.words[y+l]=this.words[y];for(y=0;y<l;y++)this.words[y]=0;this.length+=l}return this._strip()},i.prototype.ishln=function(m){return r(this.negative===0),this.iushln(m)},i.prototype.iushrn=function(m,a,l){r(typeof m=="number"&&m>=0);var h;a?h=(a-a%26)/26:h=0;var y=m%26,v=Math.min((m-y)/26,this.length),M=67108863^67108863>>>y<<y,w=l;if(h-=v,h=Math.max(0,h),w){for(var g=0;g<v;g++)w.words[g]=this.words[g];w.length=v}if(v!==0)if(this.length>v)for(this.length-=v,g=0;g<this.length;g++)this.words[g]=this.words[g+v];else this.words[0]=0,this.length=1;var f=0;for(g=this.length-1;g>=0&&(f!==0||g>=h);g--){var S=this.words[g]|0;this.words[g]=f<<26-y|S>>>y,f=S&M}return w&&f!==0&&(w.words[w.length++]=f),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(m,a,l){return r(this.negative===0),this.iushrn(m,a,l)},i.prototype.shln=function(m){return this.clone().ishln(m)},i.prototype.ushln=function(m){return this.clone().iushln(m)},i.prototype.shrn=function(m){return this.clone().ishrn(m)},i.prototype.ushrn=function(m){return this.clone().iushrn(m)},i.prototype.testn=function(m){r(typeof m=="number"&&m>=0);var a=m%26,l=(m-a)/26,h=1<<a;if(this.length<=l)return!1;var y=this.words[l];return!!(y&h)},i.prototype.imaskn=function(m){r(typeof m=="number"&&m>=0);var a=m%26,l=(m-a)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(a!==0&&l++,this.length=Math.min(l,this.length),a!==0){var h=67108863^67108863>>>a<<a;this.words[this.length-1]&=h}return this._strip()},i.prototype.maskn=function(m){return this.clone().imaskn(m)},i.prototype.iaddn=function(m){return r(typeof m=="number"),r(m<67108864),m<0?this.isubn(-m):this.negative!==0?this.length===1&&(this.words[0]|0)<=m?(this.words[0]=m-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(m),this.negative=1,this):this._iaddn(m)},i.prototype._iaddn=function(m){this.words[0]+=m;for(var a=0;a<this.length&&this.words[a]>=67108864;a++)this.words[a]-=67108864,a===this.length-1?this.words[a+1]=1:this.words[a+1]++;return this.length=Math.max(this.length,a+1),this},i.prototype.isubn=function(m){if(r(typeof m=="number"),r(m<67108864),m<0)return this.iaddn(-m);if(this.negative!==0)return this.negative=0,this.iaddn(m),this.negative=1,this;if(this.words[0]-=m,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var a=0;a<this.length&&this.words[a]<0;a++)this.words[a]+=67108864,this.words[a+1]-=1;return this._strip()},i.prototype.addn=function(m){return this.clone().iaddn(m)},i.prototype.subn=function(m){return this.clone().isubn(m)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(m,a,l){var h=m.length+l,y;this._expand(h);var v,M=0;for(y=0;y<m.length;y++){v=(this.words[y+l]|0)+M;var w=(m.words[y]|0)*a;v-=w&67108863,M=(v>>26)-(w/67108864|0),this.words[y+l]=v&67108863}for(;y<this.length-l;y++)v=(this.words[y+l]|0)+M,M=v>>26,this.words[y+l]=v&67108863;if(M===0)return this._strip();for(r(M===-1),M=0,y=0;y<this.length;y++)v=-(this.words[y]|0)+M,M=v>>26,this.words[y]=v&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(m,a){var l=this.length-m.length,h=this.clone(),y=m,v=y.words[y.length-1]|0,M=this._countBits(v);l=26-M,l!==0&&(y=y.ushln(l),h.iushln(l),v=y.words[y.length-1]|0);var w=h.length-y.length,g;if(a!=="mod"){g=new i(null),g.length=w+1,g.words=new Array(g.length);for(var f=0;f<g.length;f++)g.words[f]=0}var S=h.clone()._ishlnsubmul(y,1,w);S.negative===0&&(h=S,g&&(g.words[w]=1));for(var V=w-1;V>=0;V--){var z=(h.words[y.length+V]|0)*67108864+(h.words[y.length+V-1]|0);for(z=Math.min(z/v|0,67108863),h._ishlnsubmul(y,z,V);h.negative!==0;)z--,h.negative=0,h._ishlnsubmul(y,1,V),h.isZero()||(h.negative^=1);g&&(g.words[V]=z)}return g&&g._strip(),h._strip(),a!=="div"&&l!==0&&h.iushrn(l),{div:g||null,mod:h}},i.prototype.divmod=function(m,a,l){if(r(!m.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var h,y,v;return this.negative!==0&&m.negative===0?(v=this.neg().divmod(m,a),a!=="mod"&&(h=v.div.neg()),a!=="div"&&(y=v.mod.neg(),l&&y.negative!==0&&y.iadd(m)),{div:h,mod:y}):this.negative===0&&m.negative!==0?(v=this.divmod(m.neg(),a),a!=="mod"&&(h=v.div.neg()),{div:h,mod:v.mod}):(this.negative&m.negative)!==0?(v=this.neg().divmod(m.neg(),a),a!=="div"&&(y=v.mod.neg(),l&&y.negative!==0&&y.isub(m)),{div:v.div,mod:y}):m.length>this.length||this.cmp(m)<0?{div:new i(0),mod:this}:m.length===1?a==="div"?{div:this.divn(m.words[0]),mod:null}:a==="mod"?{div:null,mod:new i(this.modrn(m.words[0]))}:{div:this.divn(m.words[0]),mod:new i(this.modrn(m.words[0]))}:this._wordDiv(m,a)},i.prototype.div=function(m){return this.divmod(m,"div",!1).div},i.prototype.mod=function(m){return this.divmod(m,"mod",!1).mod},i.prototype.umod=function(m){return this.divmod(m,"mod",!0).mod},i.prototype.divRound=function(m){var a=this.divmod(m);if(a.mod.isZero())return a.div;var l=a.div.negative!==0?a.mod.isub(m):a.mod,h=m.ushrn(1),y=m.andln(1),v=l.cmp(h);return v<0||y===1&&v===0?a.div:a.div.negative!==0?a.div.isubn(1):a.div.iaddn(1)},i.prototype.modrn=function(m){var a=m<0;a&&(m=-m),r(m<=67108863);for(var l=(1<<26)%m,h=0,y=this.length-1;y>=0;y--)h=(l*h+(this.words[y]|0))%m;return a?-h:h},i.prototype.modn=function(m){return this.modrn(m)},i.prototype.idivn=function(m){var a=m<0;a&&(m=-m),r(m<=67108863);for(var l=0,h=this.length-1;h>=0;h--){var y=(this.words[h]|0)+l*67108864;this.words[h]=y/m|0,l=y%m}return this._strip(),a?this.ineg():this},i.prototype.divn=function(m){return this.clone().idivn(m)},i.prototype.egcd=function(m){r(m.negative===0),r(!m.isZero());var a=this,l=m.clone();a.negative!==0?a=a.umod(m):a=a.clone();for(var h=new i(1),y=new i(0),v=new i(0),M=new i(1),w=0;a.isEven()&&l.isEven();)a.iushrn(1),l.iushrn(1),++w;for(var g=l.clone(),f=a.clone();!a.isZero();){for(var S=0,V=1;(a.words[0]&V)===0&&S<26;++S,V<<=1);if(S>0)for(a.iushrn(S);S-- >0;)(h.isOdd()||y.isOdd())&&(h.iadd(g),y.isub(f)),h.iushrn(1),y.iushrn(1);for(var z=0,Z=1;(l.words[0]&Z)===0&&z<26;++z,Z<<=1);if(z>0)for(l.iushrn(z);z-- >0;)(v.isOdd()||M.isOdd())&&(v.iadd(g),M.isub(f)),v.iushrn(1),M.iushrn(1);a.cmp(l)>=0?(a.isub(l),h.isub(v),y.isub(M)):(l.isub(a),v.isub(h),M.isub(y))}return{a:v,b:M,gcd:l.iushln(w)}},i.prototype._invmp=function(m){r(m.negative===0),r(!m.isZero());var a=this,l=m.clone();a.negative!==0?a=a.umod(m):a=a.clone();for(var h=new i(1),y=new i(0),v=l.clone();a.cmpn(1)>0&&l.cmpn(1)>0;){for(var M=0,w=1;(a.words[0]&w)===0&&M<26;++M,w<<=1);if(M>0)for(a.iushrn(M);M-- >0;)h.isOdd()&&h.iadd(v),h.iushrn(1);for(var g=0,f=1;(l.words[0]&f)===0&&g<26;++g,f<<=1);if(g>0)for(l.iushrn(g);g-- >0;)y.isOdd()&&y.iadd(v),y.iushrn(1);a.cmp(l)>=0?(a.isub(l),h.isub(y)):(l.isub(a),y.isub(h))}var S;return a.cmpn(1)===0?S=h:S=y,S.cmpn(0)<0&&S.iadd(m),S},i.prototype.gcd=function(m){if(this.isZero())return m.abs();if(m.isZero())return this.abs();var a=this.clone(),l=m.clone();a.negative=0,l.negative=0;for(var h=0;a.isEven()&&l.isEven();h++)a.iushrn(1),l.iushrn(1);do{for(;a.isEven();)a.iushrn(1);for(;l.isEven();)l.iushrn(1);var y=a.cmp(l);if(y<0){var v=a;a=l,l=v}else if(y===0||l.cmpn(1)===0)break;a.isub(l)}while(!0);return l.iushln(h)},i.prototype.invm=function(m){return this.egcd(m).a.umod(m)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(m){return this.words[0]&m},i.prototype.bincn=function(m){r(typeof m=="number");var a=m%26,l=(m-a)/26,h=1<<a;if(this.length<=l)return this._expand(l+1),this.words[l]|=h,this;for(var y=h,v=l;y!==0&&v<this.length;v++){var M=this.words[v]|0;M+=y,y=M>>>26,M&=67108863,this.words[v]=M}return y!==0&&(this.words[v]=y,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(m){var a=m<0;if(this.negative!==0&&!a)return-1;if(this.negative===0&&a)return 1;this._strip();var l;if(this.length>1)l=1;else{a&&(m=-m),r(m<=67108863,"Number is too big");var h=this.words[0]|0;l=h===m?0:h<m?-1:1}return this.negative!==0?-l|0:l},i.prototype.cmp=function(m){if(this.negative!==0&&m.negative===0)return-1;if(this.negative===0&&m.negative!==0)return 1;var a=this.ucmp(m);return this.negative!==0?-a|0:a},i.prototype.ucmp=function(m){if(this.length>m.length)return 1;if(this.length<m.length)return-1;for(var a=0,l=this.length-1;l>=0;l--){var h=this.words[l]|0,y=m.words[l]|0;if(h!==y){h<y?a=-1:h>y&&(a=1);break}}return a},i.prototype.gtn=function(m){return this.cmpn(m)===1},i.prototype.gt=function(m){return this.cmp(m)===1},i.prototype.gten=function(m){return this.cmpn(m)>=0},i.prototype.gte=function(m){return this.cmp(m)>=0},i.prototype.ltn=function(m){return this.cmpn(m)===-1},i.prototype.lt=function(m){return this.cmp(m)===-1},i.prototype.lten=function(m){return this.cmpn(m)<=0},i.prototype.lte=function(m){return this.cmp(m)<=0},i.prototype.eqn=function(m){return this.cmpn(m)===0},i.prototype.eq=function(m){return this.cmp(m)===0},i.red=function(m){return new D(m)},i.prototype.toRed=function(m){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),m.convertTo(this)._forceRed(m)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(m){return this.red=m,this},i.prototype.forceRed=function(m){return r(!this.red,"Already a number in reduction context"),this._forceRed(m)},i.prototype.redAdd=function(m){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,m)},i.prototype.redIAdd=function(m){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,m)},i.prototype.redSub=function(m){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,m)},i.prototype.redISub=function(m){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,m)},i.prototype.redShl=function(m){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,m)},i.prototype.redMul=function(m){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,m),this.red.mul(this,m)},i.prototype.redIMul=function(m){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,m),this.red.imul(this,m)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(m){return r(this.red&&!m.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,m)};var ae={k256:null,p224:null,p192:null,p25519:null};function te(k,m){this.name=k,this.p=new i(m,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}te.prototype._tmp=function(){var m=new i(null);return m.words=new Array(Math.ceil(this.n/13)),m},te.prototype.ireduce=function(m){var a=m,l;do this.split(a,this.tmp),a=this.imulK(a),a=a.iadd(this.tmp),l=a.bitLength();while(l>this.n);var h=l<this.n?-1:a.ucmp(this.p);return h===0?(a.words[0]=0,a.length=1):h>0?a.isub(this.p):a.strip!==void 0?a.strip():a._strip(),a},te.prototype.split=function(m,a){m.iushrn(this.n,0,a)},te.prototype.imulK=function(m){return m.imul(this.k)};function he(){te.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(he,te),he.prototype.split=function(m,a){for(var l=4194303,h=Math.min(m.length,9),y=0;y<h;y++)a.words[y]=m.words[y];if(a.length=h,m.length<=9){m.words[0]=0,m.length=1;return}var v=m.words[9];for(a.words[a.length++]=v&l,y=10;y<m.length;y++){var M=m.words[y]|0;m.words[y-10]=(M&l)<<4|v>>>22,v=M}v>>>=22,m.words[y-10]=v,v===0&&m.length>10?m.length-=10:m.length-=9},he.prototype.imulK=function(m){m.words[m.length]=0,m.words[m.length+1]=0,m.length+=2;for(var a=0,l=0;l<m.length;l++){var h=m.words[l]|0;a+=h*977,m.words[l]=a&67108863,a=h*64+(a/67108864|0)}return m.words[m.length-1]===0&&(m.length--,m.words[m.length-1]===0&&m.length--),m};function A(){te.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(A,te);function I(){te.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(I,te);function C(){te.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(C,te),C.prototype.imulK=function(m){for(var a=0,l=0;l<m.length;l++){var h=(m.words[l]|0)*19+a,y=h&67108863;h>>>=26,m.words[l]=y,a=h}return a!==0&&(m.words[m.length++]=a),m},i._prime=function(m){if(ae[m])return ae[m];var a;if(m==="k256")a=new he;else if(m==="p224")a=new A;else if(m==="p192")a=new I;else if(m==="p25519")a=new C;else throw new Error("Unknown prime "+m);return ae[m]=a,a};function D(k){if(typeof k=="string"){var m=i._prime(k);this.m=m.p,this.prime=m}else r(k.gtn(1),"modulus must be greater than 1"),this.m=k,this.prime=null}D.prototype._verify1=function(m){r(m.negative===0,"red works only with positives"),r(m.red,"red works only with red numbers")},D.prototype._verify2=function(m,a){r((m.negative|a.negative)===0,"red works only with positives"),r(m.red&&m.red===a.red,"red works only with red numbers")},D.prototype.imod=function(m){return this.prime?this.prime.ireduce(m)._forceRed(this):(d(m,m.umod(this.m)._forceRed(this)),m)},D.prototype.neg=function(m){return m.isZero()?m.clone():this.m.sub(m)._forceRed(this)},D.prototype.add=function(m,a){this._verify2(m,a);var l=m.add(a);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},D.prototype.iadd=function(m,a){this._verify2(m,a);var l=m.iadd(a);return l.cmp(this.m)>=0&&l.isub(this.m),l},D.prototype.sub=function(m,a){this._verify2(m,a);var l=m.sub(a);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},D.prototype.isub=function(m,a){this._verify2(m,a);var l=m.isub(a);return l.cmpn(0)<0&&l.iadd(this.m),l},D.prototype.shl=function(m,a){return this._verify1(m),this.imod(m.ushln(a))},D.prototype.imul=function(m,a){return this._verify2(m,a),this.imod(m.imul(a))},D.prototype.mul=function(m,a){return this._verify2(m,a),this.imod(m.mul(a))},D.prototype.isqr=function(m){return this.imul(m,m.clone())},D.prototype.sqr=function(m){return this.mul(m,m)},D.prototype.sqrt=function(m){if(m.isZero())return m.clone();var a=this.m.andln(3);if(r(a%2===1),a===3){var l=this.m.add(new i(1)).iushrn(2);return this.pow(m,l)}for(var h=this.m.subn(1),y=0;!h.isZero()&&h.andln(1)===0;)y++,h.iushrn(1);r(!h.isZero());var v=new i(1).toRed(this),M=v.redNeg(),w=this.m.subn(1).iushrn(1),g=this.m.bitLength();for(g=new i(2*g*g).toRed(this);this.pow(g,w).cmp(M)!==0;)g.redIAdd(M);for(var f=this.pow(g,h),S=this.pow(m,h.addn(1).iushrn(1)),V=this.pow(m,h),z=y;V.cmp(v)!==0;){for(var Z=V,ce=0;Z.cmp(v)!==0;ce++)Z=Z.redSqr();r(ce<z);var E=this.pow(f,new i(1).iushln(z-ce-1));S=S.redMul(E),f=E.redSqr(),V=V.redMul(f),z=ce}return S},D.prototype.invm=function(m){var a=m._invmp(this.m);return a.negative!==0?(a.negative=0,this.imod(a).redNeg()):this.imod(a)},D.prototype.pow=function(m,a){if(a.isZero())return new i(1).toRed(this);if(a.cmpn(1)===0)return m.clone();var l=4,h=new Array(1<<l);h[0]=new i(1).toRed(this),h[1]=m;for(var y=2;y<h.length;y++)h[y]=this.mul(h[y-1],m);var v=h[0],M=0,w=0,g=a.bitLength()%26;for(g===0&&(g=26),y=a.length-1;y>=0;y--){for(var f=a.words[y],S=g-1;S>=0;S--){var V=f>>S&1;if(v!==h[0]&&(v=this.sqr(v)),V===0&&M===0){w=0;continue}M<<=1,M|=V,w++,!(w!==l&&(y!==0||S!==0))&&(v=this.mul(v,h[M]),w=0,M=0)}g=26}return v},D.prototype.convertTo=function(m){var a=m.umod(this.m);return a===m?a.clone():a},D.prototype.convertFrom=function(m){var a=m.clone();return a.red=null,a},i.mont=function(m){return new N(m)};function N(k){D.call(this,k),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(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)}n(N,D),N.prototype.convertTo=function(m){return this.imod(m.ushln(this.shift))},N.prototype.convertFrom=function(m){var a=this.imod(m.mul(this.rinv));return a.red=null,a},N.prototype.imul=function(m,a){if(m.isZero()||a.isZero())return m.words[0]=0,m.length=1,m;var l=m.imul(a),h=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=l.isub(h).iushrn(this.shift),v=y;return y.cmp(this.m)>=0?v=y.isub(this.m):y.cmpn(0)<0&&(v=y.iadd(this.m)),v._forceRed(this)},N.prototype.mul=function(m,a){if(m.isZero()||a.isZero())return new i(0)._forceRed(this);var l=m.mul(a),h=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=l.isub(h).iushrn(this.shift),v=y;return y.cmp(this.m)>=0?v=y.isub(this.m):y.cmpn(0)<0&&(v=y.iadd(this.m)),v._forceRed(this)},N.prototype.invm=function(m){var a=this.imod(m._invmp(this.m).mul(this.r2));return a._forceRed(this)}})(typeof Kh>"u"||Kh,Tv)});var jb=be(Ae=>{"use strict";Object.defineProperty(Ae,"__esModule",{value:!0});Ae.bytes=Ae.stringToBytes=Ae.str=Ae.bytesToString=Ae.hex=Ae.utf8=Ae.bech32m=Ae.bech32=Ae.base58check=Ae.createBase58check=Ae.base58xmr=Ae.base58xrp=Ae.base58flickr=Ae.base58=Ae.base64urlnopad=Ae.base64url=Ae.base64nopad=Ae.base64=Ae.base32crockford=Ae.base32hexnopad=Ae.base32hex=Ae.base32nopad=Ae.base32=Ae.base16=Ae.utils=void 0;function Ko(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Sp(t,...e){if(!Ko(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function kb(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function kp(t){if(typeof t!="function")throw new Error("function expected");return!0}function eo(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function xa(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Ll(t){if(!Array.isArray(t))throw new Error("array expected")}function $l(t,e){if(!kb(!0,e))throw new Error(`${t}: array of strings expected`)}function Op(t,e){if(!kb(!1,e))throw new Error(`${t}: array of numbers expected`)}function nn(...t){let e=s=>s,r=(s,o)=>u=>s(o(u)),n=t.map(s=>s.encode).reduceRight(r,e),i=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:i}}function dn(t){let e=typeof t=="string"?t.split(""):t,r=e.length;$l("alphabet",e);let n=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Ll(i),i.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:i=>(Ll(i),i.map(s=>{eo("alphabet.decode",s);let o=n.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function hn(t=""){return eo("join",t),{encode:e=>($l("join.decode",e),e.join(t)),decode:e=>(eo("join.decode",e),e.split(t))}}function Gu(t,e="="){return xa(t),eo("padding",e),{encode(r){for($l("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){$l("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function Ob(t){return kp(t),{encode:e=>e,decode:e=>t(e)}}function wp(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Ll(t),!t.length)return[];let n=0,i=[],s=Array.from(t,u=>{if(xa(u),u<0||u>=e)throw new Error(`invalid integer: ${u}`);return u}),o=s.length;for(;;){let u=0,c=!0;for(let d=n;d<o;d++){let p=s[d],_=e*u,b=_+p;if(!Number.isSafeInteger(b)||_/e!==u||b-p!==_)throw new Error("convertRadix: carry overflow");let O=b/r;u=b%r;let T=Math.floor(O);if(s[d]=T,!Number.isSafeInteger(T)||T*r+u!==b)throw new Error("convertRadix: carry overflow");if(c)T?c=!1:n=d;else continue}if(i.push(u),c)break}for(let u=0;u<t.length-1&&t[u]===0;u++)i.push(0);return i.reverse()}var Eb=(t,e)=>e===0?t:Eb(e,t%e),Fl=(t,e)=>t+(e-Eb(t,e)),Ul=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function ql(t,e,r,n){if(Ll(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Fl(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Fl(e,r)}`);let i=0,s=0,o=Ul[e],u=Ul[r]-1,c=[];for(let d of t){if(xa(d),d>=o)throw new Error(`convertRadix2: invalid data word=${d} from=${e}`);if(i=i<<e|d,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=r;s-=r)c.push((i>>s-r&u)>>>0);let p=Ul[s];if(p===void 0)throw new Error("invalid carry");i&=p-1}if(i=i<<r-s&u,!n&&s>=e)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&s>0&&c.push(i>>>0),c}function Ab(t){xa(t);let e=2**8;return{encode:r=>{if(!Ko(r))throw new Error("radix.encode input should be Uint8Array");return wp(Array.from(r),e,t)},decode:r=>(Op("radix.decode",r),Uint8Array.from(wp(r,t,e)))}}function bn(t,e=!1){if(xa(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Fl(8,t)>32||Fl(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Ko(r))throw new Error("radix2.encode input should be Uint8Array");return ql(Array.from(r),8,t,!e)},decode:r=>(Op("radix2.decode",r),Uint8Array.from(ql(r,t,8,e)))}}function bb(t){return kp(t),function(...e){try{return t.apply(null,e)}catch{}}}function Ib(t,e){return xa(t),kp(e),{encode(r){if(!Ko(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),i=new Uint8Array(r.length+t);return i.set(r),i.set(n,r.length),i},decode(r){if(!Ko(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),i=r.slice(-t),s=e(n).slice(0,t);for(let o=0;o<t;o++)if(s[o]!==i[o])throw new Error("Invalid checksum");return n}}}Ae.utils={alphabet:dn,chain:nn,checksum:Ib,convertRadix:wp,convertRadix2:ql,radix:Ab,radix2:bn,join:hn,padding:Gu};Ae.base16=nn(bn(4),dn("0123456789ABCDEF"),hn(""));Ae.base32=nn(bn(5),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Gu(5),hn(""));Ae.base32nopad=nn(bn(5),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),hn(""));Ae.base32hex=nn(bn(5),dn("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Gu(5),hn(""));Ae.base32hexnopad=nn(bn(5),dn("0123456789ABCDEFGHIJKLMNOPQRSTUV"),hn(""));Ae.base32crockford=nn(bn(5),dn("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),hn(""),Ob(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));var Tb=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",xb=(t,e)=>{eo("base64",t);let r=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=e?"base64url":"base64";if(t.length>0&&!r.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:n,lastChunkHandling:"strict"})};Ae.base64=Tb?{encode(t){return Sp(t),t.toBase64()},decode(t){return xb(t,!1)}}:nn(bn(6),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Gu(6),hn(""));Ae.base64nopad=nn(bn(6),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),hn(""));Ae.base64url=Tb?{encode(t){return Sp(t),t.toBase64({alphabet:"base64url"})},decode(t){return xb(t,!0)}}:nn(bn(6),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Gu(6),hn(""));Ae.base64urlnopad=nn(bn(6),dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),hn(""));var Ep=t=>nn(Ab(58),dn(t),hn(""));Ae.base58=Ep("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Ae.base58flickr=Ep("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");Ae.base58xrp=Ep("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");var wb=[0,2,3,5,6,7,9,10,11];Ae.base58xmr={encode(t){let e="";for(let r=0;r<t.length;r+=8){let n=t.subarray(r,r+8);e+=Ae.base58.encode(n).padStart(wb[n.length],"1")}return e},decode(t){let e=[];for(let r=0;r<t.length;r+=11){let n=t.slice(r,r+11),i=wb.indexOf(n.length),s=Ae.base58.decode(n);for(let o=0;o<s.length-i;o++)if(s[o]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(e)}};var gC=t=>nn(Ib(4,e=>t(t(e))),Ae.base58);Ae.createBase58check=gC;Ae.base58check=Ae.createBase58check;var Mp=nn(dn("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),hn("")),Mb=[996825010,642813549,513874426,1027748829,705979059];function zu(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<Mb.length;n++)(e>>n&1)===1&&(r^=Mb[n]);return r}function Sb(t,e,r=1){let n=t.length,i=1;for(let s=0;s<n;s++){let o=t.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);i=zu(i)^o>>5}i=zu(i);for(let s=0;s<n;s++)i=zu(i)^t.charCodeAt(s)&31;for(let s of e)i=zu(i)^s;for(let s=0;s<6;s++)i=zu(i);return i^=r,Mp.encode(ql([i%Ul[30]],30,5,!1))}function Pb(t){let e=t==="bech32"?1:734539939,r=bn(5),n=r.decode,i=r.encode,s=bb(n);function o(_,b,O=90){eo("bech32.encode prefix",_),Ko(b)&&(b=Array.from(b)),Op("bech32.encode",b);let T=_.length;if(T===0)throw new TypeError(`Invalid prefix length ${T}`);let x=T+7+b.length;if(O!==!1&&x>O)throw new TypeError(`Length ${x} exceeds limit ${O}`);let F=_.toLowerCase(),R=Sb(F,b,e);return`${F}1${Mp.encode(b)}${R}`}function u(_,b=90){eo("bech32.decode input",_);let O=_.length;if(O<8||b!==!1&&O>b)throw new TypeError(`invalid string length: ${O} (${_}). Expected (8..${b})`);let T=_.toLowerCase();if(_!==T&&_!==_.toUpperCase())throw new Error("String must be lowercase or uppercase");let x=T.lastIndexOf("1");if(x===0||x===-1)throw new Error('Letter "1" must be present between prefix and data only');let F=T.slice(0,x),R=T.slice(x+1);if(R.length<6)throw new Error("Data must be at least 6 characters long");let H=Mp.decode(R).slice(0,-6),J=Sb(F,H,e);if(!R.endsWith(J))throw new Error(`Invalid checksum in ${_}: expected "${J}"`);return{prefix:F,words:H}}let c=bb(u);function d(_){let{prefix:b,words:O}=u(_,!1);return{prefix:b,words:O,bytes:n(O)}}function p(_,b){return o(_,i(b))}return{encode:o,decode:u,encodeFromBytes:p,decodeToBytes:d,decodeUnsafe:c,fromWords:n,fromWordsUnsafe:s,toWords:i}}Ae.bech32=Pb("bech32");Ae.bech32m=Pb("bech32m");Ae.utf8={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)};var yC=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_C={encode(t){return Sp(t),t.toHex()},decode(t){return eo("hex",t),Uint8Array.fromHex(t)}};Ae.hex=yC?_C:nn(bn(4),dn("0123456789abcdef"),hn(""),Ob(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var Vl={utf8:Ae.utf8,hex:Ae.hex,base16:Ae.base16,base32:Ae.base32,base64:Ae.base64,base64url:Ae.base64url,base58:Ae.base58,base58xmr:Ae.base58xmr},Cb="Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr",vC=(t,e)=>{if(typeof t!="string"||!Vl.hasOwnProperty(t))throw new TypeError(Cb);if(!Ko(e))throw new TypeError("bytesToString() expects Uint8Array");return Vl[t].encode(e)};Ae.bytesToString=vC;Ae.str=Ae.bytesToString;var bC=(t,e)=>{if(!Vl.hasOwnProperty(t))throw new TypeError(Cb);if(typeof e!="string")throw new TypeError("stringToBytes() expects string");return Vl[t].decode(e)};Ae.stringToBytes=bC;Ae.bytes=Ae.stringToBytes});var Rb=be((sY,Bb)=>{"use strict";var Ap=Object.defineProperty,wC=Object.getOwnPropertyDescriptor,MC=Object.getOwnPropertyNames,SC=Object.prototype.hasOwnProperty,kC=(t,e)=>{for(var r in e)Ap(t,r,{get:e[r],enumerable:!0})},OC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of MC(e))!SC.call(t,i)&&i!==r&&Ap(t,i,{get:()=>e[i],enumerable:!(n=wC(e,i))||n.enumerable});return t},EC=t=>OC(Ap({},"__esModule",{value:!0}),t),Nb={};kC(Nb,{fromBase58:()=>IC,toBase58:()=>AC});Bb.exports=EC(Nb);var Db=jb(),AC=t=>Db.base58.encode(t),IC=t=>Db.base58.decode(t)});var $b=be((oY,Lb)=>{"use strict";var Tp=Object.defineProperty,TC=Object.getOwnPropertyDescriptor,xC=Object.getOwnPropertyNames,PC=Object.prototype.hasOwnProperty,CC=(t,e)=>{for(var r in e)Tp(t,r,{get:e[r],enumerable:!0})},jC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xC(e))!PC.call(t,i)&&i!==r&&Tp(t,i,{get:()=>e[i],enumerable:!(n=TC(e,i))||n.enumerable});return t},NC=t=>jC(Tp({},"__esModule",{value:!0}),t),Ub={};CC(Ub,{fromBase64:()=>DC,toBase64:()=>BC});Lb.exports=NC(Ub);function DC(t){return Uint8Array.from(atob(t),e=>e.charCodeAt(0))}var Ip=8192;function BC(t){if(t.length<Ip)return btoa(String.fromCharCode(...t));let e="";for(var r=0;r<t.length;r+=Ip){let n=t.slice(r,r+Ip);e+=String.fromCharCode(...n)}return btoa(e)}});var Vb=be((aY,qb)=>{"use strict";var xp=Object.defineProperty,RC=Object.getOwnPropertyDescriptor,UC=Object.getOwnPropertyNames,LC=Object.prototype.hasOwnProperty,$C=(t,e)=>{for(var r in e)xp(t,r,{get:e[r],enumerable:!0})},FC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of UC(e))!LC.call(t,i)&&i!==r&&xp(t,i,{get:()=>e[i],enumerable:!(n=RC(e,i))||n.enumerable});return t},qC=t=>FC(xp({},"__esModule",{value:!0}),t),Fb={};$C(Fb,{fromHex:()=>VC,toHex:()=>zC});qb.exports=qC(Fb);function VC(t){let e=t.startsWith("0x")?t.slice(2):t,r=e.length%2===0?e:`0${e}`,n=r.match(/[0-9a-fA-F]{2}/g)?.map(i=>parseInt(i,16))??[];if(n.length!==r.length/2)throw new Error(`Invalid hex string ${t}`);return Uint8Array.from(n)}function zC(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}});var Hb=be((uY,Gb)=>{"use strict";var Pp=Object.defineProperty,GC=Object.getOwnPropertyDescriptor,HC=Object.getOwnPropertyNames,WC=Object.prototype.hasOwnProperty,KC=(t,e)=>{for(var r in e)Pp(t,r,{get:e[r],enumerable:!0})},XC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of HC(e))!WC.call(t,i)&&i!==r&&Pp(t,i,{get:()=>e[i],enumerable:!(n=GC(e,i))||n.enumerable});return t},JC=t=>XC(Pp({},"__esModule",{value:!0}),t),zb={};KC(zb,{chunk:()=>ZC});Gb.exports=JC(zb);function ZC(t,e){return Array.from({length:Math.ceil(t.length/e)},(r,n)=>t.slice(n*e,(n+1)*e))}});var Xb=be((cY,Kb)=>{"use strict";var Cp=Object.defineProperty,YC=Object.getOwnPropertyDescriptor,QC=Object.getOwnPropertyNames,e8=Object.prototype.hasOwnProperty,t8=(t,e)=>{for(var r in e)Cp(t,r,{get:e[r],enumerable:!0})},r8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of QC(e))!e8.call(t,i)&&i!==r&&Cp(t,i,{get:()=>e[i],enumerable:!(n=YC(e,i))||n.enumerable});return t},n8=t=>r8(Cp({},"__esModule",{value:!0}),t),Wb={};t8(Wb,{promiseWithResolvers:()=>i8});Kb.exports=n8(Wb);function i8(){let t,e;return{promise:new Promise((n,i)=>{t=n,e=i}),resolve:t,reject:e}}});var Qb=be((lY,Yb)=>{"use strict";var Rp=Object.defineProperty,s8=Object.getOwnPropertyDescriptor,o8=Object.getOwnPropertyNames,a8=Object.prototype.hasOwnProperty,u8=(t,e)=>{for(var r in e)Rp(t,r,{get:e[r],enumerable:!0})},c8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of o8(e))!a8.call(t,i)&&i!==r&&Rp(t,i,{get:()=>e[i],enumerable:!(n=s8(e,i))||n.enumerable});return t},l8=t=>c8(Rp({},"__esModule",{value:!0}),t),Jb={};u8(Jb,{DataLoader:()=>Dp});Yb.exports=l8(Jb);var Dp=class{constructor(e,r){if(typeof e!="function")throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: ${e}.`);this._batchLoadFn=e,this._maxBatchSize=p8(r),this._batchScheduleFn=m8(r),this._cacheKeyFn=g8(r),this._cacheMap=y8(r),this._batch=null,this.name=_8(r)}load(e){if(e==null)throw new TypeError(`The loader.load() function must be called with a value, but got: ${String(e)}.`);let r=d8(this),n=this._cacheMap,i;if(n){i=this._cacheKeyFn(e);let o=n.get(i);if(o){let u=r.cacheHits||(r.cacheHits=[]);return new Promise(c=>{u.push(()=>{c(o)})})}}r.keys.push(e);let s=new Promise((o,u)=>{r.callbacks.push({resolve:o,reject:u})});return n&&n.set(i,s),s}loadMany(e){if(!Zb(e))throw new TypeError(`The loader.loadMany() function must be called with Array<key>, but got: ${e}.`);let r=[];for(let n=0;n<e.length;n++)r.push(this.load(e[n]).catch(i=>i));return Promise.all(r)}clear(e){let r=this._cacheMap;if(r){let n=this._cacheKeyFn(e);r.delete(n)}return this}clearAll(){let e=this._cacheMap;return e&&e.clear(),this}prime(e,r){let n=this._cacheMap;if(n){let i=this._cacheKeyFn(e);if(n.get(i)===void 0){let s;r instanceof Error?(s=Promise.reject(r),s.catch(()=>{})):s=Promise.resolve(r),n.set(i,s)}}return this}},f8=typeof process=="object"&&typeof process.nextTick=="function"?function(t){jp||(jp=Promise.resolve()),jp.then(()=>{process.nextTick(t)})}:typeof setImmediate=="function"?function(t){setImmediate(t)}:function(t){setTimeout(t)},jp;function d8(t){let e=t._batch;if(e!==null&&!e.hasDispatched&&e.keys.length<t._maxBatchSize)return e;let r={hasDispatched:!1,keys:[],callbacks:[]};return t._batch=r,t._batchScheduleFn(()=>{h8(t,r)}),r}function h8(t,e){if(e.hasDispatched=!0,e.keys.length===0){Bp(e);return}let r;try{r=t._batchLoadFn(e.keys)}catch(n){return Np(t,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: ${String(n)}.`))}if(!r||typeof r.then!="function")return Np(t,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: ${String(r)}.`));Promise.resolve(r).then(n=>{if(!Zb(n))throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array: ${String(n)}.`);if(n.length!==e.keys.length)throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.
2
+
3
+ Keys:
4
+ ${String(e.keys)}
5
+
6
+ Values:
7
+ ${String(n)}`);Bp(e);for(let i=0;i<e.callbacks.length;i++){let s=n[i];s instanceof Error?e.callbacks[i].reject(s):e.callbacks[i].resolve(s)}}).catch(n=>{Np(t,e,n)})}function Np(t,e,r){Bp(e);for(let n=0;n<e.keys.length;n++)t.clear(e.keys[n]),e.callbacks[n].reject(r)}function Bp(t){if(t.cacheHits)for(let e=0;e<t.cacheHits.length;e++)t.cacheHits[e]()}function p8(t){if(!(!t||t.batch!==!1))return 1;let r=t&&t.maxBatchSize;if(r===void 0)return 1/0;if(typeof r!="number"||r<1)throw new TypeError(`maxBatchSize must be a positive number: ${r}`);return r}function m8(t){let e=t&&t.batchScheduleFn;if(e===void 0)return f8;if(typeof e!="function")throw new TypeError(`batchScheduleFn must be a function: ${e}`);return e}function g8(t){let e=t&&t.cacheKeyFn;if(e===void 0)return r=>r;if(typeof e!="function")throw new TypeError(`cacheKeyFn must be a function: ${e}`);return e}function y8(t){if(!(!t||t.cache!==!1))return null;let r=t&&t.cacheMap;if(r===void 0)return new Map;if(r!==null){let i=["get","set","delete","clear"].filter(s=>r&&typeof r[s]!="function");if(i.length!==0)throw new TypeError("Custom cacheMap missing methods: "+i.join(", "))}return r}function _8(t){return t&&t.name?t.name:null}function Zb(t){return typeof t=="object"&&t!==null&&"length"in t&&typeof t.length=="number"&&(t.length===0||t.length>0&&Object.prototype.hasOwnProperty.call(t,t.length-1))}});var to=be((fY,iw)=>{"use strict";var Up=Object.defineProperty,v8=Object.getOwnPropertyDescriptor,b8=Object.getOwnPropertyNames,w8=Object.prototype.hasOwnProperty,M8=(t,e)=>{for(var r in e)Up(t,r,{get:e[r],enumerable:!0})},S8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of b8(e))!w8.call(t,i)&&i!==r&&Up(t,i,{get:()=>e[i],enumerable:!(n=v8(e,i))||n.enumerable});return t},k8=t=>S8(Up({},"__esModule",{value:!0}),t),nw={};M8(nw,{DataLoader:()=>A8.DataLoader,chunk:()=>O8.chunk,fromBase58:()=>ew.fromBase58,fromBase64:()=>tw.fromBase64,fromHex:()=>rw.fromHex,promiseWithResolvers:()=>E8.promiseWithResolvers,toBase58:()=>ew.toBase58,toBase64:()=>tw.toBase64,toHex:()=>rw.toHex});iw.exports=k8(nw);var ew=Rb(),tw=$b(),rw=Vb(),O8=Hb(),E8=Xb(),A8=Qb()});var Hu=be((dY,ow)=>{"use strict";var Lp=Object.defineProperty,I8=Object.getOwnPropertyDescriptor,T8=Object.getOwnPropertyNames,x8=Object.prototype.hasOwnProperty,P8=(t,e)=>{for(var r in e)Lp(t,r,{get:e[r],enumerable:!0})},C8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T8(e))!x8.call(t,i)&&i!==r&&Lp(t,i,{get:()=>e[i],enumerable:!(n=I8(e,i))||n.enumerable});return t},j8=t=>C8(Lp({},"__esModule",{value:!0}),t),sw={};P8(sw,{ulebDecode:()=>D8,ulebEncode:()=>N8});ow.exports=j8(sw);function N8(t){let e=[],r=0;if(t===0)return[0];for(;t>0;)e[r]=t&127,(t>>=7)&&(e[r]|=128),r+=1;return e}function D8(t){let e=0,r=0,n=0;for(;;){let i=t[n];if(n+=1,e|=(i&127)<<r,(i&128)===0)break;r+=7}return{value:e,length:n}}});var qp=be((hY,uw)=>{"use strict";var Fp=Object.defineProperty,B8=Object.getOwnPropertyDescriptor,R8=Object.getOwnPropertyNames,U8=Object.prototype.hasOwnProperty,L8=(t,e)=>{for(var r in e)Fp(t,r,{get:e[r],enumerable:!0})},$8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R8(e))!U8.call(t,i)&&i!==r&&Fp(t,i,{get:()=>e[i],enumerable:!(n=B8(e,i))||n.enumerable});return t},F8=t=>$8(Fp({},"__esModule",{value:!0}),t),aw={};L8(aw,{BcsReader:()=>$p});uw.exports=F8(aw);var q8=Hu(),$p=class{constructor(e){this.bytePosition=0,this.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength)}shift(e){return this.bytePosition+=e,this}read8(){let e=this.dataView.getUint8(this.bytePosition);return this.shift(1),e}read16(){let e=this.dataView.getUint16(this.bytePosition,!0);return this.shift(2),e}read32(){let e=this.dataView.getUint32(this.bytePosition,!0);return this.shift(4),e}read64(){let e=this.read32(),n=this.read32().toString(16)+e.toString(16).padStart(8,"0");return BigInt("0x"+n).toString(10)}read128(){let e=BigInt(this.read64()),n=BigInt(this.read64()).toString(16)+e.toString(16).padStart(16,"0");return BigInt("0x"+n).toString(10)}read256(){let e=BigInt(this.read128()),n=BigInt(this.read128()).toString(16)+e.toString(16).padStart(32,"0");return BigInt("0x"+n).toString(10)}readBytes(e){let r=this.bytePosition+this.dataView.byteOffset,n=new Uint8Array(this.dataView.buffer,r,e);return this.shift(e),n}readULEB(){let e=this.bytePosition+this.dataView.byteOffset,r=new Uint8Array(this.dataView.buffer,e),{value:n,length:i}=(0,q8.ulebDecode)(r);return this.shift(i),n}readVec(e){let r=this.readULEB(),n=[];for(let i=0;i<r;i++)n.push(e(this,i,r));return n}}});var zp=be((pY,lw)=>{"use strict";var Vp=Object.defineProperty,V8=Object.getOwnPropertyDescriptor,z8=Object.getOwnPropertyNames,G8=Object.prototype.hasOwnProperty,H8=(t,e)=>{for(var r in e)Vp(t,r,{get:e[r],enumerable:!0})},W8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z8(e))!G8.call(t,i)&&i!==r&&Vp(t,i,{get:()=>e[i],enumerable:!(n=V8(e,i))||n.enumerable});return t},K8=t=>W8(Vp({},"__esModule",{value:!0}),t),cw={};H8(cw,{decodeStr:()=>J8,encodeStr:()=>X8,splitGenericParameters:()=>Z8});lw.exports=K8(cw);var Pa=to();function X8(t,e){switch(e){case"base58":return(0,Pa.toBase58)(t);case"base64":return(0,Pa.toBase64)(t);case"hex":return(0,Pa.toHex)(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function J8(t,e){switch(e){case"base58":return(0,Pa.fromBase58)(t);case"base64":return(0,Pa.fromBase64)(t);case"hex":return(0,Pa.fromHex)(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function Z8(t,e=["<",">"]){let[r,n]=e,i=[],s="",o=0;for(let u=0;u<t.length;u++){let c=t[u];if(c===r&&o++,c===n&&o--,o===0&&c===","){i.push(s.trim()),s="";continue}s+=c}return i.push(s.trim()),i}});var Kp=be((mY,dw)=>{"use strict";var Wp=Object.defineProperty,Y8=Object.getOwnPropertyDescriptor,Q8=Object.getOwnPropertyNames,e4=Object.prototype.hasOwnProperty,t4=(t,e)=>{for(var r in e)Wp(t,r,{get:e[r],enumerable:!0})},r4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Q8(e))!e4.call(t,i)&&i!==r&&Wp(t,i,{get:()=>e[i],enumerable:!(n=Y8(e,i))||n.enumerable});return t},n4=t=>r4(Wp({},"__esModule",{value:!0}),t),fw={};t4(fw,{BcsWriter:()=>Hp});dw.exports=n4(fw);var i4=Hu(),s4=zp(),Hp=class{constructor({initialSize:e=1024,maxSize:r=1/0,allocateSize:n=1024}={}){this.bytePosition=0,this.size=e,this.maxSize=r,this.allocateSize=n,this.dataView=new DataView(new ArrayBuffer(e))}ensureSizeOrGrow(e){let r=this.bytePosition+e;if(r>this.size){let n=Math.min(this.maxSize,this.size+this.allocateSize);if(r>n)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${r}`);this.size=n;let i=new ArrayBuffer(this.size);new Uint8Array(i).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(i)}}shift(e){return this.bytePosition+=e,this}write8(e){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(e)),this.shift(1)}write16(e){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(e),!0),this.shift(2)}write32(e){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(e),!0),this.shift(4)}write64(e){return Gp(BigInt(e),8).forEach(r=>this.write8(r)),this}write128(e){return Gp(BigInt(e),16).forEach(r=>this.write8(r)),this}write256(e){return Gp(BigInt(e),32).forEach(r=>this.write8(r)),this}writeULEB(e){return(0,i4.ulebEncode)(e).forEach(r=>this.write8(r)),this}writeVec(e,r){return this.writeULEB(e.length),Array.from(e).forEach((n,i)=>r(this,n,i,e.length)),this}*[Symbol.iterator](){for(let e=0;e<this.bytePosition;e++)yield this.dataView.getUint8(e);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(e){return(0,s4.encodeStr)(this.toBytes(),e)}};function Gp(t,e){let r=new Uint8Array(e),n=0;for(;t>0;)r[n]=Number(t%BigInt(256)),t=t/BigInt(256),n+=1;return r}});var Zp=be((gY,_w)=>{"use strict";var Xp=Object.defineProperty,o4=Object.getOwnPropertyDescriptor,a4=Object.getOwnPropertyNames,u4=Object.prototype.hasOwnProperty,hw=t=>{throw TypeError(t)},c4=(t,e)=>{for(var r in e)Xp(t,r,{get:e[r],enumerable:!0})},l4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a4(e))!u4.call(t,i)&&i!==r&&Xp(t,i,{get:()=>e[i],enumerable:!(n=o4(e,i))||n.enumerable});return t},f4=t=>l4(Xp({},"__esModule",{value:!0}),t),pw=(t,e,r)=>e.has(t)||hw("Cannot "+r),yi=(t,e,r)=>(pw(t,e,"read from private field"),r?r.call(t):e.get(t)),Gl=(t,e,r)=>e.has(t)?hw("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Hl=(t,e,r,n)=>(pw(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),mw={};c4(mw,{BcsType:()=>Ku,SerializedBcs:()=>Wl,bigUIntBcsType:()=>_4,dynamicSizeBcsType:()=>v4,fixedSizeBcsType:()=>Jp,isSerializedBcs:()=>g4,lazyBcsType:()=>w4,stringLikeBcsType:()=>b4,uIntBcsType:()=>y4});_w.exports=f4(mw);var ja=to(),d4=qp(),h4=Hu(),p4=Kp(),Ca,Wu,zl,ro,m4=class gw{constructor(e){Gl(this,Ca),Gl(this,Wu),this.name=e.name,this.read=e.read,this.serializedSize=e.serializedSize??(()=>null),Hl(this,Ca,e.write),Hl(this,Wu,e.serialize??((r,n)=>{let i=new p4.BcsWriter({initialSize:this.serializedSize(r)??void 0,...n});return yi(this,Ca).call(this,r,i),i.toBytes()})),this.validate=e.validate??(()=>{})}write(e,r){this.validate(e),yi(this,Ca).call(this,e,r)}serialize(e,r){return this.validate(e),new Wl(this,yi(this,Wu).call(this,e,r))}parse(e){let r=new d4.BcsReader(e);return this.read(r)}fromHex(e){return this.parse((0,ja.fromHex)(e))}fromBase58(e){return this.parse((0,ja.fromBase58)(e))}fromBase64(e){return this.parse((0,ja.fromBase64)(e))}transform({name:e,input:r,output:n,validate:i}){return new gw({name:e??this.name,read:s=>n?n(this.read(s)):this.read(s),write:(s,o)=>yi(this,Ca).call(this,r?r(s):s,o),serializedSize:s=>this.serializedSize(r?r(s):s),serialize:(s,o)=>yi(this,Wu).call(this,r?r(s):s,o),validate:s=>{i?.(s),this.validate(r?r(s):s)}})}};Ca=new WeakMap;Wu=new WeakMap;var Ku=m4,yw=Symbol.for("@mysten/serialized-bcs");function g4(t){return!!t&&typeof t=="object"&&t[yw]===!0}var Wl=class{constructor(e,r){Gl(this,zl),Gl(this,ro),Hl(this,zl,e),Hl(this,ro,r)}get[yw](){return!0}toBytes(){return yi(this,ro)}toHex(){return(0,ja.toHex)(yi(this,ro))}toBase64(){return(0,ja.toBase64)(yi(this,ro))}toBase58(){return(0,ja.toBase58)(yi(this,ro))}parse(){return yi(this,zl).parse(yi(this,ro))}};zl=new WeakMap;ro=new WeakMap;function Jp({size:t,...e}){return new Ku({...e,serializedSize:()=>t})}function y4({readMethod:t,writeMethod:e,...r}){return Jp({...r,read:n=>n[t](),write:(n,i)=>i[e](n),validate:n=>{if(n<0||n>r.maxValue)throw new TypeError(`Invalid ${r.name} value: ${n}. Expected value in range 0-${r.maxValue}`);r.validate?.(n)}})}function _4({readMethod:t,writeMethod:e,...r}){return Jp({...r,read:n=>n[t](),write:(n,i)=>i[e](BigInt(n)),validate:n=>{let i=BigInt(n);if(i<0||i>r.maxValue)throw new TypeError(`Invalid ${r.name} value: ${i}. Expected value in range 0-${r.maxValue}`);r.validate?.(i)}})}function v4({serialize:t,...e}){let r=new Ku({...e,serialize:t,write:(n,i)=>{for(let s of r.serialize(n).toBytes())i.write8(s)}});return r}function b4({toBytes:t,fromBytes:e,...r}){return new Ku({...r,read:n=>{let i=n.readULEB(),s=n.readBytes(i);return e(s)},write:(n,i)=>{let s=t(n);i.writeULEB(s.length);for(let o=0;o<s.length;o++)i.write8(s[o])},serialize:n=>{let i=t(n),s=(0,h4.ulebEncode)(i.length),o=new Uint8Array(s.length+i.length);return o.set(s,0),o.set(i,s.length),o},validate:n=>{if(typeof n!="string")throw new TypeError(`Invalid ${r.name} value: ${n}. Expected string`);r.validate?.(n)}})}function w4(t){let e=null;function r(){return e||(e=t()),e}return new Ku({name:"lazy",read:n=>r().read(n),serializedSize:n=>r().serializedSize(n),write:(n,i)=>r().write(n,i),serialize:(n,i)=>r().serialize(n,i).toBytes()})}});var Mw=be((yY,ww)=>{"use strict";var Yp=Object.defineProperty,M4=Object.getOwnPropertyDescriptor,S4=Object.getOwnPropertyNames,k4=Object.prototype.hasOwnProperty,O4=(t,e)=>{for(var r in e)Yp(t,r,{get:e[r],enumerable:!0})},E4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of S4(e))!k4.call(t,i)&&i!==r&&Yp(t,i,{get:()=>e[i],enumerable:!(n=M4(e,i))||n.enumerable});return t},A4=t=>E4(Yp({},"__esModule",{value:!0}),t),bw={};O4(bw,{bcs:()=>Kl});ww.exports=A4(bw);var jr=Zp(),vw=Hu(),Kl={u8(t){return(0,jr.uIntBcsType)({name:"u8",readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...t})},u16(t){return(0,jr.uIntBcsType)({name:"u16",readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...t})},u32(t){return(0,jr.uIntBcsType)({name:"u32",readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...t})},u64(t){return(0,jr.bigUIntBcsType)({name:"u64",readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...t})},u128(t){return(0,jr.bigUIntBcsType)({name:"u128",readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...t})},u256(t){return(0,jr.bigUIntBcsType)({name:"u256",readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...t})},bool(t){return(0,jr.fixedSizeBcsType)({name:"bool",size:1,read:e=>e.read8()===1,write:(e,r)=>r.write8(e?1:0),...t,validate:e=>{if(t?.validate?.(e),typeof e!="boolean")throw new TypeError(`Expected boolean, found ${typeof e}`)}})},uleb128(t){return(0,jr.dynamicSizeBcsType)({name:"uleb128",read:e=>e.readULEB(),serialize:e=>Uint8Array.from((0,vw.ulebEncode)(e)),...t})},bytes(t,e){return(0,jr.fixedSizeBcsType)({name:`bytes[${t}]`,size:t,read:r=>r.readBytes(t),write:(r,n)=>{let i=new Uint8Array(r);for(let s=0;s<t;s++)n.write8(i[s]??0)},...e,validate:r=>{if(e?.validate?.(r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`);if(r.length!==t)throw new TypeError(`Expected array of length ${t}, found ${r.length}`)}})},byteVector(t){return new jr.BcsType({name:"bytesVector",read:e=>{let r=e.readULEB();return e.readBytes(r)},write:(e,r)=>{let n=new Uint8Array(e);r.writeULEB(n.length);for(let i=0;i<n.length;i++)r.write8(n[i]??0)},...t,serializedSize:e=>{let r="length"in e?e.length:null;return r==null?null:(0,vw.ulebEncode)(r).length+r},validate:e=>{if(t?.validate?.(e),!e||typeof e!="object"||!("length"in e))throw new TypeError(`Expected array, found ${typeof e}`)}})},string(t){return(0,jr.stringLikeBcsType)({name:"string",toBytes:e=>new TextEncoder().encode(e),fromBytes:e=>new TextDecoder().decode(e),...t})},fixedArray(t,e,r){return new jr.BcsType({name:`${e.name}[${t}]`,read:n=>{let i=new Array(t);for(let s=0;s<t;s++)i[s]=e.read(n);return i},write:(n,i)=>{for(let s of n)e.write(s,i)},...r,validate:n=>{if(r?.validate?.(n),!n||typeof n!="object"||!("length"in n))throw new TypeError(`Expected array, found ${typeof n}`);if(n.length!==t)throw new TypeError(`Expected array of length ${t}, found ${n.length}`)}})},option(t){return Kl.enum(`Option<${t.name}>`,{None:null,Some:t}).transform({input:e=>e==null?{None:!0}:{Some:e},output:e=>e.$kind==="Some"?e.Some:null})},vector(t,e){return new jr.BcsType({name:`vector<${t.name}>`,read:r=>{let n=r.readULEB(),i=new Array(n);for(let s=0;s<n;s++)i[s]=t.read(r);return i},write:(r,n)=>{n.writeULEB(r.length);for(let i of r)t.write(i,n)},...e,validate:r=>{if(e?.validate?.(r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`)}})},tuple(t,e){return new jr.BcsType({name:`(${t.map(r=>r.name).join(", ")})`,serializedSize:r=>{let n=0;for(let i=0;i<t.length;i++){let s=t[i].serializedSize(r[i]);if(s==null)return null;n+=s}return n},read:r=>{let n=[];for(let i of t)n.push(i.read(r));return n},write:(r,n)=>{for(let i=0;i<t.length;i++)t[i].write(r[i],n)},...e,validate:r=>{if(e?.validate?.(r),!Array.isArray(r))throw new TypeError(`Expected array, found ${typeof r}`);if(r.length!==t.length)throw new TypeError(`Expected array of length ${t.length}, found ${r.length}`)}})},struct(t,e,r){let n=Object.entries(e);return new jr.BcsType({name:t,serializedSize:i=>{let s=0;for(let[o,u]of n){let c=u.serializedSize(i[o]);if(c==null)return null;s+=c}return s},read:i=>{let s={};for(let[o,u]of n)s[o]=u.read(i);return s},write:(i,s)=>{for(let[o,u]of n)u.write(i[o],s)},...r,validate:i=>{if(r?.validate?.(i),typeof i!="object"||i==null)throw new TypeError(`Expected object, found ${typeof i}`)}})},enum(t,e,r){let n=Object.entries(e);return new jr.BcsType({name:t,read:i=>{let s=i.readULEB(),o=n[s];if(!o)throw new TypeError(`Unknown value ${s} for enum ${t}`);let[u,c]=o;return{[u]:c?.read(i)??!0,$kind:u}},write:(i,s)=>{let[o,u]=Object.entries(i).filter(([c])=>Object.hasOwn(e,c))[0];for(let c=0;c<n.length;c++){let[d,p]=n[c];if(d===o){s.writeULEB(c),p?.write(u,s);return}}},...r,validate:i=>{if(r?.validate?.(i),typeof i!="object"||i==null)throw new TypeError(`Expected object, found ${typeof i}`);let s=Object.keys(i).filter(u=>i[u]!==void 0&&Object.hasOwn(e,u));if(s.length!==1)throw new TypeError(`Expected object with one key, but found ${s.length} for type ${t}}`);let[o]=s;if(!Object.hasOwn(e,o))throw new TypeError(`Invalid enum variant ${o}`)}})},map(t,e){return Kl.vector(Kl.tuple([t,e])).transform({name:`Map<${t.name}, ${e.name}>`,input:r=>[...r.entries()],output:r=>{let n=new Map;for(let[i,s]of r)n.set(i,s);return n}})},lazy(t){return(0,jr.lazyBcsType)(t)}}});var dr=be((_Y,kw)=>{"use strict";var t0=Object.defineProperty,I4=Object.getOwnPropertyDescriptor,T4=Object.getOwnPropertyNames,x4=Object.prototype.hasOwnProperty,P4=(t,e)=>{for(var r in e)t0(t,r,{get:e[r],enumerable:!0})},C4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T4(e))!x4.call(t,i)&&i!==r&&t0(t,i,{get:()=>e[i],enumerable:!(n=I4(e,i))||n.enumerable});return t},j4=t=>C4(t0({},"__esModule",{value:!0}),t),Sw={};P4(Sw,{BcsReader:()=>D4.BcsReader,BcsType:()=>Qp.BcsType,BcsWriter:()=>B4.BcsWriter,SerializedBcs:()=>Qp.SerializedBcs,bcs:()=>N4.bcs,decodeStr:()=>e0.decodeStr,encodeStr:()=>e0.encodeStr,fromB58:()=>U4,fromB64:()=>$4,fromBase58:()=>Bn.fromBase58,fromBase64:()=>Bn.fromBase64,fromHEX:()=>q4,fromHex:()=>Bn.fromHex,isSerializedBcs:()=>Qp.isSerializedBcs,splitGenericParameters:()=>e0.splitGenericParameters,toB58:()=>R4,toB64:()=>L4,toBase58:()=>Bn.toBase58,toBase64:()=>Bn.toBase64,toHEX:()=>F4,toHex:()=>Bn.toHex});kw.exports=j4(Sw);var Bn=to(),Qp=Zp(),N4=Mw(),D4=qp(),e0=zp(),B4=Kp(),R4=Bn.toBase58,U4=Bn.fromBase58,L4=Bn.toBase64,$4=Bn.fromBase64,F4=Bn.toHex,q4=Bn.fromHex});var Xl=be((vY,Iw)=>{"use strict";var r0=Object.defineProperty,V4=Object.getOwnPropertyDescriptor,z4=Object.getOwnPropertyNames,G4=Object.prototype.hasOwnProperty,H4=(t,e)=>{for(var r in e)r0(t,r,{get:e[r],enumerable:!0})},W4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z4(e))!G4.call(t,i)&&i!==r&&r0(t,i,{get:()=>e[i],enumerable:!(n=V4(e,i))||n.enumerable});return t},K4=t=>W4(r0({},"__esModule",{value:!0}),t),Ow={};H4(Ow,{isValidSuiNSName:()=>J4,normalizeSuiNSName:()=>Z4});Iw.exports=K4(Ow);var Ew=/^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i,Aw=/^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i,X4=235;function J4(t){return t.length>X4?!1:t.includes("@")?Ew.test(t):Aw.test(t)}function Z4(t,e="at"){let r=t.toLowerCase(),n;if(r.includes("@")){if(!Ew.test(r))throw new Error(`Invalid SuiNS name ${t}`);let[i,s]=r.split("@");n=[...i?i.split("."):[],s]}else{if(!Aw.test(r))throw new Error(`Invalid SuiNS name ${t}`);n=r.split(".").slice(0,-1)}return e==="dot"?`${n.join(".")}.sui`:`${n.slice(0,-1).join(".")}@${n[n.length-1]}`}});var Xu=be((bY,Cw)=>{"use strict";var n0=Object.defineProperty,Y4=Object.getOwnPropertyDescriptor,Q4=Object.getOwnPropertyNames,ej=Object.prototype.hasOwnProperty,tj=(t,e)=>{for(var r in e)n0(t,r,{get:e[r],enumerable:!0})},rj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Q4(e))!ej.call(t,i)&&i!==r&&n0(t,i,{get:()=>e[i],enumerable:!(n=Y4(e,i))||n.enumerable});return t},nj=t=>rj(n0({},"__esModule",{value:!0}),t),Tw={};tj(Tw,{isValidNamedPackage:()=>Pw,isValidNamedType:()=>uj});Cw.exports=nj(Tw);var ij=Xl(),sj=/^([a-z0-9]+(?:-[a-z0-9]+)*)$/,oj=/^\d+$/,aj=64,xw="/",Pw=t=>{let e=t.split(xw);if(e.length<2||e.length>3)return!1;let[r,n,i]=e;return i!==void 0&&!oj.test(i)||!(0,ij.isValidSuiNSName)(r)?!1:sj.test(n)&&n.length<aj},uj=t=>{let e=t.split(/::|<|>|,/);for(let r of e)if(r.includes(xw)&&!Pw(r))return!1;return!0}});var Nr=be((wY,Rw)=>{"use strict";var i0=Object.defineProperty,cj=Object.getOwnPropertyDescriptor,lj=Object.getOwnPropertyNames,fj=Object.prototype.hasOwnProperty,dj=(t,e)=>{for(var r in e)i0(t,r,{get:e[r],enumerable:!0})},hj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lj(e))!fj.call(t,i)&&i!==r&&i0(t,i,{get:()=>e[i],enumerable:!(n=cj(e,i))||n.enumerable});return t},pj=t=>hj(i0({},"__esModule",{value:!0}),t),jw={};dj(jw,{SUI_ADDRESS_LENGTH:()=>s0,isValidSuiAddress:()=>Dw,isValidSuiObjectId:()=>_j,isValidTransactionDigest:()=>yj,normalizeStructTag:()=>Bw,normalizeSuiAddress:()=>a0,normalizeSuiObjectId:()=>bj,parseStructTag:()=>o0});Rw.exports=pj(jw);var Nw=dr(),mj=Xu(),gj=32;function yj(t){try{return(0,Nw.fromBase58)(t).length===gj}catch{return!1}}var s0=32;function Dw(t){return wj(t)&&Mj(t)===s0}function _j(t){return Dw(t)}function vj(t){return t.includes("::")?o0(t):t}function o0(t){let[e,r]=t.split("::"),n=(0,mj.isValidNamedPackage)(e),i=t.slice(e.length+r.length+4),s=i.includes("<")?i.slice(0,i.indexOf("<")):i,o=i.includes("<")?(0,Nw.splitGenericParameters)(i.slice(i.indexOf("<")+1,i.lastIndexOf(">"))).map(u=>vj(u.trim())):[];return{address:n?e:a0(e),module:r,name:s,typeParams:o}}function Bw(t){let{address:e,module:r,name:n,typeParams:i}=typeof t=="string"?o0(t):t,s=i?.length>0?`<${i.map(o=>typeof o=="string"?o:Bw(o)).join(",")}>`:"";return`${e}::${r}::${n}${s}`}function a0(t,e=!1){let r=t.toLowerCase();return!e&&r.startsWith("0x")&&(r=r.slice(2)),`0x${r.padStart(s0*2,"0")}`}function bj(t,e=!1){return a0(t,e)}function wj(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2===0}function Mj(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}});var Jl=be((MY,Lw)=>{"use strict";var c0=Object.defineProperty,Sj=Object.getOwnPropertyDescriptor,kj=Object.getOwnPropertyNames,Oj=Object.prototype.hasOwnProperty,Ej=(t,e)=>{for(var r in e)c0(t,r,{get:e[r],enumerable:!0})},Aj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of kj(e))!Oj.call(t,i)&&i!==r&&c0(t,i,{get:()=>e[i],enumerable:!(n=Sj(e,i))||n.enumerable});return t},Ij=t=>Aj(c0({},"__esModule",{value:!0}),t),Uw={};Ej(Uw,{TypeTagSerializer:()=>u0});Lw.exports=Ij(Uw);var Tj=dr(),xj=Nr(),Pj=/^vector<(.+)>$/,Cj=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/,u0=class t{static parseFromStr(e,r=!1){if(e==="address")return{address:null};if(e==="bool")return{bool:null};if(e==="u8")return{u8:null};if(e==="u16")return{u16:null};if(e==="u32")return{u32:null};if(e==="u64")return{u64:null};if(e==="u128")return{u128:null};if(e==="u256")return{u256:null};if(e==="signer")return{signer:null};let n=e.match(Pj);if(n)return{vector:t.parseFromStr(n[1],r)};let i=e.match(Cj);if(i)return{struct:{address:r?(0,xj.normalizeSuiAddress)(i[1]):i[1],module:i[2],name:i[3],typeParams:i[5]===void 0?[]:t.parseStructTypeArgs(i[5],r)}};throw new Error(`Encountered unexpected token when parsing type args for ${e}`)}static parseStructTypeArgs(e,r=!1){return(0,Tj.splitGenericParameters)(e).map(n=>t.parseFromStr(n,r))}static tagToString(e){if("bool"in e)return"bool";if("u8"in e)return"u8";if("u16"in e)return"u16";if("u32"in e)return"u32";if("u64"in e)return"u64";if("u128"in e)return"u128";if("u256"in e)return"u256";if("address"in e)return"address";if("signer"in e)return"signer";if("vector"in e)return`vector<${t.tagToString(e.vector)}>`;if("struct"in e){let r=e.struct,n=r.typeParams.map(t.tagToString).join(", ");return`${r.address}::${r.module}::${r.name}${n?`<${n}>`:""}`}throw new Error("Invalid TypeTag")}}});var Yl=be((SY,d1)=>{"use strict";var l0=Object.defineProperty,jj=Object.getOwnPropertyDescriptor,Nj=Object.getOwnPropertyNames,Dj=Object.prototype.hasOwnProperty,Bj=(t,e)=>{for(var r in e)l0(t,r,{get:e[r],enumerable:!0})},Rj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Nj(e))!Dj.call(t,i)&&i!==r&&l0(t,i,{get:()=>e[i],enumerable:!(n=jj(e,i))||n.enumerable});return t},Uj=t=>Rj(l0({},"__esModule",{value:!0}),t),Fw={};Bj(Fw,{Address:()=>wn,AppId:()=>n1,Argument:()=>qi,CallArg:()=>Gw,Command:()=>Ww,CompressedSignature:()=>o1,GasData:()=>Yw,Intent:()=>i1,IntentMessage:()=>s1,IntentScope:()=>t1,IntentVersion:()=>r1,MultiSig:()=>qj,MultiSigPkMap:()=>u1,MultiSigPublicKey:()=>c1,ObjectArg:()=>zw,ObjectDigest:()=>qw,Owner:()=>Fj,PasskeyAuthenticator:()=>zj,ProgrammableMoveCall:()=>Hw,ProgrammableTransaction:()=>Kw,PublicKey:()=>a1,SenderSignedData:()=>Vj,SenderSignedTransaction:()=>f1,SharedObjectRef:()=>Vw,StructTag:()=>Zw,SuiObjectRef:()=>Zl,TransactionData:()=>e1,TransactionDataV1:()=>Qw,TransactionExpiration:()=>Jw,TransactionKind:()=>Xw,TypeTag:()=>d0,base64String:()=>l1});d1.exports=Uj(Fw);var se=dr(),Ju=Nr(),$w=Jl();function Lj(t){return se.bcs.u64({name:"unsafe_u64",...t}).transform({input:e=>e,output:e=>Number(e)})}function $j(t){return se.bcs.enum("Option",{None:null,Some:t})}var wn=se.bcs.bytes(Ju.SUI_ADDRESS_LENGTH).transform({validate:t=>{let e=typeof t=="string"?t:(0,se.toHex)(t);if(!e||!(0,Ju.isValidSuiAddress)((0,Ju.normalizeSuiAddress)(e)))throw new Error(`Invalid Sui address ${e}`)},input:t=>typeof t=="string"?(0,se.fromHex)((0,Ju.normalizeSuiAddress)(t)):t,output:t=>(0,Ju.normalizeSuiAddress)((0,se.toHex)(t))}),qw=se.bcs.vector(se.bcs.u8()).transform({name:"ObjectDigest",input:t=>(0,se.fromBase58)(t),output:t=>(0,se.toBase58)(new Uint8Array(t)),validate:t=>{if((0,se.fromBase58)(t).length!==32)throw new Error("ObjectDigest must be 32 bytes")}}),Zl=se.bcs.struct("SuiObjectRef",{objectId:wn,version:se.bcs.u64(),digest:qw}),Vw=se.bcs.struct("SharedObjectRef",{objectId:wn,initialSharedVersion:se.bcs.u64(),mutable:se.bcs.bool()}),zw=se.bcs.enum("ObjectArg",{ImmOrOwnedObject:Zl,SharedObject:Vw,Receiving:Zl}),Fj=se.bcs.enum("Owner",{AddressOwner:wn,ObjectOwner:wn,Shared:se.bcs.struct("Shared",{initialSharedVersion:se.bcs.u64()}),Immutable:null,ConsensusV2:se.bcs.struct("ConsensusV2",{authenticator:se.bcs.enum("Authenticator",{SingleOwner:wn}),startVersion:se.bcs.u64()})}),Gw=se.bcs.enum("CallArg",{Pure:se.bcs.struct("Pure",{bytes:se.bcs.vector(se.bcs.u8()).transform({input:t=>typeof t=="string"?(0,se.fromBase64)(t):t,output:t=>(0,se.toBase64)(new Uint8Array(t))})}),Object:zw}),f0=se.bcs.enum("TypeTag",{bool:null,u8:null,u64:null,u128:null,address:null,signer:null,vector:se.bcs.lazy(()=>f0),struct:se.bcs.lazy(()=>Zw),u16:null,u32:null,u256:null}),d0=f0.transform({input:t=>typeof t=="string"?$w.TypeTagSerializer.parseFromStr(t,!0):t,output:t=>$w.TypeTagSerializer.tagToString(t)}),qi=se.bcs.enum("Argument",{GasCoin:null,Input:se.bcs.u16(),Result:se.bcs.u16(),NestedResult:se.bcs.tuple([se.bcs.u16(),se.bcs.u16()])}),Hw=se.bcs.struct("ProgrammableMoveCall",{package:wn,module:se.bcs.string(),function:se.bcs.string(),typeArguments:se.bcs.vector(d0),arguments:se.bcs.vector(qi)}),Ww=se.bcs.enum("Command",{MoveCall:Hw,TransferObjects:se.bcs.struct("TransferObjects",{objects:se.bcs.vector(qi),address:qi}),SplitCoins:se.bcs.struct("SplitCoins",{coin:qi,amounts:se.bcs.vector(qi)}),MergeCoins:se.bcs.struct("MergeCoins",{destination:qi,sources:se.bcs.vector(qi)}),Publish:se.bcs.struct("Publish",{modules:se.bcs.vector(se.bcs.vector(se.bcs.u8()).transform({input:t=>typeof t=="string"?(0,se.fromBase64)(t):t,output:t=>(0,se.toBase64)(new Uint8Array(t))})),dependencies:se.bcs.vector(wn)}),MakeMoveVec:se.bcs.struct("MakeMoveVec",{type:$j(d0).transform({input:t=>t===null?{None:!0}:{Some:t},output:t=>t.Some??null}),elements:se.bcs.vector(qi)}),Upgrade:se.bcs.struct("Upgrade",{modules:se.bcs.vector(se.bcs.vector(se.bcs.u8()).transform({input:t=>typeof t=="string"?(0,se.fromBase64)(t):t,output:t=>(0,se.toBase64)(new Uint8Array(t))})),dependencies:se.bcs.vector(wn),package:wn,ticket:qi})}),Kw=se.bcs.struct("ProgrammableTransaction",{inputs:se.bcs.vector(Gw),commands:se.bcs.vector(Ww)}),Xw=se.bcs.enum("TransactionKind",{ProgrammableTransaction:Kw,ChangeEpoch:null,Genesis:null,ConsensusCommitPrologue:null}),Jw=se.bcs.enum("TransactionExpiration",{None:null,Epoch:Lj()}),Zw=se.bcs.struct("StructTag",{address:wn,module:se.bcs.string(),name:se.bcs.string(),typeParams:se.bcs.vector(f0)}),Yw=se.bcs.struct("GasData",{payment:se.bcs.vector(Zl),owner:wn,price:se.bcs.u64(),budget:se.bcs.u64()}),Qw=se.bcs.struct("TransactionDataV1",{kind:Xw,sender:wn,gasData:Yw,expiration:Jw}),e1=se.bcs.enum("TransactionData",{V1:Qw}),t1=se.bcs.enum("IntentScope",{TransactionData:null,TransactionEffects:null,CheckpointSummary:null,PersonalMessage:null}),r1=se.bcs.enum("IntentVersion",{V0:null}),n1=se.bcs.enum("AppId",{Sui:null}),i1=se.bcs.struct("Intent",{scope:t1,version:r1,appId:n1});function s1(t){return se.bcs.struct(`IntentMessage<${t.name}>`,{intent:i1,value:t})}var o1=se.bcs.enum("CompressedSignature",{ED25519:se.bcs.fixedArray(64,se.bcs.u8()),Secp256k1:se.bcs.fixedArray(64,se.bcs.u8()),Secp256r1:se.bcs.fixedArray(64,se.bcs.u8()),ZkLogin:se.bcs.vector(se.bcs.u8())}),a1=se.bcs.enum("PublicKey",{ED25519:se.bcs.fixedArray(32,se.bcs.u8()),Secp256k1:se.bcs.fixedArray(33,se.bcs.u8()),Secp256r1:se.bcs.fixedArray(33,se.bcs.u8()),ZkLogin:se.bcs.vector(se.bcs.u8())}),u1=se.bcs.struct("MultiSigPkMap",{pubKey:a1,weight:se.bcs.u8()}),c1=se.bcs.struct("MultiSigPublicKey",{pk_map:se.bcs.vector(u1),threshold:se.bcs.u16()}),qj=se.bcs.struct("MultiSig",{sigs:se.bcs.vector(o1),bitmap:se.bcs.u16(),multisig_pk:c1}),l1=se.bcs.vector(se.bcs.u8()).transform({input:t=>typeof t=="string"?(0,se.fromBase64)(t):t,output:t=>(0,se.toBase64)(new Uint8Array(t))}),f1=se.bcs.struct("SenderSignedTransaction",{intentMessage:s1(e1),txSignatures:se.bcs.vector(l1)}),Vj=se.bcs.vector(f1,{name:"SenderSignedData"}),zj=se.bcs.struct("PasskeyAuthenticator",{authenticatorData:se.bcs.vector(se.bcs.u8()),clientDataJson:se.bcs.string(),userSignature:se.bcs.vector(se.bcs.u8())})});var _1=be((kY,y1)=>{"use strict";var h0=Object.defineProperty,Gj=Object.getOwnPropertyDescriptor,Hj=Object.getOwnPropertyNames,Wj=Object.prototype.hasOwnProperty,Kj=(t,e)=>{for(var r in e)h0(t,r,{get:e[r],enumerable:!0})},Xj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Hj(e))!Wj.call(t,i)&&i!==r&&h0(t,i,{get:()=>e[i],enumerable:!(n=Gj(e,i))||n.enumerable});return t},Jj=t=>Xj(h0({},"__esModule",{value:!0}),t),p1={};Kj(p1,{TransactionEffects:()=>c5});y1.exports=Jj(p1);var ue=dr(),Et=Yl(),Zj=ue.bcs.enum("PackageUpgradeError",{UnableToFetchPackage:ue.bcs.struct("UnableToFetchPackage",{packageId:Et.Address}),NotAPackage:ue.bcs.struct("NotAPackage",{objectId:Et.Address}),IncompatibleUpgrade:null,DigestDoesNotMatch:ue.bcs.struct("DigestDoesNotMatch",{digest:ue.bcs.vector(ue.bcs.u8())}),UnknownUpgradePolicy:ue.bcs.struct("UnknownUpgradePolicy",{policy:ue.bcs.u8()}),PackageIDDoesNotMatch:ue.bcs.struct("PackageIDDoesNotMatch",{packageId:Et.Address,ticketId:Et.Address})}),Yj=ue.bcs.struct("ModuleId",{address:Et.Address,name:ue.bcs.string()}),h1=ue.bcs.struct("MoveLocation",{module:Yj,function:ue.bcs.u16(),instruction:ue.bcs.u16(),functionName:ue.bcs.option(ue.bcs.string())}),Qj=ue.bcs.enum("CommandArgumentError",{TypeMismatch:null,InvalidBCSBytes:null,InvalidUsageOfPureArg:null,InvalidArgumentToPrivateEntryFunction:null,IndexOutOfBounds:ue.bcs.struct("IndexOutOfBounds",{idx:ue.bcs.u16()}),SecondaryIndexOutOfBounds:ue.bcs.struct("SecondaryIndexOutOfBounds",{resultIdx:ue.bcs.u16(),secondaryIdx:ue.bcs.u16()}),InvalidResultArity:ue.bcs.struct("InvalidResultArity",{resultIdx:ue.bcs.u16()}),InvalidGasCoinUsage:null,InvalidValueUsage:null,InvalidObjectByValue:null,InvalidObjectByMutRef:null,SharedObjectOperationNotAllowed:null}),e5=ue.bcs.enum("TypeArgumentError",{TypeNotFound:null,ConstraintNotSatisfied:null}),t5=ue.bcs.enum("ExecutionFailureStatus",{InsufficientGas:null,InvalidGasObject:null,InvariantViolation:null,FeatureNotYetSupported:null,MoveObjectTooBig:ue.bcs.struct("MoveObjectTooBig",{objectSize:ue.bcs.u64(),maxObjectSize:ue.bcs.u64()}),MovePackageTooBig:ue.bcs.struct("MovePackageTooBig",{objectSize:ue.bcs.u64(),maxObjectSize:ue.bcs.u64()}),CircularObjectOwnership:ue.bcs.struct("CircularObjectOwnership",{object:Et.Address}),InsufficientCoinBalance:null,CoinBalanceOverflow:null,PublishErrorNonZeroAddress:null,SuiMoveVerificationError:null,MovePrimitiveRuntimeError:ue.bcs.option(h1),MoveAbort:ue.bcs.tuple([h1,ue.bcs.u64()]),VMVerificationOrDeserializationError:null,VMInvariantViolation:null,FunctionNotFound:null,ArityMismatch:null,TypeArityMismatch:null,NonEntryFunctionInvoked:null,CommandArgumentError:ue.bcs.struct("CommandArgumentError",{argIdx:ue.bcs.u16(),kind:Qj}),TypeArgumentError:ue.bcs.struct("TypeArgumentError",{argumentIdx:ue.bcs.u16(),kind:e5}),UnusedValueWithoutDrop:ue.bcs.struct("UnusedValueWithoutDrop",{resultIdx:ue.bcs.u16(),secondaryIdx:ue.bcs.u16()}),InvalidPublicFunctionReturnType:ue.bcs.struct("InvalidPublicFunctionReturnType",{idx:ue.bcs.u16()}),InvalidTransferObject:null,EffectsTooLarge:ue.bcs.struct("EffectsTooLarge",{currentSize:ue.bcs.u64(),maxSize:ue.bcs.u64()}),PublishUpgradeMissingDependency:null,PublishUpgradeDependencyDowngrade:null,PackageUpgradeError:ue.bcs.struct("PackageUpgradeError",{upgradeError:Zj}),WrittenObjectsTooLarge:ue.bcs.struct("WrittenObjectsTooLarge",{currentSize:ue.bcs.u64(),maxSize:ue.bcs.u64()}),CertificateDenied:null,SuiMoveVerificationTimedout:null,SharedObjectOperationNotAllowed:null,InputObjectDeleted:null,ExecutionCancelledDueToSharedObjectCongestion:ue.bcs.struct("ExecutionCancelledDueToSharedObjectCongestion",{congestedObjects:ue.bcs.vector(Et.Address)}),AddressDeniedForCoin:ue.bcs.struct("AddressDeniedForCoin",{address:Et.Address,coinType:ue.bcs.string()}),CoinTypeGlobalPause:ue.bcs.struct("CoinTypeGlobalPause",{coinType:ue.bcs.string()}),ExecutionCancelledDueToRandomnessUnavailable:null}),m1=ue.bcs.enum("ExecutionStatus",{Success:null,Failed:ue.bcs.struct("ExecutionFailed",{error:t5,command:ue.bcs.option(ue.bcs.u64())})}),g1=ue.bcs.struct("GasCostSummary",{computationCost:ue.bcs.u64(),storageCost:ue.bcs.u64(),storageRebate:ue.bcs.u64(),nonRefundableStorageFee:ue.bcs.u64()}),r5=ue.bcs.struct("TransactionEffectsV1",{status:m1,executedEpoch:ue.bcs.u64(),gasUsed:g1,modifiedAtVersions:ue.bcs.vector(ue.bcs.tuple([Et.Address,ue.bcs.u64()])),sharedObjects:ue.bcs.vector(Et.SuiObjectRef),transactionDigest:Et.ObjectDigest,created:ue.bcs.vector(ue.bcs.tuple([Et.SuiObjectRef,Et.Owner])),mutated:ue.bcs.vector(ue.bcs.tuple([Et.SuiObjectRef,Et.Owner])),unwrapped:ue.bcs.vector(ue.bcs.tuple([Et.SuiObjectRef,Et.Owner])),deleted:ue.bcs.vector(Et.SuiObjectRef),unwrappedThenDeleted:ue.bcs.vector(Et.SuiObjectRef),wrapped:ue.bcs.vector(Et.SuiObjectRef),gasObject:ue.bcs.tuple([Et.SuiObjectRef,Et.Owner]),eventsDigest:ue.bcs.option(Et.ObjectDigest),dependencies:ue.bcs.vector(Et.ObjectDigest)}),p0=ue.bcs.tuple([ue.bcs.u64(),Et.ObjectDigest]),n5=ue.bcs.enum("ObjectIn",{NotExist:null,Exist:ue.bcs.tuple([p0,Et.Owner])}),i5=ue.bcs.enum("ObjectOut",{NotExist:null,ObjectWrite:ue.bcs.tuple([Et.ObjectDigest,Et.Owner]),PackageWrite:p0}),s5=ue.bcs.enum("IDOperation",{None:null,Created:null,Deleted:null}),o5=ue.bcs.struct("EffectsObjectChange",{inputState:n5,outputState:i5,idOperation:s5}),a5=ue.bcs.enum("UnchangedSharedKind",{ReadOnlyRoot:p0,MutateDeleted:ue.bcs.u64(),ReadDeleted:ue.bcs.u64(),Cancelled:ue.bcs.u64(),PerEpochConfig:null}),u5=ue.bcs.struct("TransactionEffectsV2",{status:m1,executedEpoch:ue.bcs.u64(),gasUsed:g1,transactionDigest:Et.ObjectDigest,gasObjectIndex:ue.bcs.option(ue.bcs.u32()),eventsDigest:ue.bcs.option(Et.ObjectDigest),dependencies:ue.bcs.vector(Et.ObjectDigest),lamportVersion:ue.bcs.u64(),changedObjects:ue.bcs.vector(ue.bcs.tuple([Et.Address,o5])),unchangedSharedObjects:ue.bcs.vector(ue.bcs.tuple([Et.Address,a5])),auxDataDigest:ue.bcs.option(Et.ObjectDigest)}),c5=ue.bcs.enum("TransactionEffects",{V1:r5,V2:u5})});var y0=be((OY,b1)=>{"use strict";var g0=Object.defineProperty,l5=Object.getOwnPropertyDescriptor,f5=Object.getOwnPropertyNames,d5=Object.prototype.hasOwnProperty,h5=(t,e)=>{for(var r in e)g0(t,r,{get:e[r],enumerable:!0})},p5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of f5(e))!d5.call(t,i)&&i!==r&&g0(t,i,{get:()=>e[i],enumerable:!(n=l5(e,i))||n.enumerable});return t},m5=t=>p5(g0({},"__esModule",{value:!0}),t),v1={};h5(v1,{pureBcsSchemaFromTypeName:()=>m0});b1.exports=m5(v1);var Vi=dr(),g5=Yl();function m0(t){switch(t){case"u8":return Vi.bcs.u8();case"u16":return Vi.bcs.u16();case"u32":return Vi.bcs.u32();case"u64":return Vi.bcs.u64();case"u128":return Vi.bcs.u128();case"u256":return Vi.bcs.u256();case"bool":return Vi.bcs.bool();case"string":return Vi.bcs.string();case"id":case"address":return g5.Address}let e=t.match(/^(vector|option)<(.+)>$/);if(e){let[r,n]=e.slice(1);return r==="vector"?Vi.bcs.vector(m0(n)):Vi.bcs.option(m0(n))}throw new Error(`Invalid Pure type name: ${t}`)}});var Rn=be((EY,M1)=>{"use strict";var _0=Object.defineProperty,y5=Object.getOwnPropertyDescriptor,_5=Object.getOwnPropertyNames,v5=Object.prototype.hasOwnProperty,b5=(t,e)=>{for(var r in e)_0(t,r,{get:e[r],enumerable:!0})},w5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _5(e))!v5.call(t,i)&&i!==r&&_0(t,i,{get:()=>e[i],enumerable:!(n=y5(e,i))||n.enumerable});return t},M5=t=>w5(_0({},"__esModule",{value:!0}),t),w1={};b5(w1,{BcsType:()=>O5.BcsType,TypeTagSerializer:()=>k5.TypeTagSerializer,bcs:()=>A5,pureBcsSchemaFromTypeName:()=>E5.pureBcsSchemaFromTypeName});M1.exports=M5(w1);var zi=dr(),Tt=Yl(),S5=_1(),k5=Jl(),O5=dr(),E5=y0(),A5={...zi.bcs,U8:zi.bcs.u8(),U16:zi.bcs.u16(),U32:zi.bcs.u32(),U64:zi.bcs.u64(),U128:zi.bcs.u128(),U256:zi.bcs.u256(),ULEB128:zi.bcs.uleb128(),Bool:zi.bcs.bool(),String:zi.bcs.string(),Address:Tt.Address,AppId:Tt.AppId,Argument:Tt.Argument,CallArg:Tt.CallArg,Command:Tt.Command,CompressedSignature:Tt.CompressedSignature,GasData:Tt.GasData,Intent:Tt.Intent,IntentMessage:Tt.IntentMessage,IntentScope:Tt.IntentScope,IntentVersion:Tt.IntentVersion,MultiSig:Tt.MultiSig,MultiSigPkMap:Tt.MultiSigPkMap,MultiSigPublicKey:Tt.MultiSigPublicKey,ObjectArg:Tt.ObjectArg,ObjectDigest:Tt.ObjectDigest,Owner:Tt.Owner,PasskeyAuthenticator:Tt.PasskeyAuthenticator,ProgrammableMoveCall:Tt.ProgrammableMoveCall,ProgrammableTransaction:Tt.ProgrammableTransaction,PublicKey:Tt.PublicKey,SenderSignedData:Tt.SenderSignedData,SenderSignedTransaction:Tt.SenderSignedTransaction,SharedObjectRef:Tt.SharedObjectRef,StructTag:Tt.StructTag,SuiObjectRef:Tt.SuiObjectRef,TransactionData:Tt.TransactionData,TransactionDataV1:Tt.TransactionDataV1,TransactionEffects:S5.TransactionEffects,TransactionExpiration:Tt.TransactionExpiration,TransactionKind:Tt.TransactionKind,TypeTag:Tt.TypeTag}});var E1=be((AY,O1)=>{"use strict";var v0=Object.defineProperty,I5=Object.getOwnPropertyDescriptor,T5=Object.getOwnPropertyNames,x5=Object.prototype.hasOwnProperty,P5=(t,e)=>{for(var r in e)v0(t,r,{get:e[r],enumerable:!0})},C5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T5(e))!x5.call(t,i)&&i!==r&&v0(t,i,{get:()=>e[i],enumerable:!(n=I5(e,i))||n.enumerable});return t},j5=t=>C5(v0({},"__esModule",{value:!0}),t),S1={};P5(S1,{formatAddress:()=>N5,formatDigest:()=>D5});O1.exports=j5(S1);var k1="\u2026";function N5(t){if(t.length<=6)return t;let e=t.startsWith("0x")?2:0;return`0x${t.slice(e,e+4)}${k1}${t.slice(-4)}`}function D5(t){return`${t.slice(0,10)}${k1}`}});var P1=be((IY,x1)=>{"use strict";var b0=Object.defineProperty,B5=Object.getOwnPropertyDescriptor,R5=Object.getOwnPropertyNames,U5=Object.prototype.hasOwnProperty,L5=(t,e)=>{for(var r in e)b0(t,r,{get:e[r],enumerable:!0})},$5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R5(e))!U5.call(t,i)&&i!==r&&b0(t,i,{get:()=>e[i],enumerable:!(n=B5(e,i))||n.enumerable});return t},F5=t=>$5(b0({},"__esModule",{value:!0}),t),A1={};L5(A1,{MIST_PER_SUI:()=>V5,MOVE_STDLIB_ADDRESS:()=>z5,SUI_CLOCK_OBJECT_ID:()=>H5,SUI_DECIMALS:()=>q5,SUI_FRAMEWORK_ADDRESS:()=>T1,SUI_SYSTEM_ADDRESS:()=>G5,SUI_SYSTEM_MODULE_NAME:()=>W5,SUI_SYSTEM_STATE_OBJECT_ID:()=>X5,SUI_TYPE_ARG:()=>K5});x1.exports=F5(A1);var I1=Nr(),q5=9,V5=BigInt(1e9),z5="0x1",T1="0x2",G5="0x3",H5=(0,I1.normalizeSuiObjectId)("0x6"),W5="sui_system",K5=`${T1}::sui::SUI`,X5=(0,I1.normalizeSuiObjectId)("0x5")});var C1=be(Ql=>{"use strict";Object.defineProperty(Ql,"__esModule",{value:!0});Ql.crypto=void 0;var no=xr("crypto");Ql.crypto=no&&typeof no=="object"&&"webcrypto"in no?no.webcrypto:no&&typeof no=="object"&&"randomBytes"in no?no:void 0});var tf=be(Ze=>{"use strict";Object.defineProperty(Ze,"__esModule",{value:!0});Ze.wrapXOFConstructorWithOpts=Ze.wrapConstructorWithOpts=Ze.wrapConstructor=Ze.Hash=Ze.nextTick=Ze.swap32IfBE=Ze.byteSwapIfBE=Ze.swap8IfBE=Ze.isLE=void 0;Ze.isBytes=N1;Ze.anumber=w0;Ze.abytes=Da;Ze.ahash=J5;Ze.aexists=Z5;Ze.aoutput=Y5;Ze.u8=Q5;Ze.u32=e7;Ze.clean=t7;Ze.createView=r7;Ze.rotr=n7;Ze.rotl=i7;Ze.byteSwap=S0;Ze.byteSwap32=D1;Ze.bytesToHex=o7;Ze.hexToBytes=a7;Ze.asyncLoop=c7;Ze.utf8ToBytes=k0;Ze.bytesToUtf8=l7;Ze.toBytes=ef;Ze.kdfInputToBytes=f7;Ze.concatBytes=d7;Ze.checkOpts=h7;Ze.createHasher=R1;Ze.createOptHasher=U1;Ze.createXOFer=L1;Ze.randomBytes=p7;var Na=C1();function N1(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function w0(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Da(t,...e){if(!N1(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function J5(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");w0(t.outputLen),w0(t.blockLen)}function Z5(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Y5(t,e){Da(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Q5(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function e7(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function t7(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function r7(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function n7(t,e){return t<<32-e|t>>>e}function i7(t,e){return t<<e|t>>>32-e>>>0}Ze.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function S0(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}Ze.swap8IfBE=Ze.isLE?t=>t:t=>S0(t);Ze.byteSwapIfBE=Ze.swap8IfBE;function D1(t){for(let e=0;e<t.length;e++)t[e]=S0(t[e]);return t}Ze.swap32IfBE=Ze.isLE?t=>t:D1;var B1=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",s7=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function o7(t){if(Da(t),B1)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=s7[t[r]];return e}var gs={_0:48,_9:57,A:65,F:70,a:97,f:102};function j1(t){if(t>=gs._0&&t<=gs._9)return t-gs._0;if(t>=gs.A&&t<=gs.F)return t-(gs.A-10);if(t>=gs.a&&t<=gs.f)return t-(gs.a-10)}function a7(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(B1)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){let o=j1(t.charCodeAt(s)),u=j1(t.charCodeAt(s+1));if(o===void 0||u===void 0){let c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+u}return n}var u7=async()=>{};Ze.nextTick=u7;async function c7(t,e,r){let n=Date.now();for(let i=0;i<t;i++){r(i);let s=Date.now()-n;s>=0&&s<e||(await(0,Ze.nextTick)(),n+=s)}}function k0(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function l7(t){return new TextDecoder().decode(t)}function ef(t){return typeof t=="string"&&(t=k0(t)),Da(t),t}function f7(t){return typeof t=="string"&&(t=k0(t)),Da(t),t}function d7(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Da(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let s=t[n];r.set(s,i),i+=s.length}return r}function h7(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(t,e)}var M0=class{};Ze.Hash=M0;function R1(t){let e=n=>t().update(ef(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function U1(t){let e=(n,i)=>t(i).update(ef(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}function L1(t){let e=(n,i)=>t(i).update(ef(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}Ze.wrapConstructor=R1;Ze.wrapConstructorWithOpts=U1;Ze.wrapXOFConstructorWithOpts=L1;function p7(t=32){if(Na.crypto&&typeof Na.crypto.getRandomValues=="function")return Na.crypto.getRandomValues(new Uint8Array(t));if(Na.crypto&&typeof Na.crypto.randomBytes=="function")return Uint8Array.from(Na.crypto.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}});var $1=be(Ba=>{"use strict";Object.defineProperty(Ba,"__esModule",{value:!0});Ba.BSIGMA=void 0;Ba.G1s=m7;Ba.G2s=g7;var rf=tf();Ba.BSIGMA=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function m7(t,e,r,n,i){return t=t+e+i|0,n=(0,rf.rotr)(n^t,16),r=r+n|0,e=(0,rf.rotr)(e^r,12),{a:t,b:e,c:r,d:n}}function g7(t,e,r,n,i){return t=t+e+i|0,n=(0,rf.rotr)(n^t,8),r=r+n|0,e=(0,rf.rotr)(e^r,7),{a:t,b:e,c:r,d:n}}});var q1=be(sn=>{"use strict";Object.defineProperty(sn,"__esModule",{value:!0});sn.SHA512_IV=sn.SHA384_IV=sn.SHA224_IV=sn.SHA256_IV=sn.HashMD=void 0;sn.setBigUint64=F1;sn.Chi=y7;sn.Maj=_7;var Gi=tf();function F1(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),u=Number(r&s),c=n?4:0,d=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+d,u,n)}function y7(t,e,r){return t&e^~t&r}function _7(t,e,r){return t&e^t&r^e&r}var O0=class extends Gi.Hash{constructor(e,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=(0,Gi.createView)(this.buffer)}update(e){(0,Gi.aexists)(this),e=(0,Gi.toBytes)(e),(0,Gi.abytes)(e);let{view:r,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let u=Math.min(i-this.pos,s-o);if(u===i){let c=(0,Gi.createView)(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+u),this.pos),this.pos+=u,o+=u,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){(0,Gi.aexists)(this),(0,Gi.aoutput)(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,(0,Gi.clean)(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let _=o;_<i;_++)r[_]=0;F1(n,i-8,BigInt(this.length*8),s),this.process(n,0);let u=(0,Gi.createView)(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=c/4,p=this.get();if(d>p.length)throw new Error("_sha2: outputLen bigger than state");for(let _=0;_<d;_++)u.setUint32(4*_,p[_],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:u}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=u,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}};sn.HashMD=O0;sn.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);sn.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);sn.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);sn.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var l2=be(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.toBig=vt.shrSL=vt.shrSH=vt.rotrSL=vt.rotrSH=vt.rotrBL=vt.rotrBH=vt.rotr32L=vt.rotr32H=vt.rotlSL=vt.rotlSH=vt.rotlBL=vt.rotlBH=vt.add5L=vt.add5H=vt.add4L=vt.add4H=vt.add3L=vt.add3H=void 0;vt.add=n2;vt.fromBig=A0;vt.split=V1;var nf=BigInt(2**32-1),E0=BigInt(32);function A0(t,e=!1){return e?{h:Number(t&nf),l:Number(t>>E0&nf)}:{h:Number(t>>E0&nf)|0,l:Number(t&nf)|0}}function V1(t,e=!1){let r=t.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:u}=A0(t[s],e);[n[s],i[s]]=[o,u]}return[n,i]}var z1=(t,e)=>BigInt(t>>>0)<<E0|BigInt(e>>>0);vt.toBig=z1;var G1=(t,e,r)=>t>>>r;vt.shrSH=G1;var H1=(t,e,r)=>t<<32-r|e>>>r;vt.shrSL=H1;var W1=(t,e,r)=>t>>>r|e<<32-r;vt.rotrSH=W1;var K1=(t,e,r)=>t<<32-r|e>>>r;vt.rotrSL=K1;var X1=(t,e,r)=>t<<64-r|e>>>r-32;vt.rotrBH=X1;var J1=(t,e,r)=>t>>>r-32|e<<64-r;vt.rotrBL=J1;var Z1=(t,e)=>e;vt.rotr32H=Z1;var Y1=(t,e)=>t;vt.rotr32L=Y1;var Q1=(t,e,r)=>t<<r|e>>>32-r;vt.rotlSH=Q1;var e2=(t,e,r)=>e<<r|t>>>32-r;vt.rotlSL=e2;var t2=(t,e,r)=>e<<r-32|t>>>64-r;vt.rotlBH=t2;var r2=(t,e,r)=>t<<r-32|e>>>64-r;vt.rotlBL=r2;function n2(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var i2=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0);vt.add3L=i2;var s2=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;vt.add3H=s2;var o2=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0);vt.add4L=o2;var a2=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0;vt.add4H=a2;var u2=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0);vt.add5L=u2;var c2=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0;vt.add5H=c2;var v7={fromBig:A0,split:V1,toBig:z1,shrSH:G1,shrSL:H1,rotrSH:W1,rotrSL:K1,rotrBH:X1,rotrBL:J1,rotr32H:Z1,rotr32L:Y1,rotlSH:Q1,rotlSL:e2,rotlBH:t2,rotlBL:r2,add:n2,add3L:i2,add3H:s2,add4L:o2,add4H:a2,add5H:c2,add5L:u2};vt.default=v7});var h2=be(Mn=>{"use strict";Object.defineProperty(Mn,"__esModule",{value:!0});Mn.blake2s=Mn.BLAKE2s=Mn.blake2b=Mn.BLAKE2b=Mn.BLAKE2=void 0;Mn.compress=d2;var Ir=$1(),b7=q1(),Gr=l2(),nt=tf(),vr=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),ke=new Uint32Array(32);function io(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=ke[2*t],d=ke[2*t+1],p=ke[2*e],_=ke[2*e+1],b=ke[2*r],O=ke[2*r+1],T=ke[2*n],x=ke[2*n+1],F=Gr.add3L(c,p,o);d=Gr.add3H(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:Gr.rotr32H(x,T),Dl:Gr.rotr32L(x,T)},{h:O,l:b}=Gr.add(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Gr.rotrSH(_,p,24),Bl:Gr.rotrSL(_,p,24)},ke[2*t]=c,ke[2*t+1]=d,ke[2*e]=p,ke[2*e+1]=_,ke[2*r]=b,ke[2*r+1]=O,ke[2*n]=T,ke[2*n+1]=x}function so(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=ke[2*t],d=ke[2*t+1],p=ke[2*e],_=ke[2*e+1],b=ke[2*r],O=ke[2*r+1],T=ke[2*n],x=ke[2*n+1],F=Gr.add3L(c,p,o);d=Gr.add3H(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:Gr.rotrSH(x,T,16),Dl:Gr.rotrSL(x,T,16)},{h:O,l:b}=Gr.add(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Gr.rotrBH(_,p,63),Bl:Gr.rotrBL(_,p,63)},ke[2*t]=c,ke[2*t+1]=d,ke[2*e]=p,ke[2*e+1]=_,ke[2*r]=b,ke[2*r+1]=O,ke[2*n]=T,ke[2*n+1]=x}function f2(t,e={},r,n,i){if((0,nt.anumber)(r),t<0||t>r)throw new Error("outputLen bigger than keyLen");let{key:s,salt:o,personalization:u}=e;if(s!==void 0&&(s.length<1||s.length>r))throw new Error("key length must be undefined or 1.."+r);if(o!==void 0&&o.length!==n)throw new Error("salt must be undefined or "+n);if(u!==void 0&&u.length!==i)throw new Error("personalization must be undefined or "+i)}var Zu=class extends nt.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,(0,nt.anumber)(e),(0,nt.anumber)(r),this.blockLen=e,this.outputLen=r,this.buffer=new Uint8Array(e),this.buffer32=(0,nt.u32)(this.buffer)}update(e){(0,nt.aexists)(this),e=(0,nt.toBytes)(e),(0,nt.abytes)(e);let{blockLen:r,buffer:n,buffer32:i}=this,s=e.length,o=e.byteOffset,u=e.buffer;for(let c=0;c<s;){this.pos===r&&((0,nt.swap32IfBE)(i),this.compress(i,0,!1),(0,nt.swap32IfBE)(i),this.pos=0);let d=Math.min(r-this.pos,s-c),p=o+c;if(d===r&&!(p%4)&&c+d<s){let _=new Uint32Array(u,p,Math.floor((s-c)/4));(0,nt.swap32IfBE)(_);for(let b=0;c+r<s;b+=i.length,c+=r)this.length+=r,this.compress(_,b,!1);(0,nt.swap32IfBE)(_);continue}n.set(e.subarray(c,c+d),this.pos),this.pos+=d,this.length+=d,c+=d}return this}digestInto(e){(0,nt.aexists)(this),(0,nt.aoutput)(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,(0,nt.clean)(this.buffer.subarray(r)),(0,nt.swap32IfBE)(n),this.compress(n,0,!0),(0,nt.swap32IfBE)(n);let i=(0,nt.u32)(e);this.get().forEach((s,o)=>i[o]=(0,nt.swap8IfBE)(s))}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){let{buffer:r,length:n,finished:i,destroyed:s,outputLen:o,pos:u}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(r),e.destroyed=s,e.finished=i,e.length=n,e.pos=u,e.outputLen=o,e}clone(){return this._cloneInto()}};Mn.BLAKE2=Zu;var sf=class extends Zu{constructor(e={}){let r=e.dkLen===void 0?64:e.dkLen;super(128,r),this.v0l=vr[0]|0,this.v0h=vr[1]|0,this.v1l=vr[2]|0,this.v1h=vr[3]|0,this.v2l=vr[4]|0,this.v2h=vr[5]|0,this.v3l=vr[6]|0,this.v3h=vr[7]|0,this.v4l=vr[8]|0,this.v4h=vr[9]|0,this.v5l=vr[10]|0,this.v5h=vr[11]|0,this.v6l=vr[12]|0,this.v6h=vr[13]|0,this.v7l=vr[14]|0,this.v7h=vr[15]|0,f2(r,e,64,16,16);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=(0,nt.toBytes)(n),o=n.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=(0,nt.toBytes)(s);let u=(0,nt.u32)(s);this.v4l^=(0,nt.swap8IfBE)(u[0]),this.v4h^=(0,nt.swap8IfBE)(u[1]),this.v5l^=(0,nt.swap8IfBE)(u[2]),this.v5h^=(0,nt.swap8IfBE)(u[3])}if(i!==void 0){i=(0,nt.toBytes)(i);let u=(0,nt.u32)(i);this.v6l^=(0,nt.swap8IfBE)(u[0]),this.v6h^=(0,nt.swap8IfBE)(u[1]),this.v7l^=(0,nt.swap8IfBE)(u[2]),this.v7h^=(0,nt.swap8IfBE)(u[3])}if(n!==void 0){let u=new Uint8Array(this.blockLen);u.set(n),this.update(u)}}get(){let{v0l:e,v0h:r,v1l:n,v1h:i,v2l:s,v2h:o,v3l:u,v3h:c,v4l:d,v4h:p,v5l:_,v5h:b,v6l:O,v6h:T,v7l:x,v7h:F}=this;return[e,r,n,i,s,o,u,c,d,p,_,b,O,T,x,F]}set(e,r,n,i,s,o,u,c,d,p,_,b,O,T,x,F){this.v0l=e|0,this.v0h=r|0,this.v1l=n|0,this.v1h=i|0,this.v2l=s|0,this.v2h=o|0,this.v3l=u|0,this.v3h=c|0,this.v4l=d|0,this.v4h=p|0,this.v5l=_|0,this.v5h=b|0,this.v6l=O|0,this.v6h=T|0,this.v7l=x|0,this.v7h=F|0}compress(e,r,n){this.get().forEach((c,d)=>ke[d]=c),ke.set(vr,16);let{h:i,l:s}=Gr.fromBig(BigInt(this.length));ke[24]=vr[8]^s,ke[25]=vr[9]^i,n&&(ke[28]=~ke[28],ke[29]=~ke[29]);let o=0,u=Ir.BSIGMA;for(let c=0;c<12;c++)io(0,4,8,12,e,r+2*u[o++]),so(0,4,8,12,e,r+2*u[o++]),io(1,5,9,13,e,r+2*u[o++]),so(1,5,9,13,e,r+2*u[o++]),io(2,6,10,14,e,r+2*u[o++]),so(2,6,10,14,e,r+2*u[o++]),io(3,7,11,15,e,r+2*u[o++]),so(3,7,11,15,e,r+2*u[o++]),io(0,5,10,15,e,r+2*u[o++]),so(0,5,10,15,e,r+2*u[o++]),io(1,6,11,12,e,r+2*u[o++]),so(1,6,11,12,e,r+2*u[o++]),io(2,7,8,13,e,r+2*u[o++]),so(2,7,8,13,e,r+2*u[o++]),io(3,4,9,14,e,r+2*u[o++]),so(3,4,9,14,e,r+2*u[o++]);this.v0l^=ke[0]^ke[16],this.v0h^=ke[1]^ke[17],this.v1l^=ke[2]^ke[18],this.v1h^=ke[3]^ke[19],this.v2l^=ke[4]^ke[20],this.v2h^=ke[5]^ke[21],this.v3l^=ke[6]^ke[22],this.v3h^=ke[7]^ke[23],this.v4l^=ke[8]^ke[24],this.v4h^=ke[9]^ke[25],this.v5l^=ke[10]^ke[26],this.v5h^=ke[11]^ke[27],this.v6l^=ke[12]^ke[28],this.v6h^=ke[13]^ke[29],this.v7l^=ke[14]^ke[30],this.v7h^=ke[15]^ke[31],(0,nt.clean)(ke)}destroy(){this.destroyed=!0,(0,nt.clean)(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Mn.BLAKE2b=sf;Mn.blake2b=(0,nt.createOptHasher)(t=>new sf(t));function d2(t,e,r,n,i,s,o,u,c,d,p,_,b,O,T,x,F,R,H,J){let ee=0;for(let ae=0;ae<n;ae++)({a:i,b:c,c:b,d:F}=(0,Ir.G1s)(i,c,b,F,r[e+t[ee++]])),{a:i,b:c,c:b,d:F}=(0,Ir.G2s)(i,c,b,F,r[e+t[ee++]]),{a:s,b:d,c:O,d:R}=(0,Ir.G1s)(s,d,O,R,r[e+t[ee++]]),{a:s,b:d,c:O,d:R}=(0,Ir.G2s)(s,d,O,R,r[e+t[ee++]]),{a:o,b:p,c:T,d:H}=(0,Ir.G1s)(o,p,T,H,r[e+t[ee++]]),{a:o,b:p,c:T,d:H}=(0,Ir.G2s)(o,p,T,H,r[e+t[ee++]]),{a:u,b:_,c:x,d:J}=(0,Ir.G1s)(u,_,x,J,r[e+t[ee++]]),{a:u,b:_,c:x,d:J}=(0,Ir.G2s)(u,_,x,J,r[e+t[ee++]]),{a:i,b:d,c:T,d:J}=(0,Ir.G1s)(i,d,T,J,r[e+t[ee++]]),{a:i,b:d,c:T,d:J}=(0,Ir.G2s)(i,d,T,J,r[e+t[ee++]]),{a:s,b:p,c:x,d:F}=(0,Ir.G1s)(s,p,x,F,r[e+t[ee++]]),{a:s,b:p,c:x,d:F}=(0,Ir.G2s)(s,p,x,F,r[e+t[ee++]]),{a:o,b:_,c:b,d:R}=(0,Ir.G1s)(o,_,b,R,r[e+t[ee++]]),{a:o,b:_,c:b,d:R}=(0,Ir.G2s)(o,_,b,R,r[e+t[ee++]]),{a:u,b:c,c:O,d:H}=(0,Ir.G1s)(u,c,O,H,r[e+t[ee++]]),{a:u,b:c,c:O,d:H}=(0,Ir.G2s)(u,c,O,H,r[e+t[ee++]]);return{v0:i,v1:s,v2:o,v3:u,v4:c,v5:d,v6:p,v7:_,v8:b,v9:O,v10:T,v11:x,v12:F,v13:R,v14:H,v15:J}}var Dr=b7.SHA256_IV,of=class extends Zu{constructor(e={}){let r=e.dkLen===void 0?32:e.dkLen;super(64,r),this.v0=Dr[0]|0,this.v1=Dr[1]|0,this.v2=Dr[2]|0,this.v3=Dr[3]|0,this.v4=Dr[4]|0,this.v5=Dr[5]|0,this.v6=Dr[6]|0,this.v7=Dr[7]|0,f2(r,e,32,8,8);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=(0,nt.toBytes)(n),o=n.length),this.v0^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=(0,nt.toBytes)(s);let u=(0,nt.u32)(s);this.v4^=(0,nt.swap8IfBE)(u[0]),this.v5^=(0,nt.swap8IfBE)(u[1])}if(i!==void 0){i=(0,nt.toBytes)(i);let u=(0,nt.u32)(i);this.v6^=(0,nt.swap8IfBE)(u[0]),this.v7^=(0,nt.swap8IfBE)(u[1])}if(n!==void 0){(0,nt.abytes)(n);let u=new Uint8Array(this.blockLen);u.set(n),this.update(u)}}get(){let{v0:e,v1:r,v2:n,v3:i,v4:s,v5:o,v6:u,v7:c}=this;return[e,r,n,i,s,o,u,c]}set(e,r,n,i,s,o,u,c){this.v0=e|0,this.v1=r|0,this.v2=n|0,this.v3=i|0,this.v4=s|0,this.v5=o|0,this.v6=u|0,this.v7=c|0}compress(e,r,n){let{h:i,l:s}=Gr.fromBig(BigInt(this.length)),{v0:o,v1:u,v2:c,v3:d,v4:p,v5:_,v6:b,v7:O,v8:T,v9:x,v10:F,v11:R,v12:H,v13:J,v14:ee,v15:ae}=d2(Ir.BSIGMA,r,e,10,this.v0,this.v1,this.v2,this.v3,this.v4,this.v5,this.v6,this.v7,Dr[0],Dr[1],Dr[2],Dr[3],s^Dr[4],i^Dr[5],n?~Dr[6]:Dr[6],Dr[7]);this.v0^=o^T,this.v1^=u^x,this.v2^=c^F,this.v3^=d^R,this.v4^=p^H,this.v5^=_^J,this.v6^=b^ee,this.v7^=O^ae}destroy(){this.destroyed=!0,(0,nt.clean)(this.buffer32),this.set(0,0,0,0,0,0,0,0)}};Mn.BLAKE2s=of;Mn.blake2s=(0,nt.createOptHasher)(t=>new of(t))});var I0=be(Ra=>{"use strict";Object.defineProperty(Ra,"__esModule",{value:!0});Ra.blake2b=Ra.BLAKE2b=void 0;var p2=h2();Ra.BLAKE2b=p2.BLAKE2b;Ra.blake2b=p2.blake2b});var P0=be((BY,g2)=>{"use strict";var x0=Object.defineProperty,w7=Object.getOwnPropertyDescriptor,M7=Object.getOwnPropertyNames,S7=Object.prototype.hasOwnProperty,k7=(t,e)=>{for(var r in e)x0(t,r,{get:e[r],enumerable:!0})},O7=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M7(e))!S7.call(t,i)&&i!==r&&x0(t,i,{get:()=>e[i],enumerable:!(n=w7(e,i))||n.enumerable});return t},E7=t=>O7(x0({},"__esModule",{value:!0}),t),m2={};k7(m2,{deriveDynamicFieldID:()=>T7});g2.exports=E7(m2);var A7=dr(),I7=I0(),T0=Rn();function T7(t,e,r){let n=T0.bcs.Address.serialize(t).toBytes(),i=T0.bcs.TypeTag.serialize(e).toBytes(),s=T0.bcs.u64().serialize(r.length).toBytes(),o=I7.blake2b.create({dkLen:32});return o.update(new Uint8Array([240])),o.update(n),o.update(s),o.update(r),o.update(i),`0x${(0,A7.toHex)(o.digest().slice(0,32))}`}});var af=be((RY,w2)=>{"use strict";var C0=Object.defineProperty,x7=Object.getOwnPropertyDescriptor,P7=Object.getOwnPropertyNames,C7=Object.prototype.hasOwnProperty,j7=(t,e)=>{for(var r in e)C0(t,r,{get:e[r],enumerable:!0})},N7=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of P7(e))!C7.call(t,i)&&i!==r&&C0(t,i,{get:()=>e[i],enumerable:!(n=x7(e,i))||n.enumerable});return t},D7=t=>N7(C0({},"__esModule",{value:!0}),t),b2={};j7(b2,{MIST_PER_SUI:()=>ys.MIST_PER_SUI,MOVE_STDLIB_ADDRESS:()=>ys.MOVE_STDLIB_ADDRESS,SUI_ADDRESS_LENGTH:()=>oo.SUI_ADDRESS_LENGTH,SUI_CLOCK_OBJECT_ID:()=>ys.SUI_CLOCK_OBJECT_ID,SUI_DECIMALS:()=>ys.SUI_DECIMALS,SUI_FRAMEWORK_ADDRESS:()=>ys.SUI_FRAMEWORK_ADDRESS,SUI_SYSTEM_ADDRESS:()=>ys.SUI_SYSTEM_ADDRESS,SUI_SYSTEM_MODULE_NAME:()=>ys.SUI_SYSTEM_MODULE_NAME,SUI_SYSTEM_STATE_OBJECT_ID:()=>ys.SUI_SYSTEM_STATE_OBJECT_ID,SUI_TYPE_ARG:()=>ys.SUI_TYPE_ARG,deriveDynamicFieldID:()=>B7.deriveDynamicFieldID,formatAddress:()=>y2.formatAddress,formatDigest:()=>y2.formatDigest,fromB64:()=>Hi.fromB64,fromBase58:()=>Hi.fromBase58,fromBase64:()=>Hi.fromBase64,fromHEX:()=>Hi.fromHEX,fromHex:()=>Hi.fromHex,isValidNamedPackage:()=>v2.isValidNamedPackage,isValidNamedType:()=>v2.isValidNamedType,isValidSuiAddress:()=>oo.isValidSuiAddress,isValidSuiNSName:()=>_2.isValidSuiNSName,isValidSuiObjectId:()=>oo.isValidSuiObjectId,isValidTransactionDigest:()=>oo.isValidTransactionDigest,normalizeStructTag:()=>oo.normalizeStructTag,normalizeSuiAddress:()=>oo.normalizeSuiAddress,normalizeSuiNSName:()=>_2.normalizeSuiNSName,normalizeSuiObjectId:()=>oo.normalizeSuiObjectId,parseStructTag:()=>oo.parseStructTag,toB64:()=>Hi.toB64,toBase58:()=>Hi.toBase58,toBase64:()=>Hi.toBase64,toHEX:()=>Hi.toHEX,toHex:()=>Hi.toHex});w2.exports=D7(b2);var y2=E1(),oo=Nr(),Hi=dr(),_2=Xl(),ys=P1(),v2=Xu(),B7=P0()});var D0=be((UY,O2)=>{"use strict";var N0=Object.defineProperty,R7=Object.getOwnPropertyDescriptor,U7=Object.getOwnPropertyNames,L7=Object.prototype.hasOwnProperty,$7=(t,e)=>{for(var r in e)N0(t,r,{get:e[r],enumerable:!0})},F7=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of U7(e))!L7.call(t,i)&&i!==r&&N0(t,i,{get:()=>e[i],enumerable:!(n=R7(e,i))||n.enumerable});return t},q7=t=>F7(N0({},"__esModule",{value:!0}),t),S2={};$7(S2,{getPureBcsSchema:()=>j0,isTxContext:()=>Z7,normalizedTypeToMoveTypeSignature:()=>Y7,pureBcsSchemaFromOpenMoveTypeSignatureBody:()=>k2});O2.exports=q7(S2);var er=Rn(),M2=af(),Yu=Nr(),V7="object",z7="ID",G7="ascii",H7="String",W7="string",K7="String",X7="option",J7="Option";function Z7(t){let e=typeof t.body=="object"&&"datatype"in t.body?t.body.datatype:null;return!!e&&(0,Yu.normalizeSuiAddress)(e.package)===(0,Yu.normalizeSuiAddress)("0x2")&&e.module==="tx_context"&&e.type==="TxContext"}function j0(t){if(typeof t=="string")switch(t){case"address":return er.bcs.Address;case"bool":return er.bcs.Bool;case"u8":return er.bcs.U8;case"u16":return er.bcs.U16;case"u32":return er.bcs.U32;case"u64":return er.bcs.U64;case"u128":return er.bcs.U128;case"u256":return er.bcs.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t){if(t.vector==="u8")return er.bcs.vector(er.bcs.U8).transform({input:r=>typeof r=="string"?new TextEncoder().encode(r):r,output:r=>r});let e=j0(t.vector);return e?er.bcs.vector(e):null}if("datatype"in t){let e=(0,Yu.normalizeSuiAddress)(t.datatype.package);if(e===(0,Yu.normalizeSuiAddress)(M2.MOVE_STDLIB_ADDRESS)){if(t.datatype.module===G7&&t.datatype.type===H7||t.datatype.module===W7&&t.datatype.type===K7)return er.bcs.String;if(t.datatype.module===X7&&t.datatype.type===J7){let r=j0(t.datatype.typeParameters[0]);return r?er.bcs.vector(r):null}}if(e===(0,Yu.normalizeSuiAddress)(M2.SUI_FRAMEWORK_ADDRESS)&&t.datatype.module===V7&&t.datatype.type===z7)return er.bcs.Address}return null}function Y7(t){return typeof t=="object"&&"Reference"in t?{ref:"&",body:Qu(t.Reference)}:typeof t=="object"&&"MutableReference"in t?{ref:"&mut",body:Qu(t.MutableReference)}:{ref:null,body:Qu(t)}}function Qu(t){if(typeof t=="string")switch(t){case"Address":return"address";case"Bool":return"bool";case"U8":return"u8";case"U16":return"u16";case"U32":return"u32";case"U64":return"u64";case"U128":return"u128";case"U256":return"u256";default:throw new Error(`Unexpected type ${t}`)}if("Vector"in t)return{vector:Qu(t.Vector)};if("Struct"in t)return{datatype:{package:t.Struct.address,module:t.Struct.module,type:t.Struct.name,typeParameters:t.Struct.typeArguments.map(Qu)}};if("TypeParameter"in t)return{typeParameter:t.TypeParameter};throw new Error(`Unexpected type ${JSON.stringify(t)}`)}function k2(t){if(typeof t=="string")switch(t){case"address":return er.bcs.Address;case"bool":return er.bcs.Bool;case"u8":return er.bcs.U8;case"u16":return er.bcs.U16;case"u32":return er.bcs.U32;case"u64":return er.bcs.U64;case"u128":return er.bcs.U128;case"u256":return er.bcs.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t)return er.bcs.vector(k2(t.vector));throw new Error(`Expected pure typeSignature, but got ${JSON.stringify(t)}`)}});var Ua=be((LY,A2)=>{"use strict";var R0=Object.defineProperty,Q7=Object.getOwnPropertyDescriptor,eN=Object.getOwnPropertyNames,tN=Object.prototype.hasOwnProperty,rN=(t,e)=>{for(var r in e)R0(t,r,{get:e[r],enumerable:!0})},nN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of eN(e))!tN.call(t,i)&&i!==r&&R0(t,i,{get:()=>e[i],enumerable:!(n=Q7(e,i))||n.enumerable});return t},iN=t=>nN(R0({},"__esModule",{value:!0}),t),E2={};rN(E2,{Inputs:()=>aN});A2.exports=iN(E2);var sN=dr(),B0=Nr();function oN(t){return{$kind:"Pure",Pure:{bytes:t instanceof Uint8Array?(0,sN.toBase64)(t):t.toBase64()}}}var aN={Pure:oN,ObjectRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{digest:e,version:r,objectId:(0,B0.normalizeSuiAddress)(t)}}}},SharedObjectRef({objectId:t,mutable:e,initialSharedVersion:r}){return{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{mutable:e,initialSharedVersion:r,objectId:(0,B0.normalizeSuiAddress)(t)}}}},ReceivingRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"Receiving",Receiving:{digest:e,version:r,objectId:(0,B0.normalizeSuiAddress)(t)}}}}}});var Wi=be(($Y,Lk)=>{"use strict";var W0=Object.defineProperty,uN=Object.getOwnPropertyDescriptor,cN=Object.getOwnPropertyNames,lN=Object.prototype.hasOwnProperty,fN=(t,e)=>{for(var r in e)W0(t,r,{get:e[r],enumerable:!0})},dN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of cN(e))!lN.call(t,i)&&i!==r&&W0(t,i,{get:()=>e[i],enumerable:!(n=uN(e,i))||n.enumerable});return t},hN=t=>dN(W0({},"__esModule",{value:!0}),t),I2={};fN(I2,{BIC_REGEX:()=>x2,CUID2_REGEX:()=>P2,DECIMAL_REGEX:()=>C2,EMAIL_REGEX:()=>j2,EMOJI_REGEX:()=>N2,HEXADECIMAL_REGEX:()=>D2,HEX_COLOR_REGEX:()=>B2,IMEI_REGEX:()=>R2,IPV4_REGEX:()=>U2,IPV6_REGEX:()=>L2,IP_REGEX:()=>$2,ISO_DATE_REGEX:()=>F2,ISO_DATE_TIME_REGEX:()=>q2,ISO_TIMESTAMP_REGEX:()=>G2,ISO_TIME_REGEX:()=>V2,ISO_TIME_SECOND_REGEX:()=>z2,ISO_WEEK_REGEX:()=>H2,MAC48_REGEX:()=>W2,MAC64_REGEX:()=>K2,MAC_REGEX:()=>X2,OCTAL_REGEX:()=>J2,ULID_REGEX:()=>Z2,UUID_REGEX:()=>Y2,ValiError:()=>lf,_addIssue:()=>ne,_isLuhnAlgo:()=>K0,_isValidObjectKey:()=>Jo,_stringify:()=>on,any:()=>CS,array:()=>jS,arrayAsync:()=>NS,awaitAsync:()=>T2,bic:()=>nM,bigint:()=>DS,blob:()=>BS,boolean:()=>RS,brand:()=>iM,bytes:()=>sM,check:()=>oM,checkAsync:()=>aM,checkItems:()=>uM,config:()=>PN,creditCard:()=>cM,cuid2:()=>lM,custom:()=>US,customAsync:()=>LS,date:()=>$S,decimal:()=>fM,deleteGlobalConfig:()=>mN,deleteGlobalMessage:()=>yN,deleteSchemaMessage:()=>vN,deleteSpecificMessage:()=>wN,email:()=>dM,emoji:()=>hM,empty:()=>pM,endsWith:()=>mM,entriesFromList:()=>SN,enum:()=>q0,enum_:()=>q0,everyItem:()=>gM,excludes:()=>yM,fallback:()=>CN,fallbackAsync:()=>jN,file:()=>FS,filterItems:()=>_M,findItem:()=>vM,finite:()=>bM,flatten:()=>NN,forward:()=>DN,forwardAsync:()=>BN,function:()=>V0,function_:()=>V0,getDefault:()=>_s,getDefaults:()=>U0,getDefaultsAsync:()=>L0,getDotPath:()=>rM,getFallback:()=>nc,getFallbacks:()=>$0,getFallbacksAsync:()=>F0,getGlobalConfig:()=>rc,getGlobalMessage:()=>Q2,getSchemaMessage:()=>eM,getSpecificMessage:()=>tM,hash:()=>wM,hexColor:()=>SM,hexadecimal:()=>MM,imei:()=>kM,includes:()=>OM,instance:()=>qS,integer:()=>EM,intersect:()=>VS,intersectAsync:()=>zS,ip:()=>AM,ipv4:()=>IM,ipv6:()=>TM,is:()=>RN,isOfKind:()=>kN,isOfType:()=>ON,isValiError:()=>EN,isoDate:()=>xM,isoDateTime:()=>PM,isoTime:()=>CM,isoTimeSecond:()=>jM,isoTimestamp:()=>NM,isoWeek:()=>DM,keyof:()=>UN,lazy:()=>GS,lazyAsync:()=>HS,length:()=>BM,literal:()=>WS,looseObject:()=>KS,looseObjectAsync:()=>XS,looseTuple:()=>JS,looseTupleAsync:()=>ZS,mac:()=>RM,mac48:()=>UM,mac64:()=>LM,map:()=>YS,mapAsync:()=>QS,mapItems:()=>$M,maxBytes:()=>FM,maxLength:()=>qM,maxSize:()=>VM,maxValue:()=>zM,mimeType:()=>GM,minBytes:()=>HM,minLength:()=>WM,minSize:()=>KM,minValue:()=>XM,multipleOf:()=>JM,nan:()=>ek,never:()=>tk,nonEmpty:()=>ZM,nonNullable:()=>rk,nonNullableAsync:()=>nk,nonNullish:()=>ik,nonNullishAsync:()=>sk,nonOptional:()=>X0,nonOptionalAsync:()=>J0,normalize:()=>YM,notBytes:()=>QM,notLength:()=>eS,notSize:()=>tS,notValue:()=>rS,null:()=>z0,null_:()=>z0,nullable:()=>ok,nullableAsync:()=>ak,nullish:()=>uk,nullishAsync:()=>ck,number:()=>lk,object:()=>fk,objectAsync:()=>dk,objectWithRest:()=>hk,objectWithRestAsync:()=>pk,octal:()=>nS,omit:()=>LN,optional:()=>Z0,optionalAsync:()=>Y0,parse:()=>Dk,parseAsync:()=>Bk,parser:()=>$N,parserAsync:()=>FN,partial:()=>qN,partialAsync:()=>VN,partialCheck:()=>sS,partialCheckAsync:()=>oS,pick:()=>zN,picklist:()=>Q0,pipe:()=>GN,pipeAsync:()=>HN,promise:()=>mk,rawCheck:()=>aS,rawCheckAsync:()=>uS,rawTransform:()=>cS,rawTransformAsync:()=>lS,readonly:()=>fS,record:()=>gk,recordAsync:()=>yk,reduceItems:()=>dS,regex:()=>hS,required:()=>WN,requiredAsync:()=>KN,safeInteger:()=>pS,safeParse:()=>Rk,safeParseAsync:()=>Uk,safeParser:()=>XN,safeParserAsync:()=>JN,set:()=>_k,setAsync:()=>vk,setGlobalConfig:()=>pN,setGlobalMessage:()=>gN,setSchemaMessage:()=>_N,setSpecificMessage:()=>bN,size:()=>mS,someItem:()=>gS,sortItems:()=>yS,startsWith:()=>_S,strictObject:()=>bk,strictObjectAsync:()=>wk,strictTuple:()=>Mk,strictTupleAsync:()=>Sk,string:()=>kk,symbol:()=>Ok,toLowerCase:()=>vS,toMaxValue:()=>bS,toMinValue:()=>wS,toUpperCase:()=>MS,transform:()=>SS,transformAsync:()=>kS,trim:()=>OS,trimEnd:()=>ES,trimStart:()=>AS,tuple:()=>Ek,tupleAsync:()=>Ak,tupleWithRest:()=>Ik,tupleWithRestAsync:()=>Tk,ulid:()=>IS,undefined:()=>G0,undefined_:()=>G0,union:()=>xk,unionAsync:()=>Pk,unknown:()=>Ck,unwrap:()=>ZN,url:()=>TS,uuid:()=>xS,value:()=>PS,variant:()=>jk,variantAsync:()=>Nk,void:()=>H0,void_:()=>H0});Lk.exports=hN(I2);function T2(){return{kind:"transformation",type:"await",reference:T2,async:!0,async _run(t){return t.value=await t.value,t}}}var x2=/^[A-Z]{6}(?!00)[A-Z\d]{2}(?:[A-Z\d]{3})?$/u,P2=/^[a-z][\da-z]*$/u,C2=/^\d+$/u,j2=/^[\w+-]+(?:\.[\w+-]+)*@[\da-z]+(?:[.-][\da-z]+)*\.[a-z]{2,}$/iu,N2=/^[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u,D2=/^(?:0h|0x)?[\da-f]+$/iu,B2=/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/iu,R2=/^\d{15}$|^\d{2}-\d{6}-\d{6}-\d$/u,U2=/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$/u,L2=/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu,$2=/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$|^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu,F2=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])$/u,q2=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])T(?:0\d|1\d|2[0-3]):[0-5]\d$/u,V2=/^(?:0\d|1\d|2[0-3]):[0-5]\d$/u,z2=/^(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}$/u,G2=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])T(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?(?:Z|[+-](?:0\d|1\d|2[0-3])(?::?[0-5]\d)?)$/u,H2=/^\d{4}-W(?:0[1-9]|[1-4]\d|5[0-3])$/u,W2=/^(?:[\da-f]{2}:){5}[\da-f]{2}$|^(?:[\da-f]{2}-){5}[\da-f]{2}$|^(?:[\da-f]{4}\.){2}[\da-f]{4}$/iu,K2=/^(?:[\da-f]{2}:){7}[\da-f]{2}$|^(?:[\da-f]{2}-){7}[\da-f]{2}$|^(?:[\da-f]{4}\.){3}[\da-f]{4}$|^(?:[\da-f]{4}:){3}[\da-f]{4}$/iu,X2=/^(?:[\da-f]{2}:){5}[\da-f]{2}$|^(?:[\da-f]{2}-){5}[\da-f]{2}$|^(?:[\da-f]{4}\.){2}[\da-f]{4}$|^(?:[\da-f]{2}:){7}[\da-f]{2}$|^(?:[\da-f]{2}-){7}[\da-f]{2}$|^(?:[\da-f]{4}\.){3}[\da-f]{4}$|^(?:[\da-f]{4}:){3}[\da-f]{4}$/iu,J2=/^(?:0o)?[0-7]+$/iu,Z2=/^[\da-hjkmnp-tv-z]{26}$/iu,Y2=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu,La;function pN(t){La={...La,...t}}function rc(t){return{lang:t?.lang??La?.lang,message:t?.message,abortEarly:t?.abortEarly??La?.abortEarly,abortPipeEarly:t?.abortPipeEarly??La?.abortPipeEarly}}function mN(){La=void 0}var ec;function gN(t,e){ec||(ec=new Map),ec.set(e,t)}function Q2(t){return ec?.get(t)}function yN(t){ec?.delete(t)}var tc;function _N(t,e){tc||(tc=new Map),tc.set(e,t)}function eM(t){return tc?.get(t)}function vN(t){tc?.delete(t)}var Xo;function bN(t,e,r){Xo||(Xo=new Map),Xo.get(t)||Xo.set(t,new Map),Xo.get(t).set(r,e)}function tM(t,e){return Xo?.get(t)?.get(e)}function wN(t,e){Xo?.get(t)?.delete(e)}function on(t){let e=typeof t;return e==="string"?`"${t}"`:e==="number"||e==="bigint"||e==="boolean"?`${t}`:e==="object"||e==="function"?(t&&Object.getPrototypeOf(t)?.constructor?.name)??"null":e}function ne(t,e,r,n,i){let s=i&&"input"in i?i.input:r.value,o=i?.expected??t.expects??null,u=i?.received??on(s),c={kind:t.kind,type:t.type,input:s,expected:o,received:u,message:`Invalid ${e}: ${o?`Expected ${o} but r`:"R"}eceived ${u}`,requirement:t.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},d=t.kind==="schema",p=i?.message??t.message??tM(t.reference,c.lang)??(d?eM(c.lang):null)??n.message??Q2(c.lang);p&&(c.message=typeof p=="function"?p(c):p),d&&(r.typed=!1),r.issues?r.issues.push(c):r.issues=[c]}var MN=/\D/gu;function K0(t){let e=t.replace(MN,""),r=e.length,n=1,i=0;for(;r;){let s=+e[--r];n^=1,i+=n?[0,2,4,6,8,1,3,5,7,9][s]:s}return i%10===0}function Jo(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function SN(t,e){let r={};for(let n of t)r[n]=e;return r}function rM(t){if(t.path){let e="";for(let r of t.path)if(typeof r.key=="string"||typeof r.key=="number")e?e+=`.${r.key}`:e+=r.key;else return null;return e}return null}function kN(t,e){return e.kind===t}function ON(t,e){return e.type===t}function EN(t){return t instanceof lf}var lf=class extends Error{issues;constructor(t){super(t[0].message),this.name="ValiError",this.issues=t}};function nM(t){return{kind:"validation",type:"bic",reference:nM,async:!1,expects:null,requirement:x2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"BIC",e,r),e}}}function iM(t){return{kind:"transformation",type:"brand",reference:iM,async:!1,name:t,_run(e){return e}}}function sM(t,e){return{kind:"validation",type:"bytes",reference:sM,async:!1,expects:`${t}`,requirement:t,message:e,_run(r,n){if(r.typed){let i=new TextEncoder().encode(r.value).length;i!==this.requirement&&ne(this,"bytes",r,n,{received:`${i}`})}return r}}}function oM(t,e){return{kind:"validation",type:"check",reference:oM,async:!1,expects:null,requirement:t,message:e,_run(r,n){return r.typed&&!this.requirement(r.value)&&ne(this,"input",r,n),r}}}function aM(t,e){return{kind:"validation",type:"check",reference:aM,async:!0,expects:null,requirement:t,message:e,async _run(r,n){return r.typed&&!await this.requirement(r.value)&&ne(this,"input",r,n),r}}}function uM(t,e){return{kind:"validation",type:"check_items",reference:uM,async:!1,expects:null,requirement:t,message:e,_run(r,n){if(r.typed)for(let i=0;i<r.value.length;i++){let s=r.value[i];this.requirement(s,i,r.value)||ne(this,"item",r,n,{input:s,path:[{type:"array",origin:"value",input:r.value,key:i,value:s}]})}return r}}}var AN=/^(?:\d{14,19}|\d{4}(?: \d{3,6}){2,4}|\d{4}(?:-\d{3,6}){2,4})$/u,IN=/[- ]/gu,TN=[/^3[47]\d{13}$/u,/^3(?:0[0-5]|[68]\d)\d{11,13}$/u,/^6(?:011|5\d{2})\d{12,15}$/u,/^(?:2131|1800|35\d{3})\d{11}$/u,/^5[1-5]\d{2}|(?:222\d|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)\d{12}$/u,/^(?:6[27]\d{14,17}|81\d{14,17})$/u,/^4\d{12}(?:\d{3,6})?$/u];function cM(t){return{kind:"validation",type:"credit_card",reference:cM,async:!1,expects:null,requirement(e){let r;return AN.test(e)&&(r=e.replace(IN,""))&&TN.some(n=>n.test(r))&&K0(r)},message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"credit card",e,r),e}}}function lM(t){return{kind:"validation",type:"cuid2",reference:lM,async:!1,expects:null,requirement:P2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"Cuid2",e,r),e}}}function fM(t){return{kind:"validation",type:"decimal",reference:fM,async:!1,expects:null,requirement:C2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"decimal",e,r),e}}}function dM(t){return{kind:"validation",type:"email",reference:dM,expects:null,async:!1,requirement:j2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"email",e,r),e}}}function hM(t){return{kind:"validation",type:"emoji",reference:hM,async:!1,expects:null,requirement:N2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"emoji",e,r),e}}}function pM(t){return{kind:"validation",type:"empty",reference:pM,async:!1,expects:"0",message:t,_run(e,r){return e.typed&&e.value.length>0&&ne(this,"length",e,r,{received:`${e.value.length}`}),e}}}function mM(t,e){return{kind:"validation",type:"ends_with",reference:mM,async:!1,expects:`"${t}"`,requirement:t,message:e,_run(r,n){return r.typed&&!r.value.endsWith(this.requirement)&&ne(this,"end",r,n,{received:`"${r.value.slice(-this.requirement.length)}"`}),r}}}function gM(t,e){return{kind:"validation",type:"every_item",reference:gM,async:!1,expects:null,requirement:t,message:e,_run(r,n){return r.typed&&!r.value.every(this.requirement)&&ne(this,"item",r,n),r}}}function yM(t,e){let r=on(t);return{kind:"validation",type:"excludes",reference:yM,async:!1,expects:`!${r}`,requirement:t,message:e,_run(n,i){return n.typed&&n.value.includes(this.requirement)&&ne(this,"content",n,i,{received:r}),n}}}function _M(t){return{kind:"transformation",type:"filter_items",reference:_M,async:!1,operation:t,_run(e){return e.value=e.value.filter(this.operation),e}}}function vM(t){return{kind:"transformation",type:"find_item",reference:vM,async:!1,operation:t,_run(e){return e.value=e.value.find(this.operation),e}}}function bM(t){return{kind:"validation",type:"finite",reference:bM,async:!1,expects:null,requirement:Number.isFinite,message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"finite",e,r),e}}}var xN={md4:32,md5:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8,adler32:8};function wM(t,e){return{kind:"validation",type:"hash",reference:wM,expects:null,async:!1,requirement:RegExp(t.map(r=>`^[a-f0-9]{${xN[r]}}$`).join("|"),"iu"),message:e,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&ne(this,"hash",r,n),r}}}function MM(t){return{kind:"validation",type:"hexadecimal",reference:MM,async:!1,expects:null,requirement:D2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"hexadecimal",e,r),e}}}function SM(t){return{kind:"validation",type:"hex_color",reference:SM,async:!1,expects:null,requirement:B2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"hex color",e,r),e}}}function kM(t){return{kind:"validation",type:"imei",reference:kM,async:!1,expects:null,requirement(e){return R2.test(e)&&K0(e)},message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"IMEI",e,r),e}}}function OM(t,e){let r=on(t);return{kind:"validation",type:"includes",reference:OM,async:!1,expects:r,requirement:t,message:e,_run(n,i){return n.typed&&!n.value.includes(this.requirement)&&ne(this,"content",n,i,{received:`!${r}`}),n}}}function EM(t){return{kind:"validation",type:"integer",reference:EM,async:!1,expects:null,requirement:Number.isInteger,message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"integer",e,r),e}}}function AM(t){return{kind:"validation",type:"ip",reference:AM,async:!1,expects:null,requirement:$2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IP",e,r),e}}}function IM(t){return{kind:"validation",type:"ipv4",reference:IM,async:!1,expects:null,requirement:U2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IPv4",e,r),e}}}function TM(t){return{kind:"validation",type:"ipv6",reference:TM,async:!1,expects:null,requirement:L2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IPv6",e,r),e}}}function xM(t){return{kind:"validation",type:"iso_date",reference:xM,async:!1,expects:null,requirement:F2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"date",e,r),e}}}function PM(t){return{kind:"validation",type:"iso_date_time",reference:PM,async:!1,expects:null,requirement:q2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"date-time",e,r),e}}}function CM(t){return{kind:"validation",type:"iso_time",reference:CM,async:!1,expects:null,requirement:V2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"time",e,r),e}}}function jM(t){return{kind:"validation",type:"iso_time_second",reference:jM,async:!1,expects:null,requirement:z2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"time-second",e,r),e}}}function NM(t){return{kind:"validation",type:"iso_timestamp",reference:NM,async:!1,expects:null,requirement:G2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"timestamp",e,r),e}}}function DM(t){return{kind:"validation",type:"iso_week",reference:DM,async:!1,expects:null,requirement:H2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"week",e,r),e}}}function BM(t,e){return{kind:"validation",type:"length",reference:BM,async:!1,expects:`${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.length!==this.requirement&&ne(this,"length",r,n,{received:`${r.value.length}`}),r}}}function RM(t){return{kind:"validation",type:"mac",reference:RM,async:!1,expects:null,requirement:X2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"MAC",e,r),e}}}function UM(t){return{kind:"validation",type:"mac48",reference:UM,async:!1,expects:null,requirement:W2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"48-bit MAC",e,r),e}}}function LM(t){return{kind:"validation",type:"mac64",reference:LM,async:!1,expects:null,requirement:K2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"64-bit MAC",e,r),e}}}function $M(t){return{kind:"transformation",type:"map_items",reference:$M,async:!1,operation:t,_run(e){return e.value=e.value.map(this.operation),e}}}function FM(t,e){return{kind:"validation",type:"max_bytes",reference:FM,async:!1,expects:`<=${t}`,requirement:t,message:e,_run(r,n){if(r.typed){let i=new TextEncoder().encode(r.value).length;i>this.requirement&&ne(this,"bytes",r,n,{received:`${i}`})}return r}}}function qM(t,e){return{kind:"validation",type:"max_length",reference:qM,async:!1,expects:`<=${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.length>this.requirement&&ne(this,"length",r,n,{received:`${r.value.length}`}),r}}}function VM(t,e){return{kind:"validation",type:"max_size",reference:VM,async:!1,expects:`<=${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.size>this.requirement&&ne(this,"size",r,n,{received:`${r.value.size}`}),r}}}function zM(t,e){return{kind:"validation",type:"max_value",reference:zM,async:!1,expects:`<=${t instanceof Date?t.toJSON():on(t)}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value>this.requirement&&ne(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():on(r.value)}),r}}}function GM(t,e){return{kind:"validation",type:"mime_type",reference:GM,async:!1,expects:t.map(r=>`"${r}"`).join(" | ")||"never",requirement:t,message:e,_run(r,n){return r.typed&&!this.requirement.includes(r.value.type)&&ne(this,"MIME type",r,n,{received:`"${r.value.type}"`}),r}}}function HM(t,e){return{kind:"validation",type:"min_bytes",reference:HM,async:!1,expects:`>=${t}`,requirement:t,message:e,_run(r,n){if(r.typed){let i=new TextEncoder().encode(r.value).length;i<this.requirement&&ne(this,"bytes",r,n,{received:`${i}`})}return r}}}function WM(t,e){return{kind:"validation",type:"min_length",reference:WM,async:!1,expects:`>=${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.length<this.requirement&&ne(this,"length",r,n,{received:`${r.value.length}`}),r}}}function KM(t,e){return{kind:"validation",type:"min_size",reference:KM,async:!1,expects:`>=${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.size<this.requirement&&ne(this,"size",r,n,{received:`${r.value.size}`}),r}}}function XM(t,e){return{kind:"validation",type:"min_value",reference:XM,async:!1,expects:`>=${t instanceof Date?t.toJSON():on(t)}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value<this.requirement&&ne(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():on(r.value)}),r}}}function JM(t,e){return{kind:"validation",type:"multiple_of",reference:JM,async:!1,expects:`%${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value%this.requirement!==0&&ne(this,"multiple",r,n),r}}}function ZM(t){return{kind:"validation",type:"non_empty",reference:ZM,async:!1,expects:"!0",message:t,_run(e,r){return e.typed&&e.value.length===0&&ne(this,"length",e,r,{received:"0"}),e}}}function YM(t){return{kind:"transformation",type:"normalize",reference:YM,async:!1,form:t,_run(e){return e.value=e.value.normalize(this.form),e}}}function QM(t,e){return{kind:"validation",type:"not_bytes",reference:QM,async:!1,expects:`!${t}`,requirement:t,message:e,_run(r,n){if(r.typed){let i=new TextEncoder().encode(r.value).length;i===this.requirement&&ne(this,"bytes",r,n,{received:`${i}`})}return r}}}function eS(t,e){return{kind:"validation",type:"not_length",reference:eS,async:!1,expects:`!${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.length===this.requirement&&ne(this,"length",r,n,{received:`${r.value.length}`}),r}}}function tS(t,e){return{kind:"validation",type:"not_size",reference:tS,async:!1,expects:`!${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.size===this.requirement&&ne(this,"size",r,n,{received:`${r.value.size}`}),r}}}function rS(t,e){return{kind:"validation",type:"not_value",reference:rS,async:!1,expects:t instanceof Date?`!${t.toJSON()}`:`!${on(t)}`,requirement:t,message:e,_run(r,n){return r.typed&&this.requirement<=r.value&&this.requirement>=r.value&&ne(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():on(r.value)}),r}}}function nS(t){return{kind:"validation",type:"octal",reference:nS,async:!1,expects:null,requirement:J2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"octal",e,r),e}}}function iS(t,e){if(t.issues)for(let r of e)for(let n of t.issues){let i=!1,s=Math.min(r.length,n.path?.length??0);for(let o=0;o<s;o++)if(r[o]!==n.path[o].key){i=!0;break}if(!i)return!1}return!0}function sS(t,e,r){return{kind:"validation",type:"partial_check",reference:sS,async:!1,expects:null,requirement:e,message:r,_run(n,i){return iS(n,t)&&!this.requirement(n.value)&&ne(this,"input",n,i),n}}}function oS(t,e,r){return{kind:"validation",type:"partial_check",reference:oS,async:!0,expects:null,requirement:e,message:r,async _run(n,i){return iS(n,t)&&!await this.requirement(n.value)&&ne(this,"input",n,i),n}}}function aS(t){return{kind:"validation",type:"raw_check",reference:aS,async:!1,expects:null,_run(e,r){return t({dataset:e,config:r,addIssue:n=>ne(this,n?.label??"input",e,r,n)}),e}}}function uS(t){return{kind:"validation",type:"raw_check",reference:uS,async:!0,expects:null,async _run(e,r){return await t({dataset:e,config:r,addIssue:n=>ne(this,n?.label??"input",e,r,n)}),e}}}function cS(t){return{kind:"transformation",type:"raw_transform",reference:cS,async:!1,_run(e,r){let n=t({dataset:e,config:r,addIssue:i=>ne(this,i?.label??"input",e,r,i),NEVER:null});return e.issues?e.typed=!1:e.value=n,e}}}function lS(t){return{kind:"transformation",type:"raw_transform",reference:lS,async:!0,async _run(e,r){let n=await t({dataset:e,config:r,addIssue:i=>ne(this,i?.label??"input",e,r,i),NEVER:null});return e.issues?e.typed=!1:e.value=n,e}}}function fS(){return{kind:"transformation",type:"readonly",reference:fS,async:!1,_run(t){return t}}}function dS(t,e){return{kind:"transformation",type:"reduce_items",reference:dS,async:!1,operation:t,initial:e,_run(r){return r.value=r.value.reduce(this.operation,this.initial),r}}}function hS(t,e){return{kind:"validation",type:"regex",reference:hS,async:!1,expects:`${t}`,requirement:t,message:e,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&ne(this,"format",r,n),r}}}function pS(t){return{kind:"validation",type:"safe_integer",reference:pS,async:!1,expects:null,requirement:Number.isSafeInteger,message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"safe integer",e,r),e}}}function mS(t,e){return{kind:"validation",type:"size",reference:mS,async:!1,expects:`${t}`,requirement:t,message:e,_run(r,n){return r.typed&&r.value.size!==this.requirement&&ne(this,"size",r,n,{received:`${r.value.size}`}),r}}}function gS(t,e){return{kind:"validation",type:"some_item",reference:gS,async:!1,expects:null,requirement:t,message:e,_run(r,n){return r.typed&&!r.value.some(this.requirement)&&ne(this,"item",r,n),r}}}function yS(t){return{kind:"transformation",type:"sort_items",reference:yS,async:!1,operation:t,_run(e){return e.value=e.value.sort(this.operation),e}}}function _S(t,e){return{kind:"validation",type:"starts_with",reference:_S,async:!1,expects:`"${t}"`,requirement:t,message:e,_run(r,n){return r.typed&&!r.value.startsWith(this.requirement)&&ne(this,"start",r,n,{received:`"${r.value.slice(0,this.requirement.length)}"`}),r}}}function vS(){return{kind:"transformation",type:"to_lower_case",reference:vS,async:!1,_run(t){return t.value=t.value.toLowerCase(),t}}}function bS(t){return{kind:"transformation",type:"to_max_value",reference:bS,async:!1,requirement:t,_run(e){return e.value=e.value>this.requirement?this.requirement:e.value,e}}}function wS(t){return{kind:"transformation",type:"to_min_value",reference:wS,async:!1,requirement:t,_run(e){return e.value=e.value<this.requirement?this.requirement:e.value,e}}}function MS(){return{kind:"transformation",type:"to_upper_case",reference:MS,async:!1,_run(t){return t.value=t.value.toUpperCase(),t}}}function SS(t){return{kind:"transformation",type:"transform",reference:SS,async:!1,operation:t,_run(e){return e.value=this.operation(e.value),e}}}function kS(t){return{kind:"transformation",type:"transform",reference:kS,async:!0,operation:t,async _run(e){return e.value=await this.operation(e.value),e}}}function OS(){return{kind:"transformation",type:"trim",reference:OS,async:!1,_run(t){return t.value=t.value.trim(),t}}}function ES(){return{kind:"transformation",type:"trim_end",reference:ES,async:!1,_run(t){return t.value=t.value.trimEnd(),t}}}function AS(){return{kind:"transformation",type:"trim_start",reference:AS,async:!1,_run(t){return t.value=t.value.trimStart(),t}}}function IS(t){return{kind:"validation",type:"ulid",reference:IS,async:!1,expects:null,requirement:Z2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"ULID",e,r),e}}}function TS(t){return{kind:"validation",type:"url",reference:TS,async:!1,expects:null,requirement(e){try{return new URL(e),!0}catch{return!1}},message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"URL",e,r),e}}}function xS(t){return{kind:"validation",type:"uuid",reference:xS,async:!1,expects:null,requirement:Y2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"UUID",e,r),e}}}function PS(t,e){return{kind:"validation",type:"value",reference:PS,async:!1,expects:t instanceof Date?t.toJSON():on(t),requirement:t,message:e,_run(r,n){return r.typed&&!(this.requirement<=r.value&&this.requirement>=r.value)&&ne(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():on(r.value)}),r}}}function PN(t,e){return{...t,_run(r,n){return t._run(r,{...n,...e})}}}function nc(t,e,r){return typeof t.fallback=="function"?t.fallback(e,r):t.fallback}function CN(t,e){return{...t,fallback:e,_run(r,n){return t._run(r,n),r.issues?{typed:!0,value:nc(this,r,n)}:r}}}function jN(t,e){return{...t,fallback:e,async:!0,async _run(r,n){return t._run(r,n),r.issues?{typed:!0,value:await nc(this,r,n)}:r}}}function NN(t){let e={};for(let r of t)if(r.path){let n=rM(r);n?(e.nested||(e.nested={}),e.nested[n]?e.nested[n].push(r.message):e.nested[n]=[r.message]):e.other?e.other.push(r.message):e.other=[r.message]}else e.root?e.root.push(r.message):e.root=[r.message];return e}function DN(t,e){return{...t,_run(r,n){let i=r.issues&&[...r.issues];if(t._run(r,n),r.issues){for(let s of r.issues)if(!i?.includes(s)){let o=r.value;for(let u of e){let c=o[u],d={type:"unknown",origin:"value",input:o,key:u,value:c};if(s.path?s.path.push(d):s.path=[d],!c)break;o=c}}}return r}}}function BN(t,e){return{...t,async:!0,async _run(r,n){let i=r.issues&&[...r.issues];if(await t._run(r,n),r.issues){for(let s of r.issues)if(!i?.includes(s)){let o=r.value;for(let u of e){let c=o[u],d={type:"unknown",origin:"value",input:o,key:u,value:c};if(s.path?s.path.push(d):s.path=[d],!c)break;o=c}}}return r}}}function _s(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function U0(t){if("entries"in t){let e={};for(let r in t.entries)e[r]=U0(t.entries[r]);return e}return"items"in t?t.items.map(U0):_s(t)}async function L0(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([e,r])=>[e,await L0(r)]))):"items"in t?Promise.all(t.items.map(L0)):_s(t)}function $0(t){if("entries"in t){let e={};for(let r in t.entries)e[r]=$0(t.entries[r]);return e}return"items"in t?t.items.map($0):nc(t)}async function F0(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([e,r])=>[e,await F0(r)]))):"items"in t?Promise.all(t.items.map(F0)):nc(t)}function RN(t,e){return!t._run({typed:!1,value:e},{abortEarly:!0}).issues}function CS(){return{kind:"schema",type:"any",reference:CS,expects:"any",async:!1,_run(t){return t.typed=!0,t}}}function jS(t,e){return{kind:"schema",type:"array",reference:jS,expects:"Array",async:!1,item:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<i.length;s++){let o=i[s],u=this.item._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else ne(this,"type",r,n);return r}}}function NS(t,e){return{kind:"schema",type:"array",reference:NS,expects:"Array",async:!0,item:t,message:e,async _run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];let s=await Promise.all(i.map(o=>this.item._run({typed:!1,value:o},n)));for(let o=0;o<s.length;o++){let u=s[o];if(u.issues){let c={type:"array",origin:"value",input:i,key:o,value:i[o]};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else ne(this,"type",r,n);return r}}}function DS(t){return{kind:"schema",type:"bigint",reference:DS,expects:"bigint",async:!1,message:t,_run(e,r){return typeof e.value=="bigint"?e.typed=!0:ne(this,"type",e,r),e}}}function BS(t){return{kind:"schema",type:"blob",reference:BS,expects:"Blob",async:!1,message:t,_run(e,r){return e.value instanceof Blob?e.typed=!0:ne(this,"type",e,r),e}}}function RS(t){return{kind:"schema",type:"boolean",reference:RS,expects:"boolean",async:!1,message:t,_run(e,r){return typeof e.value=="boolean"?e.typed=!0:ne(this,"type",e,r),e}}}function US(t,e){return{kind:"schema",type:"custom",reference:US,expects:"unknown",async:!1,check:t,message:e,_run(r,n){return this.check(r.value)?r.typed=!0:ne(this,"type",r,n),r}}}function LS(t,e){return{kind:"schema",type:"custom",reference:LS,expects:"unknown",async:!0,check:t,message:e,async _run(r,n){return await this.check(r.value)?r.typed=!0:ne(this,"type",r,n),r}}}function $S(t){return{kind:"schema",type:"date",reference:$S,expects:"Date",async:!1,message:t,_run(e,r){return e.value instanceof Date?isNaN(e.value)?ne(this,"type",e,r,{received:'"Invalid Date"'}):e.typed=!0:ne(this,"type",e,r),e}}}function q0(t,e){let r=Object.entries(t).filter(([n])=>isNaN(+n)).map(([,n])=>n);return{kind:"schema",type:"enum",reference:q0,expects:r.map(on).join(" | ")||"never",async:!1,enum:t,options:r,message:e,_run(n,i){return this.options.includes(n.value)?n.typed=!0:ne(this,"type",n,i),n}}}function FS(t){return{kind:"schema",type:"file",reference:FS,expects:"File",async:!1,message:t,_run(e,r){return e.value instanceof File?e.typed=!0:ne(this,"type",e,r),e}}}function V0(t){return{kind:"schema",type:"function",reference:V0,expects:"Function",async:!1,message:t,_run(e,r){return typeof e.value=="function"?e.typed=!0:ne(this,"type",e,r),e}}}function qS(t,e){return{kind:"schema",type:"instance",reference:qS,expects:t.name,async:!1,class:t,message:e,_run(r,n){return r.value instanceof this.class?r.typed=!0:ne(this,"type",r,n),r}}}function uf(t,e){if(typeof t==typeof e){if(t===e||t instanceof Date&&e instanceof Date&&+t==+e)return{value:t};if(t&&e&&t.constructor===Object&&e.constructor===Object){for(let r in e)if(r in t){let n=uf(t[r],e[r]);if(n.issue)return n;t[r]=n.value}else t[r]=e[r];return{value:t}}if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length){for(let r=0;r<t.length;r++){let n=uf(t[r],e[r]);if(n.issue)return n;t[r]=n.value}return{value:t}}}return{issue:!0}}function VS(t,e){return{kind:"schema",type:"intersect",reference:VS,expects:[...new Set(t.map(r=>r.expects))].join(" & ")||"never",async:!1,options:t,message:e,_run(r,n){if(this.options.length){let i=r.value,s;r.typed=!0;for(let o of this.options){let u=o._run({typed:!1,value:i},n);if(u.issues&&(r.issues?r.issues.push(...u.issues):r.issues=u.issues,n.abortEarly)){r.typed=!1;break}u.typed||(r.typed=!1),r.typed&&(s?s.push(u.value):s=[u.value])}if(r.typed){r.value=s[0];for(let o=1;o<s.length;o++){let u=uf(r.value,s[o]);if(u.issue){ne(this,"type",r,n,{received:"unknown"});break}r.value=u.value}}}else ne(this,"type",r,n);return r}}}function zS(t,e){return{kind:"schema",type:"intersect",reference:zS,expects:[...new Set(t.map(r=>r.expects))].join(" & ")||"never",async:!0,options:t,message:e,async _run(r,n){if(this.options.length){let i=r.value,s;r.typed=!0;let o=await Promise.all(this.options.map(u=>u._run({typed:!1,value:i},n)));for(let u of o){if(u.issues&&(r.issues?r.issues.push(...u.issues):r.issues=u.issues,n.abortEarly)){r.typed=!1;break}u.typed||(r.typed=!1),r.typed&&(s?s.push(u.value):s=[u.value])}if(r.typed){r.value=s[0];for(let u=1;u<s.length;u++){let c=uf(r.value,s[u]);if(c.issue){ne(this,"type",r,n,{received:"unknown"});break}r.value=c.value}}}else ne(this,"type",r,n);return r}}}function GS(t){return{kind:"schema",type:"lazy",reference:GS,expects:"unknown",async:!1,getter:t,_run(e,r){return this.getter(e.value)._run(e,r)}}}function HS(t){return{kind:"schema",type:"lazy",reference:HS,expects:"unknown",async:!0,getter:t,async _run(e,r){return(await this.getter(e.value))._run(e,r)}}}function WS(t,e){return{kind:"schema",type:"literal",reference:WS,expects:on(t),async:!1,literal:t,message:e,_run(r,n){return r.value===this.literal?r.typed=!0:ne(this,"type",r,n),r}}}function KS(t,e){return{kind:"schema",type:"loose_object",reference:KS,expects:"Object",async:!1,entries:t,message:e,_run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(let s in this.entries){let o=i[s],u=this.entries[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"object",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),(u.value!==void 0||s in i)&&(r.value[s]=u.value)}if(!r.issues||!n.abortEarly)for(let s in i)Jo(i,s)&&!(s in this.entries)&&(r.value[s]=i[s])}else ne(this,"type",r,n);return r}}}function XS(t,e){return{kind:"schema",type:"loose_object",reference:XS,expects:"Object",async:!0,entries:t,message:e,async _run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};let s=await Promise.all(Object.entries(this.entries).map(async([o,u])=>{let c=i[o];return[o,c,await u._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"object",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),(c.value!==void 0||o in i)&&(r.value[o]=c.value)}if(!r.issues||!n.abortEarly)for(let o in i)Jo(i,o)&&!(o in this.entries)&&(r.value[o]=i[o])}else ne(this,"type",r,n);return r}}}function JS(t,e){return{kind:"schema",type:"loose_tuple",reference:JS,expects:"Array",async:!1,items:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<this.items.length;s++){let o=i[s],u=this.items[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}if(!r.issues||!n.abortEarly)for(let s=this.items.length;s<i.length;s++)r.value.push(i[s])}else ne(this,"type",r,n);return r}}}function ZS(t,e){return{kind:"schema",type:"loose_tuple",reference:ZS,expects:"Array",async:!0,items:t,message:e,async _run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];let s=await Promise.all(this.items.map(async(o,u)=>{let c=i[u];return[u,c,await o._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"array",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}if(!r.issues||!n.abortEarly)for(let o=this.items.length;o<i.length;o++)r.value.push(i[o])}else ne(this,"type",r,n);return r}}}function YS(t,e,r){return{kind:"schema",type:"map",reference:YS,expects:"Map",async:!1,key:t,value:e,message:r,_run(n,i){let s=n.value;if(s instanceof Map){n.typed=!0,n.value=new Map;for(let[o,u]of s){let c=this.key._run({typed:!1,value:o},i);if(c.issues){let p={type:"map",origin:"key",input:s,key:o,value:u};for(let _ of c.issues)_.path?_.path.unshift(p):_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}let d=this.value._run({typed:!1,value:u},i);if(d.issues){let p={type:"map",origin:"value",input:s,key:o,value:u};for(let _ of d.issues)_.path?_.path.unshift(p):_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=d.issues),i.abortEarly){n.typed=!1;break}}(!c.typed||!d.typed)&&(n.typed=!1),n.value.set(c.value,d.value)}}else ne(this,"type",n,i);return n}}}function QS(t,e,r){return{kind:"schema",type:"map",reference:QS,expects:"Map",async:!0,key:t,value:e,message:r,async _run(n,i){let s=n.value;if(s instanceof Map){n.typed=!0,n.value=new Map;let o=await Promise.all([...s].map(([u,c])=>Promise.all([u,c,this.key._run({typed:!1,value:u},i),this.value._run({typed:!1,value:c},i)])));for(let[u,c,d,p]of o){if(d.issues){let _={type:"map",origin:"key",input:s,key:u,value:c};for(let b of d.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=d.issues),i.abortEarly){n.typed=!1;break}}if(p.issues){let _={type:"map",origin:"value",input:s,key:u,value:c};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}(!d.typed||!p.typed)&&(n.typed=!1),n.value.set(d.value,p.value)}}else ne(this,"type",n,i);return n}}}function ek(t){return{kind:"schema",type:"nan",reference:ek,expects:"NaN",async:!1,message:t,_run(e,r){return Number.isNaN(e.value)?e.typed=!0:ne(this,"type",e,r),e}}}function tk(t){return{kind:"schema",type:"never",reference:tk,expects:"never",async:!1,message:t,_run(e,r){return ne(this,"type",e,r),e}}}function rk(t,e){return{kind:"schema",type:"non_nullable",reference:rk,expects:"!null",async:!1,wrapped:t,message:e,_run(r,n){return r.value===null?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function nk(t,e){return{kind:"schema",type:"non_nullable",reference:nk,expects:"!null",async:!0,wrapped:t,message:e,async _run(r,n){return r.value===null?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function ik(t,e){return{kind:"schema",type:"non_nullish",reference:ik,expects:"!null & !undefined",async:!1,wrapped:t,message:e,_run(r,n){return r.value===null||r.value===void 0?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function sk(t,e){return{kind:"schema",type:"non_nullish",reference:sk,expects:"!null & !undefined",async:!0,wrapped:t,message:e,async _run(r,n){return r.value===null||r.value===void 0?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function X0(t,e){return{kind:"schema",type:"non_optional",reference:X0,expects:"!undefined",async:!1,wrapped:t,message:e,_run(r,n){return r.value===void 0?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function J0(t,e){return{kind:"schema",type:"non_optional",reference:J0,expects:"!undefined",async:!0,wrapped:t,message:e,async _run(r,n){return r.value===void 0?(ne(this,"type",r,n),r):this.wrapped._run(r,n)}}}function z0(t){return{kind:"schema",type:"null",reference:z0,expects:"null",async:!1,message:t,_run(e,r){return e.value===null?e.typed=!0:ne(this,"type",e,r),e}}}function ok(t,...e){let r={kind:"schema",type:"nullable",reference:ok,expects:`${t.expects} | null`,async:!1,wrapped:t,_run(n,i){return n.value===null&&("default"in this&&(n.value=_s(this,n,i)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function ak(t,...e){let r={kind:"schema",type:"nullable",reference:ak,expects:`${t.expects} | null`,async:!0,wrapped:t,async _run(n,i){return n.value===null&&("default"in this&&(n.value=await _s(this,n,i)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function uk(t,...e){let r={kind:"schema",type:"nullish",reference:uk,expects:`${t.expects} | null | undefined`,async:!1,wrapped:t,_run(n,i){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=_s(this,n,i)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function ck(t,...e){let r={kind:"schema",type:"nullish",reference:ck,expects:`${t.expects} | null | undefined`,async:!0,wrapped:t,async _run(n,i){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=await _s(this,n,i)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function lk(t){return{kind:"schema",type:"number",reference:lk,expects:"number",async:!1,message:t,_run(e,r){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:ne(this,"type",e,r),e}}}function fk(t,e){return{kind:"schema",type:"object",reference:fk,expects:"Object",async:!1,entries:t,message:e,_run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(let s in this.entries){let o=i[s],u=this.entries[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"object",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),(u.value!==void 0||s in i)&&(r.value[s]=u.value)}}else ne(this,"type",r,n);return r}}}function dk(t,e){return{kind:"schema",type:"object",reference:dk,expects:"Object",async:!0,entries:t,message:e,async _run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};let s=await Promise.all(Object.entries(this.entries).map(async([o,u])=>{let c=i[o];return[o,c,await u._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"object",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),(c.value!==void 0||o in i)&&(r.value[o]=c.value)}}else ne(this,"type",r,n);return r}}}function hk(t,e,r){return{kind:"schema",type:"object_with_rest",reference:hk,expects:"Object",async:!1,entries:t,rest:e,message:r,_run(n,i){let s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};for(let o in this.entries){let u=s[o],c=this.entries[o]._run({typed:!1,value:u},i);if(c.issues){let d={type:"object",origin:"value",input:s,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],n.issues?.push(p);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),(c.value!==void 0||o in s)&&(n.value[o]=c.value)}if(!n.issues||!i.abortEarly){for(let o in s)if(Jo(s,o)&&!(o in this.entries)){let u=s[o],c=this.rest._run({typed:!1,value:u},i);if(c.issues){let d={type:"object",origin:"value",input:s,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],n.issues?.push(p);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value[o]=c.value}}}else ne(this,"type",n,i);return n}}}function pk(t,e,r){return{kind:"schema",type:"object_with_rest",reference:pk,expects:"Object",async:!0,entries:t,rest:e,message:r,async _run(n,i){let s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};let[o,u]=await Promise.all([Promise.all(Object.entries(this.entries).map(async([c,d])=>{let p=s[c];return[c,p,await d._run({typed:!1,value:p},i)]})),Promise.all(Object.entries(s).filter(([c])=>Jo(s,c)&&!(c in this.entries)).map(async([c,d])=>[c,d,await this.rest._run({typed:!1,value:d},i)]))]);for(let[c,d,p]of o){if(p.issues){let _={type:"object",origin:"value",input:s,key:c,value:d};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}p.typed||(n.typed=!1),(p.value!==void 0||c in s)&&(n.value[c]=p.value)}if(!n.issues||!i.abortEarly)for(let[c,d,p]of u){if(p.issues){let _={type:"object",origin:"value",input:s,key:c,value:d};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}p.typed||(n.typed=!1),n.value[c]=p.value}}else ne(this,"type",n,i);return n}}}function Z0(t,...e){let r={kind:"schema",type:"optional",reference:Z0,expects:`${t.expects} | undefined`,async:!1,wrapped:t,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=_s(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function Y0(t,...e){let r={kind:"schema",type:"optional",reference:Y0,expects:`${t.expects} | undefined`,async:!0,wrapped:t,async _run(n,i){return n.value===void 0&&("default"in this&&(n.value=await _s(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function Q0(t,e){return{kind:"schema",type:"picklist",reference:Q0,expects:t.map(on).join(" | ")||"never",async:!1,options:t,message:e,_run(r,n){return this.options.includes(r.value)?r.typed=!0:ne(this,"type",r,n),r}}}function mk(t){return{kind:"schema",type:"promise",reference:mk,expects:"Promise",async:!1,message:t,_run(e,r){return e.value instanceof Promise?e.typed=!0:ne(this,"type",e,r),e}}}function gk(t,e,r){return{kind:"schema",type:"record",reference:gk,expects:"Object",async:!1,key:t,value:e,message:r,_run(n,i){let s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};for(let o in s)if(Jo(s,o)){let u=s[o],c=this.key._run({typed:!1,value:o},i);if(c.issues){let p={type:"object",origin:"key",input:s,key:o,value:u};for(let _ of c.issues)_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}let d=this.value._run({typed:!1,value:u},i);if(d.issues){let p={type:"object",origin:"value",input:s,key:o,value:u};for(let _ of d.issues)_.path?_.path.unshift(p):_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=d.issues),i.abortEarly){n.typed=!1;break}}(!c.typed||!d.typed)&&(n.typed=!1),c.typed&&(n.value[c.value]=d.value)}}else ne(this,"type",n,i);return n}}}function yk(t,e,r){return{kind:"schema",type:"record",reference:yk,expects:"Object",async:!0,key:t,value:e,message:r,async _run(n,i){let s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};let o=await Promise.all(Object.entries(s).filter(([u])=>Jo(s,u)).map(([u,c])=>Promise.all([u,c,this.key._run({typed:!1,value:u},i),this.value._run({typed:!1,value:c},i)])));for(let[u,c,d,p]of o){if(d.issues){let _={type:"object",origin:"key",input:s,key:u,value:c};for(let b of d.issues)b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=d.issues),i.abortEarly){n.typed=!1;break}}if(p.issues){let _={type:"object",origin:"value",input:s,key:u,value:c};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}(!d.typed||!p.typed)&&(n.typed=!1),d.typed&&(n.value[d.value]=p.value)}}else ne(this,"type",n,i);return n}}}function _k(t,e){return{kind:"schema",type:"set",reference:_k,expects:"Set",async:!1,value:t,message:e,_run(r,n){let i=r.value;if(i instanceof Set){r.typed=!0,r.value=new Set;for(let s of i){let o=this.value._run({typed:!1,value:s},n);if(o.issues){let u={type:"set",origin:"value",input:i,key:null,value:s};for(let c of o.issues)c.path?c.path.unshift(u):c.path=[u],r.issues?.push(c);if(r.issues||(r.issues=o.issues),n.abortEarly){r.typed=!1;break}}o.typed||(r.typed=!1),r.value.add(o.value)}}else ne(this,"type",r,n);return r}}}function vk(t,e){return{kind:"schema",type:"set",reference:vk,expects:"Set",async:!0,value:t,message:e,async _run(r,n){let i=r.value;if(i instanceof Set){r.typed=!0,r.value=new Set;let s=await Promise.all([...i].map(async o=>[o,await this.value._run({typed:!1,value:o},n)]));for(let[o,u]of s){if(u.issues){let c={type:"set",origin:"value",input:i,key:null,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.add(u.value)}}else ne(this,"type",r,n);return r}}}function bk(t,e){return{kind:"schema",type:"strict_object",reference:bk,expects:"Object",async:!1,entries:t,message:e,_run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(let s in this.entries){let o=i[s],u=this.entries[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"object",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),(u.value!==void 0||s in i)&&(r.value[s]=u.value)}if(!r.issues||!n.abortEarly){for(let s in i)if(!(s in this.entries)){let o=i[s];ne(this,"type",r,n,{input:o,expected:"never",path:[{type:"object",origin:"value",input:i,key:s,value:o}]});break}}}else ne(this,"type",r,n);return r}}}function wk(t,e){return{kind:"schema",type:"strict_object",reference:wk,expects:"Object",async:!0,entries:t,message:e,async _run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};let s=await Promise.all(Object.entries(this.entries).map(async([o,u])=>{let c=i[o];return[o,c,await u._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"object",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),(c.value!==void 0||o in i)&&(r.value[o]=c.value)}if(!r.issues||!n.abortEarly){for(let o in i)if(!(o in this.entries)){let u=i[o];ne(this,"type",r,n,{input:u,expected:"never",path:[{type:"object",origin:"value",input:i,key:o,value:u}]});break}}}else ne(this,"type",r,n);return r}}}function Mk(t,e){return{kind:"schema",type:"strict_tuple",reference:Mk,expects:"Array",async:!1,items:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<this.items.length;s++){let o=i[s],u=this.items[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}if(!(r.issues&&n.abortEarly)&&this.items.length<i.length){let s=i[t.length];ne(this,"type",r,n,{input:s,expected:"never",path:[{type:"array",origin:"value",input:i,key:this.items.length,value:s}]})}}else ne(this,"type",r,n);return r}}}function Sk(t,e){return{kind:"schema",type:"strict_tuple",reference:Sk,expects:"Array",async:!0,items:t,message:e,async _run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];let s=await Promise.all(this.items.map(async(o,u)=>{let c=i[u];return[u,c,await o._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"array",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}if(!(r.issues&&n.abortEarly)&&this.items.length<i.length){let o=i[t.length];ne(this,"type",r,n,{input:o,expected:"never",path:[{type:"array",origin:"value",input:i,key:this.items.length,value:o}]})}}else ne(this,"type",r,n);return r}}}function kk(t){return{kind:"schema",type:"string",reference:kk,expects:"string",async:!1,message:t,_run(e,r){return typeof e.value=="string"?e.typed=!0:ne(this,"type",e,r),e}}}function Ok(t){return{kind:"schema",type:"symbol",reference:Ok,expects:"symbol",async:!1,message:t,_run(e,r){return typeof e.value=="symbol"?e.typed=!0:ne(this,"type",e,r),e}}}function Ek(t,e){return{kind:"schema",type:"tuple",reference:Ek,expects:"Array",async:!1,items:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<this.items.length;s++){let o=i[s],u=this.items[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else ne(this,"type",r,n);return r}}}function Ak(t,e){return{kind:"schema",type:"tuple",reference:Ak,expects:"Array",async:!0,items:t,message:e,async _run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];let s=await Promise.all(this.items.map(async(o,u)=>{let c=i[u];return[u,c,await o._run({typed:!1,value:c},n)]}));for(let[o,u,c]of s){if(c.issues){let d={type:"array",origin:"value",input:i,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],r.issues?.push(p);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}}else ne(this,"type",r,n);return r}}}function Ik(t,e,r){return{kind:"schema",type:"tuple_with_rest",reference:Ik,expects:"Array",async:!1,items:t,rest:e,message:r,_run(n,i){let s=n.value;if(Array.isArray(s)){n.typed=!0,n.value=[];for(let o=0;o<this.items.length;o++){let u=s[o],c=this.items[o]._run({typed:!1,value:u},i);if(c.issues){let d={type:"array",origin:"value",input:s,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],n.issues?.push(p);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}if(!n.issues||!i.abortEarly)for(let o=this.items.length;o<s.length;o++){let u=s[o],c=this.rest._run({typed:!1,value:u},i);if(c.issues){let d={type:"array",origin:"value",input:s,key:o,value:u};for(let p of c.issues)p.path?p.path.unshift(d):p.path=[d],n.issues?.push(p);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else ne(this,"type",n,i);return n}}}function Tk(t,e,r){return{kind:"schema",type:"tuple_with_rest",reference:Tk,expects:"Array",async:!0,items:t,rest:e,message:r,async _run(n,i){let s=n.value;if(Array.isArray(s)){n.typed=!0,n.value=[];let[o,u]=await Promise.all([Promise.all(this.items.map(async(c,d)=>{let p=s[d];return[d,p,await c._run({typed:!1,value:p},i)]})),Promise.all(s.slice(this.items.length).map(async(c,d)=>[d+this.items.length,c,await this.rest._run({typed:!1,value:c},i)]))]);for(let[c,d,p]of o){if(p.issues){let _={type:"array",origin:"value",input:s,key:c,value:d};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}p.typed||(n.typed=!1),n.value.push(p.value)}if(!n.issues||!i.abortEarly)for(let[c,d,p]of u){if(p.issues){let _={type:"array",origin:"value",input:s,key:c,value:d};for(let b of p.issues)b.path?b.path.unshift(_):b.path=[_],n.issues?.push(b);if(n.issues||(n.issues=p.issues),i.abortEarly){n.typed=!1;break}}p.typed||(n.typed=!1),n.value.push(p.value)}}else ne(this,"type",n,i);return n}}}function G0(t){return{kind:"schema",type:"undefined",reference:G0,expects:"undefined",async:!1,message:t,_run(e,r){return e.value===void 0?e.typed=!0:ne(this,"type",e,r),e}}}function cf(t){let e;if(t)for(let r of t)e?e.push(...r.issues):e=r.issues;return e}function xk(t,e){return{kind:"schema",type:"union",reference:xk,expects:[...new Set(t.map(r=>r.expects))].join(" | ")||"never",async:!1,options:t,message:e,_run(r,n){let i,s,o;for(let u of this.options){let c=u._run({typed:!1,value:r.value},n);if(c.typed)if(c.issues)s?s.push(c):s=[c];else{i=c;break}else o?o.push(c):o=[c]}if(i)return i;if(s){if(s.length===1)return s[0];ne(this,"type",r,n,{issues:cf(s)}),r.typed=!0}else{if(o?.length===1)return o[0];ne(this,"type",r,n,{issues:cf(o)})}return r}}}function Pk(t,e){return{kind:"schema",type:"union",reference:Pk,expects:[...new Set(t.map(r=>r.expects))].join(" | ")||"never",async:!0,options:t,message:e,async _run(r,n){let i,s,o;for(let u of this.options){let c=await u._run({typed:!1,value:r.value},n);if(c.typed)if(c.issues)s?s.push(c):s=[c];else{i=c;break}else o?o.push(c):o=[c]}if(i)return i;if(s){if(s.length===1)return s[0];ne(this,"type",r,n,{issues:cf(s)}),r.typed=!0}else{if(o?.length===1)return o[0];ne(this,"type",r,n,{issues:cf(o)})}return r}}}function Ck(){return{kind:"schema",type:"unknown",reference:Ck,expects:"unknown",async:!1,_run(t){return t.typed=!0,t}}}function em(t,e,r=new Set){for(let n of e)n.type==="variant"?em(t,n.options,r):r.add(n.entries[t].expects);return r}function jk(t,e,r){let n;return{kind:"schema",type:"variant",reference:jk,expects:"Object",async:!1,key:t,options:e,message:r,_run(i,s){let o=i.value;if(o&&typeof o=="object"){let u=o[this.key];if(this.key in o){let c;for(let d of this.options)if(d.type==="variant"||!d.entries[this.key]._run({typed:!1,value:u},s).issues){let p=d._run({typed:!1,value:o},s);if(!p.issues)return p;(!c||!c.typed&&p.typed)&&(c=p)}if(c)return c}n||(n=[...em(this.key,this.options)].join(" | ")||"never"),ne(this,"type",i,s,{input:u,expected:n,path:[{type:"object",origin:"value",input:o,key:this.key,value:u}]})}else ne(this,"type",i,s);return i}}}function Nk(t,e,r){let n;return{kind:"schema",type:"variant",reference:Nk,expects:"Object",async:!0,key:t,options:e,message:r,async _run(i,s){let o=i.value;if(o&&typeof o=="object"){let u=o[this.key];if(this.key in o){let c;for(let d of this.options)if(d.type==="variant"||!(await d.entries[this.key]._run({typed:!1,value:u},s)).issues){let p=await d._run({typed:!1,value:o},s);if(!p.issues)return p;(!c||!c.typed&&p.typed)&&(c=p)}if(c)return c}n||(n=[...em(this.key,this.options)].join(" | ")||"never"),ne(this,"type",i,s,{input:u,expected:n,path:[{type:"object",origin:"value",input:o,key:this.key,value:u}]})}else ne(this,"type",i,s);return i}}}function H0(t){return{kind:"schema",type:"void",reference:H0,expects:"void",async:!1,message:t,_run(e,r){return e.value===void 0?e.typed=!0:ne(this,"type",e,r),e}}}function UN(t,e){return Q0(Object.keys(t.entries),e)}function LN(t,e){let r={...t.entries};for(let n of e)delete r[n];return{...t,entries:r}}function Dk(t,e,r){let n=t._run({typed:!1,value:e},rc(r));if(n.issues)throw new lf(n.issues);return n.value}async function Bk(t,e,r){let n=await t._run({typed:!1,value:e},rc(r));if(n.issues)throw new lf(n.issues);return n.value}function $N(t,e){let r=n=>Dk(t,n,e);return r.schema=t,r.config=e,r}function FN(t,e){let r=n=>Bk(t,n,e);return r.schema=t,r.config=e,r}function qN(t,e){let r={};for(let n in t.entries)r[n]=!e||e.includes(n)?Z0(t.entries[n]):t.entries[n];return{...t,entries:r}}function VN(t,e){let r={};for(let n in t.entries)r[n]=!e||e.includes(n)?Y0(t.entries[n]):t.entries[n];return{...t,entries:r}}function zN(t,e){let r={};for(let n of e)r[n]=t.entries[n];return{...t,entries:r}}function GN(...t){return{...t[0],pipe:t,_run(e,r){for(let n=0;n<t.length;n++){if(e.issues&&(t[n].kind==="schema"||t[n].kind==="transformation")){e.typed=!1;break}(!e.issues||!r.abortEarly&&!r.abortPipeEarly)&&(e=t[n]._run(e,r))}return e}}}function HN(...t){return{...t[0],pipe:t,async:!0,async _run(e,r){for(let n=0;n<t.length;n++){if(e.issues&&(t[n].kind==="schema"||t[n].kind==="transformation")){e.typed=!1;break}(!e.issues||!r.abortEarly&&!r.abortPipeEarly)&&(e=await t[n]._run(e,r))}return e}}}function WN(t,e,r){let n=Array.isArray(e)?e:void 0,i=Array.isArray(e)?r:e,s={};for(let o in t.entries)s[o]=!n||n.includes(o)?X0(t.entries[o],i):t.entries[o];return{...t,entries:s}}function KN(t,e,r){let n=Array.isArray(e)?e:void 0,i=Array.isArray(e)?r:e,s={};for(let o in t.entries)s[o]=!n||n.includes(o)?J0(t.entries[o],i):t.entries[o];return{...t,entries:s}}function Rk(t,e,r){let n=t._run({typed:!1,value:e},rc(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}async function Uk(t,e,r){let n=await t._run({typed:!1,value:e},rc(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}function XN(t,e){let r=n=>Rk(t,n,e);return r.schema=t,r.config=e,r}function JN(t,e){let r=n=>Uk(t,n,e);return r.schema=t,r.config=e,r}function ZN(t){return t.wrapped}});var uo=be((qY,Wk)=>{"use strict";var tm=Object.defineProperty,YN=Object.getOwnPropertyDescriptor,QN=Object.getOwnPropertyNames,eD=Object.prototype.hasOwnProperty,tD=(t,e)=>{for(var r in e)tm(t,r,{get:e[r],enumerable:!0})},rD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of QN(e))!eD.call(t,i)&&i!==r&&tm(t,i,{get:()=>e[i],enumerable:!(n=YN(e,i))||n.enumerable});return t},nD=t=>rD(tm({},"__esModule",{value:!0}),t),Fk={};tD(Fk,{$Intent:()=>zk,Argument:()=>Un,BCSBytes:()=>ic,Command:()=>Gk,GasData:()=>qk,JsonU64:()=>ao,NormalizedCallArg:()=>aD,ObjectArg:()=>rm,ObjectID:()=>Zo,ObjectRef:()=>ff,OpenMoveTypeSignature:()=>Vk,OpenMoveTypeSignatureBody:()=>df,StructTag:()=>iD,SuiAddress:()=>sc,TransactionData:()=>uD,TransactionExpiration:()=>Hk,safeEnum:()=>$a});Wk.exports=nD(Fk);var re=Wi(),$k=Nr();function $a(t){let e=Object.entries(t).map(([r,n])=>(0,re.object)({[r]:n}));return(0,re.pipe)((0,re.union)(e),(0,re.transform)(r=>({...r,$kind:Object.keys(r)[0]})))}var sc=(0,re.pipe)((0,re.string)(),(0,re.transform)(t=>(0,$k.normalizeSuiAddress)(t)),(0,re.check)($k.isValidSuiAddress)),Zo=sc,ic=(0,re.string)(),ao=(0,re.pipe)((0,re.union)([(0,re.string)(),(0,re.pipe)((0,re.number)(),(0,re.integer)())]),(0,re.check)(t=>{try{return BigInt(t),BigInt(t)>=0&&BigInt(t)<=18446744073709551615n}catch{return!1}},"Invalid u64")),ff=(0,re.object)({objectId:sc,version:ao,digest:(0,re.string)()}),Un=(0,re.pipe)((0,re.union)([(0,re.object)({GasCoin:(0,re.literal)(!0)}),(0,re.object)({Input:(0,re.pipe)((0,re.number)(),(0,re.integer)()),type:(0,re.optional)((0,re.literal)("pure"))}),(0,re.object)({Input:(0,re.pipe)((0,re.number)(),(0,re.integer)()),type:(0,re.optional)((0,re.literal)("object"))}),(0,re.object)({Result:(0,re.pipe)((0,re.number)(),(0,re.integer)())}),(0,re.object)({NestedResult:(0,re.tuple)([(0,re.pipe)((0,re.number)(),(0,re.integer)()),(0,re.pipe)((0,re.number)(),(0,re.integer)())])})]),(0,re.transform)(t=>({...t,$kind:Object.keys(t)[0]}))),qk=(0,re.object)({budget:(0,re.nullable)(ao),price:(0,re.nullable)(ao),owner:(0,re.nullable)(sc),payment:(0,re.nullable)((0,re.array)(ff))}),iD=(0,re.object)({address:(0,re.string)(),module:(0,re.string)(),name:(0,re.string)(),typeParams:(0,re.array)((0,re.string)())}),df=(0,re.union)([(0,re.literal)("address"),(0,re.literal)("bool"),(0,re.literal)("u8"),(0,re.literal)("u16"),(0,re.literal)("u32"),(0,re.literal)("u64"),(0,re.literal)("u128"),(0,re.literal)("u256"),(0,re.object)({vector:(0,re.lazy)(()=>df)}),(0,re.object)({datatype:(0,re.object)({package:(0,re.string)(),module:(0,re.string)(),type:(0,re.string)(),typeParameters:(0,re.array)((0,re.lazy)(()=>df))})}),(0,re.object)({typeParameter:(0,re.pipe)((0,re.number)(),(0,re.integer)())})]),Vk=(0,re.object)({ref:(0,re.nullable)((0,re.union)([(0,re.literal)("&"),(0,re.literal)("&mut")])),body:df}),sD=(0,re.object)({package:Zo,module:(0,re.string)(),function:(0,re.string)(),typeArguments:(0,re.array)((0,re.string)()),arguments:(0,re.array)(Un),_argumentTypes:(0,re.optional)((0,re.nullable)((0,re.array)(Vk)))}),zk=(0,re.object)({name:(0,re.string)(),inputs:(0,re.record)((0,re.string)(),(0,re.union)([Un,(0,re.array)(Un)])),data:(0,re.record)((0,re.string)(),(0,re.unknown)())}),Gk=$a({MoveCall:sD,TransferObjects:(0,re.object)({objects:(0,re.array)(Un),address:Un}),SplitCoins:(0,re.object)({coin:Un,amounts:(0,re.array)(Un)}),MergeCoins:(0,re.object)({destination:Un,sources:(0,re.array)(Un)}),Publish:(0,re.object)({modules:(0,re.array)(ic),dependencies:(0,re.array)(Zo)}),MakeMoveVec:(0,re.object)({type:(0,re.nullable)((0,re.string)()),elements:(0,re.array)(Un)}),Upgrade:(0,re.object)({modules:(0,re.array)(ic),dependencies:(0,re.array)(Zo),package:Zo,ticket:Un}),$Intent:zk}),rm=$a({ImmOrOwnedObject:ff,SharedObject:(0,re.object)({objectId:Zo,initialSharedVersion:ao,mutable:(0,re.boolean)()}),Receiving:ff}),oD=$a({Object:rm,Pure:(0,re.object)({bytes:ic}),UnresolvedPure:(0,re.object)({value:(0,re.unknown)()}),UnresolvedObject:(0,re.object)({objectId:Zo,version:(0,re.optional)((0,re.nullable)(ao)),digest:(0,re.optional)((0,re.nullable)((0,re.string)())),initialSharedVersion:(0,re.optional)((0,re.nullable)(ao))})}),aD=$a({Object:rm,Pure:(0,re.object)({bytes:ic})}),Hk=$a({None:(0,re.literal)(!0),Epoch:ao}),uD=(0,re.object)({version:(0,re.literal)(2),sender:(0,re.nullish)(sc),expiration:(0,re.nullish)(Hk),gasData:qk,inputs:(0,re.array)(oD),commands:(0,re.array)(Gk)})});var hf=be((VY,Yk)=>{"use strict";var nm=Object.defineProperty,cD=Object.getOwnPropertyDescriptor,lD=Object.getOwnPropertyNames,fD=Object.prototype.hasOwnProperty,dD=(t,e)=>{for(var r in e)nm(t,r,{get:e[r],enumerable:!0})},hD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lD(e))!fD.call(t,i)&&i!==r&&nm(t,i,{get:()=>e[i],enumerable:!(n=cD(e,i))||n.enumerable});return t},pD=t=>hD(nm({},"__esModule",{value:!0}),t),Jk={};dD(Jk,{Commands:()=>mD,UpgradePolicy:()=>Zk});Yk.exports=pD(Jk);var Kk=dr(),Ki=Wi(),Xk=Nr(),Xi=uo(),Zk=(t=>(t[t.COMPATIBLE=0]="COMPATIBLE",t[t.ADDITIVE=128]="ADDITIVE",t[t.DEP_ONLY=192]="DEP_ONLY",t))(Zk||{}),mD={MoveCall(t){let[e,r="",n=""]="target"in t?t.target.split("::"):[t.package,t.module,t.function];return{$kind:"MoveCall",MoveCall:{package:e,module:r,function:n,typeArguments:t.typeArguments??[],arguments:t.arguments??[]}}},TransferObjects(t,e){return{$kind:"TransferObjects",TransferObjects:{objects:t.map(r=>(0,Ki.parse)(Xi.Argument,r)),address:(0,Ki.parse)(Xi.Argument,e)}}},SplitCoins(t,e){return{$kind:"SplitCoins",SplitCoins:{coin:(0,Ki.parse)(Xi.Argument,t),amounts:e.map(r=>(0,Ki.parse)(Xi.Argument,r))}}},MergeCoins(t,e){return{$kind:"MergeCoins",MergeCoins:{destination:(0,Ki.parse)(Xi.Argument,t),sources:e.map(r=>(0,Ki.parse)(Xi.Argument,r))}}},Publish({modules:t,dependencies:e}){return{$kind:"Publish",Publish:{modules:t.map(r=>typeof r=="string"?r:(0,Kk.toBase64)(new Uint8Array(r))),dependencies:e.map(r=>(0,Xk.normalizeSuiObjectId)(r))}}},Upgrade({modules:t,dependencies:e,package:r,ticket:n}){return{$kind:"Upgrade",Upgrade:{modules:t.map(i=>typeof i=="string"?i:(0,Kk.toBase64)(new Uint8Array(i))),dependencies:e.map(i=>(0,Xk.normalizeSuiObjectId)(i)),package:r,ticket:(0,Ki.parse)(Xi.Argument,n)}}},MakeMoveVec({type:t,elements:e}){return{$kind:"MakeMoveVec",MakeMoveVec:{type:t??null,elements:e.map(r=>(0,Ki.parse)(Xi.Argument,r))}}},Intent({name:t,inputs:e={},data:r={}}){return{$kind:"$Intent",$Intent:{name:t,inputs:Object.fromEntries(Object.entries(e).map(([n,i])=>[n,Array.isArray(i)?i.map(s=>(0,Ki.parse)(Xi.Argument,s)):(0,Ki.parse)(Xi.Argument,i)])),data:r}}}}});var om=be((zY,iO)=>{"use strict";var sm=Object.defineProperty,gD=Object.getOwnPropertyDescriptor,yD=Object.getOwnPropertyNames,_D=Object.prototype.hasOwnProperty,vD=(t,e)=>{for(var r in e)sm(t,r,{get:e[r],enumerable:!0})},bD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yD(e))!_D.call(t,i)&&i!==r&&sm(t,i,{get:()=>e[i],enumerable:!(n=gD(e,i))||n.enumerable});return t},wD=t=>bD(sm({},"__esModule",{value:!0}),t),eO={};vD(eO,{NormalizedCallArg:()=>im,ObjectRef:()=>pf,SerializedTransactionDataV1:()=>DD,StructTag:()=>nO,TransactionArgument:()=>Ji,TypeTag:()=>mf,serializeV1TransactionData:()=>BD,transactionDataFromV1:()=>RD});iO.exports=wD(eO);var Fa=dr(),Q=Wi(),tO=Rn(),oc=uo(),pf=(0,Q.object)({digest:(0,Q.string)(),objectId:(0,Q.string)(),version:(0,Q.union)([(0,Q.pipe)((0,Q.number)(),(0,Q.integer)()),(0,Q.string)(),(0,Q.bigint)()])}),MD=(0,oc.safeEnum)({ImmOrOwned:pf,Shared:(0,Q.object)({objectId:oc.ObjectID,initialSharedVersion:oc.JsonU64,mutable:(0,Q.boolean)()}),Receiving:pf}),im=(0,oc.safeEnum)({Object:MD,Pure:(0,Q.array)((0,Q.pipe)((0,Q.number)(),(0,Q.integer)()))}),rO=(0,Q.union)([(0,Q.object)({kind:(0,Q.literal)("Input"),index:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)()),value:(0,Q.unknown)(),type:(0,Q.optional)((0,Q.literal)("object"))}),(0,Q.object)({kind:(0,Q.literal)("Input"),index:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)()),value:(0,Q.unknown)(),type:(0,Q.literal)("pure")})]),SD=(0,Q.union)([(0,Q.object)({Epoch:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)())}),(0,Q.object)({None:(0,Q.nullable)((0,Q.literal)(!0))})]),Qk=(0,Q.pipe)((0,Q.union)([(0,Q.number)(),(0,Q.string)(),(0,Q.bigint)()]),(0,Q.check)(t=>{if(!["string","number","bigint"].includes(typeof t))return!1;try{return BigInt(t),!0}catch{return!1}})),mf=(0,Q.union)([(0,Q.object)({bool:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({u8:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({u64:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({u128:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({address:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({signer:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({vector:(0,Q.lazy)(()=>mf)}),(0,Q.object)({struct:(0,Q.lazy)(()=>nO)}),(0,Q.object)({u16:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({u32:(0,Q.nullable)((0,Q.literal)(!0))}),(0,Q.object)({u256:(0,Q.nullable)((0,Q.literal)(!0))})]),nO=(0,Q.object)({address:(0,Q.string)(),module:(0,Q.string)(),name:(0,Q.string)(),typeParams:(0,Q.array)(mf)}),kD=(0,Q.object)({budget:(0,Q.optional)(Qk),price:(0,Q.optional)(Qk),payment:(0,Q.optional)((0,Q.array)(pf)),owner:(0,Q.optional)((0,Q.string)())}),OD=[rO,(0,Q.object)({kind:(0,Q.literal)("GasCoin")}),(0,Q.object)({kind:(0,Q.literal)("Result"),index:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)())}),(0,Q.object)({kind:(0,Q.literal)("NestedResult"),index:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)()),resultIndex:(0,Q.pipe)((0,Q.number)(),(0,Q.integer)())})],Ji=(0,Q.union)([...OD]),ED=(0,Q.object)({kind:(0,Q.literal)("MoveCall"),target:(0,Q.pipe)((0,Q.string)(),(0,Q.check)(t=>t.split("::").length===3)),typeArguments:(0,Q.array)((0,Q.string)()),arguments:(0,Q.array)(Ji)}),AD=(0,Q.object)({kind:(0,Q.literal)("TransferObjects"),objects:(0,Q.array)(Ji),address:Ji}),ID=(0,Q.object)({kind:(0,Q.literal)("SplitCoins"),coin:Ji,amounts:(0,Q.array)(Ji)}),TD=(0,Q.object)({kind:(0,Q.literal)("MergeCoins"),destination:Ji,sources:(0,Q.array)(Ji)}),xD=(0,Q.object)({kind:(0,Q.literal)("MakeMoveVec"),type:(0,Q.union)([(0,Q.object)({Some:mf}),(0,Q.object)({None:(0,Q.nullable)((0,Q.literal)(!0))})]),objects:(0,Q.array)(Ji)}),PD=(0,Q.object)({kind:(0,Q.literal)("Publish"),modules:(0,Q.array)((0,Q.array)((0,Q.pipe)((0,Q.number)(),(0,Q.integer)()))),dependencies:(0,Q.array)((0,Q.string)())}),CD=(0,Q.object)({kind:(0,Q.literal)("Upgrade"),modules:(0,Q.array)((0,Q.array)((0,Q.pipe)((0,Q.number)(),(0,Q.integer)()))),dependencies:(0,Q.array)((0,Q.string)()),packageId:(0,Q.string)(),ticket:Ji}),jD=[ED,AD,ID,TD,PD,CD,xD],ND=(0,Q.union)([...jD]),DD=(0,Q.object)({version:(0,Q.literal)(1),sender:(0,Q.optional)((0,Q.string)()),expiration:(0,Q.nullish)(SD),gasConfig:kD,inputs:(0,Q.array)(rO),transactions:(0,Q.array)(ND)});function BD(t){let e=t.inputs.map((r,n)=>{if(r.Object)return{kind:"Input",index:n,value:{Object:r.Object.ImmOrOwnedObject?{ImmOrOwned:r.Object.ImmOrOwnedObject}:r.Object.Receiving?{Receiving:{digest:r.Object.Receiving.digest,version:r.Object.Receiving.version,objectId:r.Object.Receiving.objectId}}:{Shared:{mutable:r.Object.SharedObject.mutable,initialSharedVersion:r.Object.SharedObject.initialSharedVersion,objectId:r.Object.SharedObject.objectId}}},type:"object"};if(r.Pure)return{kind:"Input",index:n,value:{Pure:Array.from((0,Fa.fromBase64)(r.Pure.bytes))},type:"pure"};if(r.UnresolvedPure)return{kind:"Input",type:"pure",index:n,value:r.UnresolvedPure.value};if(r.UnresolvedObject)return{kind:"Input",type:"object",index:n,value:r.UnresolvedObject.objectId};throw new Error("Invalid input")});return{version:1,sender:t.sender??void 0,expiration:t.expiration?.$kind==="Epoch"?{Epoch:Number(t.expiration.Epoch)}:t.expiration?{None:!0}:null,gasConfig:{owner:t.gasData.owner??void 0,budget:t.gasData.budget??void 0,price:t.gasData.price??void 0,payment:t.gasData.payment??void 0},inputs:e,transactions:t.commands.map(r=>{if(r.MakeMoveVec)return{kind:"MakeMoveVec",type:r.MakeMoveVec.type===null?{None:!0}:{Some:tO.TypeTagSerializer.parseFromStr(r.MakeMoveVec.type)},objects:r.MakeMoveVec.elements.map(n=>vs(n,e))};if(r.MergeCoins)return{kind:"MergeCoins",destination:vs(r.MergeCoins.destination,e),sources:r.MergeCoins.sources.map(n=>vs(n,e))};if(r.MoveCall)return{kind:"MoveCall",target:`${r.MoveCall.package}::${r.MoveCall.module}::${r.MoveCall.function}`,typeArguments:r.MoveCall.typeArguments,arguments:r.MoveCall.arguments.map(n=>vs(n,e))};if(r.Publish)return{kind:"Publish",modules:r.Publish.modules.map(n=>Array.from((0,Fa.fromBase64)(n))),dependencies:r.Publish.dependencies};if(r.SplitCoins)return{kind:"SplitCoins",coin:vs(r.SplitCoins.coin,e),amounts:r.SplitCoins.amounts.map(n=>vs(n,e))};if(r.TransferObjects)return{kind:"TransferObjects",objects:r.TransferObjects.objects.map(n=>vs(n,e)),address:vs(r.TransferObjects.address,e)};if(r.Upgrade)return{kind:"Upgrade",modules:r.Upgrade.modules.map(n=>Array.from((0,Fa.fromBase64)(n))),dependencies:r.Upgrade.dependencies,packageId:r.Upgrade.package,ticket:vs(r.Upgrade.ticket,e)};throw new Error(`Unknown transaction ${Object.keys(r)}`)})}}function vs(t,e){if(t.$kind==="GasCoin")return{kind:"GasCoin"};if(t.$kind==="Result")return{kind:"Result",index:t.Result};if(t.$kind==="NestedResult")return{kind:"NestedResult",index:t.NestedResult[0],resultIndex:t.NestedResult[1]};if(t.$kind==="Input")return e[t.Input];throw new Error(`Invalid argument ${Object.keys(t)}`)}function RD(t){return(0,Q.parse)(oc.TransactionData,{version:2,sender:t.sender??null,expiration:t.expiration?"Epoch"in t.expiration?{Epoch:t.expiration.Epoch}:{None:!0}:null,gasData:{owner:t.gasConfig.owner??null,budget:t.gasConfig.budget?.toString()??null,price:t.gasConfig.price?.toString()??null,payment:t.gasConfig.payment?.map(e=>({digest:e.digest,objectId:e.objectId,version:e.version.toString()}))??null},inputs:t.inputs.map(e=>{if(e.kind==="Input"){if((0,Q.is)(im,e.value)){let r=(0,Q.parse)(im,e.value);if(r.Object){if(r.Object.ImmOrOwned)return{Object:{ImmOrOwnedObject:{objectId:r.Object.ImmOrOwned.objectId,version:String(r.Object.ImmOrOwned.version),digest:r.Object.ImmOrOwned.digest}}};if(r.Object.Shared)return{Object:{SharedObject:{mutable:r.Object.Shared.mutable??null,initialSharedVersion:r.Object.Shared.initialSharedVersion,objectId:r.Object.Shared.objectId}}};if(r.Object.Receiving)return{Object:{Receiving:{digest:r.Object.Receiving.digest,version:String(r.Object.Receiving.version),objectId:r.Object.Receiving.objectId}}};throw new Error("Invalid object input")}return{Pure:{bytes:(0,Fa.toBase64)(new Uint8Array(r.Pure))}}}return e.type==="object"?{UnresolvedObject:{objectId:e.value}}:{UnresolvedPure:{value:e.value}}}throw new Error("Invalid input")}),commands:t.transactions.map(e=>{switch(e.kind){case"MakeMoveVec":return{MakeMoveVec:{type:"Some"in e.type?tO.TypeTagSerializer.tagToString(e.type.Some):null,elements:e.objects.map(r=>bs(r))}};case"MergeCoins":return{MergeCoins:{destination:bs(e.destination),sources:e.sources.map(r=>bs(r))}};case"MoveCall":{let[r,n,i]=e.target.split("::");return{MoveCall:{package:r,module:n,function:i,typeArguments:e.typeArguments,arguments:e.arguments.map(s=>bs(s))}}}case"Publish":return{Publish:{modules:e.modules.map(r=>(0,Fa.toBase64)(Uint8Array.from(r))),dependencies:e.dependencies}};case"SplitCoins":return{SplitCoins:{coin:bs(e.coin),amounts:e.amounts.map(r=>bs(r))}};case"TransferObjects":return{TransferObjects:{objects:e.objects.map(r=>bs(r)),address:bs(e.address)}};case"Upgrade":return{Upgrade:{modules:e.modules.map(r=>(0,Fa.toBase64)(Uint8Array.from(r))),dependencies:e.dependencies,package:e.packageId,ticket:bs(e.ticket)}}}throw new Error(`Unknown transaction ${Object.keys(e)}`)})})}function bs(t){switch(t.kind){case"GasCoin":return{GasCoin:!0};case"Result":return{Result:t.index};case"NestedResult":return{NestedResult:[t.index,t.resultIndex]};case"Input":return{Input:t.index}}}});var aO=be((GY,oO)=>{"use strict";var am=Object.defineProperty,UD=Object.getOwnPropertyDescriptor,LD=Object.getOwnPropertyNames,$D=Object.prototype.hasOwnProperty,FD=(t,e)=>{for(var r in e)am(t,r,{get:e[r],enumerable:!0})},qD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of LD(e))!$D.call(t,i)&&i!==r&&am(t,i,{get:()=>e[i],enumerable:!(n=UD(e,i))||n.enumerable});return t},VD=t=>qD(am({},"__esModule",{value:!0}),t),sO={};FD(sO,{SerializedTransactionDataV2:()=>ZD});oO.exports=VD(sO);var Me=Wi(),hr=uo();function ac(t){return(0,Me.union)(Object.entries(t).map(([e,r])=>(0,Me.object)({[e]:r})))}var _i=ac({GasCoin:(0,Me.literal)(!0),Input:(0,Me.pipe)((0,Me.number)(),(0,Me.integer)()),Result:(0,Me.pipe)((0,Me.number)(),(0,Me.integer)()),NestedResult:(0,Me.tuple)([(0,Me.pipe)((0,Me.number)(),(0,Me.integer)()),(0,Me.pipe)((0,Me.number)(),(0,Me.integer)())])}),zD=(0,Me.object)({budget:(0,Me.nullable)(hr.JsonU64),price:(0,Me.nullable)(hr.JsonU64),owner:(0,Me.nullable)(hr.SuiAddress),payment:(0,Me.nullable)((0,Me.array)(hr.ObjectRef))}),GD=(0,Me.object)({package:hr.ObjectID,module:(0,Me.string)(),function:(0,Me.string)(),typeArguments:(0,Me.array)((0,Me.string)()),arguments:(0,Me.array)(_i)}),HD=(0,Me.object)({name:(0,Me.string)(),inputs:(0,Me.record)((0,Me.string)(),(0,Me.union)([_i,(0,Me.array)(_i)])),data:(0,Me.record)((0,Me.string)(),(0,Me.unknown)())}),WD=ac({MoveCall:GD,TransferObjects:(0,Me.object)({objects:(0,Me.array)(_i),address:_i}),SplitCoins:(0,Me.object)({coin:_i,amounts:(0,Me.array)(_i)}),MergeCoins:(0,Me.object)({destination:_i,sources:(0,Me.array)(_i)}),Publish:(0,Me.object)({modules:(0,Me.array)(hr.BCSBytes),dependencies:(0,Me.array)(hr.ObjectID)}),MakeMoveVec:(0,Me.object)({type:(0,Me.nullable)((0,Me.string)()),elements:(0,Me.array)(_i)}),Upgrade:(0,Me.object)({modules:(0,Me.array)(hr.BCSBytes),dependencies:(0,Me.array)(hr.ObjectID),package:hr.ObjectID,ticket:_i}),$Intent:HD}),KD=ac({ImmOrOwnedObject:hr.ObjectRef,SharedObject:(0,Me.object)({objectId:hr.ObjectID,initialSharedVersion:hr.JsonU64,mutable:(0,Me.boolean)()}),Receiving:hr.ObjectRef}),XD=ac({Object:KD,Pure:(0,Me.object)({bytes:hr.BCSBytes}),UnresolvedPure:(0,Me.object)({value:(0,Me.unknown)()}),UnresolvedObject:(0,Me.object)({objectId:hr.ObjectID,version:(0,Me.optional)((0,Me.nullable)(hr.JsonU64)),digest:(0,Me.optional)((0,Me.nullable)((0,Me.string)())),initialSharedVersion:(0,Me.optional)((0,Me.nullable)(hr.JsonU64))})}),JD=ac({None:(0,Me.literal)(!0),Epoch:hr.JsonU64}),ZD=(0,Me.object)({version:(0,Me.literal)(2),sender:(0,Me.nullish)(hr.SuiAddress),expiration:(0,Me.nullish)(JD),gasData:zD,inputs:(0,Me.array)(XD),commands:(0,Me.array)(WD),digest:(0,Me.optional)((0,Me.nullable)((0,Me.string)()))})});var cm=be((HY,pO)=>{"use strict";var um=Object.defineProperty,YD=Object.getOwnPropertyDescriptor,QD=Object.getOwnPropertyNames,e9=Object.prototype.hasOwnProperty,lO=t=>{throw TypeError(t)},t9=(t,e)=>{for(var r in e)um(t,r,{get:e[r],enumerable:!0})},r9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of QD(e))!e9.call(t,i)&&i!==r&&um(t,i,{get:()=>e[i],enumerable:!(n=YD(e,i))||n.enumerable});return t},n9=t=>r9(um({},"__esModule",{value:!0}),t),fO=(t,e,r)=>e.has(t)||lO("Cannot "+r),Hr=(t,e,r)=>(fO(t,e,"read from private field"),r?r.call(t):e.get(t)),uO=(t,e,r)=>e.has(t)?lO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),cO=(t,e,r,n)=>(fO(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),dO={};t9(dO,{ClientCache:()=>s9});pO.exports=n9(dO);var Yo,an,i9=class hO{constructor({prefix:e,cache:r}={}){uO(this,Yo),uO(this,an),cO(this,Yo,e??[]),cO(this,an,r??new Map)}read(e,r){let n=[Hr(this,Yo),...e].join(":");if(Hr(this,an).has(n))return Hr(this,an).get(n);let i=r();return Hr(this,an).set(n,i),typeof i=="object"&&i!==null&&"then"in i?Promise.resolve(i).then(s=>(Hr(this,an).set(n,s),s)).catch(s=>{throw Hr(this,an).delete(n),s}):i}readSync(e,r){let n=[Hr(this,Yo),...e].join(":");if(Hr(this,an).has(n))return Hr(this,an).get(n);let i=r();return Hr(this,an).set(n,i),i}clear(e){let r=[...Hr(this,Yo),...e??[]].join(":");if(!r){Hr(this,an).clear();return}for(let n of Hr(this,an).keys())n.startsWith(r)&&Hr(this,an).delete(n)}scope(e){return new hO({prefix:[...Hr(this,Yo),...Array.isArray(e)?e:[e]],cache:Hr(this,an)})}};Yo=new WeakMap;an=new WeakMap;var s9=i9});var fm=be((WY,gO)=>{"use strict";var lm=Object.defineProperty,o9=Object.getOwnPropertyDescriptor,a9=Object.getOwnPropertyNames,u9=Object.prototype.hasOwnProperty,c9=(t,e)=>{for(var r in e)lm(t,r,{get:e[r],enumerable:!0})},l9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a9(e))!u9.call(t,i)&&i!==r&&lm(t,i,{get:()=>e[i],enumerable:!(n=o9(e,i))||n.enumerable});return t},f9=t=>l9(lm({},"__esModule",{value:!0}),t),mO={};c9(mO,{PACKAGE_VERSION:()=>d9,TARGETED_RPC_VERSION:()=>h9});gO.exports=f9(mO);var d9="1.34.0",h9="1.51.0"});var fc=be((KY,SO)=>{"use strict";var gm=Object.defineProperty,p9=Object.getOwnPropertyDescriptor,m9=Object.getOwnPropertyNames,g9=Object.prototype.hasOwnProperty,_O=t=>{throw TypeError(t)},y9=(t,e)=>{for(var r in e)gm(t,r,{get:e[r],enumerable:!0})},_9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of m9(e))!g9.call(t,i)&&i!==r&&gm(t,i,{get:()=>e[i],enumerable:!(n=p9(e,i))||n.enumerable});return t},v9=t=>_9(gm({},"__esModule",{value:!0}),t),ym=(t,e,r)=>e.has(t)||_O("Cannot "+r),br=(t,e,r)=>(ym(t,e,"read from private field"),r?r.call(t):e.get(t)),uc=(t,e,r)=>e.has(t)?_O("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),gf=(t,e,r,n)=>(ym(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_f=(t,e,r)=>(ym(t,e,"access private method"),r),vO={};y9(vO,{MvrClient:()=>pm,extractMvrTypes:()=>yf,findNamesInTransaction:()=>k9,hasMvrName:()=>ws,replaceNames:()=>O9});SO.exports=v9(vO);var vf=to(),_m=Xu(),co=Nr(),b9=fm(),cc,Ms,lc,lo,Zi,dm,hm,bO,wO,vm,w9="/",M9={"Mvr-Source":`@mysten/sui@${b9.PACKAGE_VERSION}`},pm=class{constructor({cache:e,url:r,pageSize:n=50,overrides:i}){uc(this,Zi),uc(this,cc),uc(this,Ms),uc(this,lc),uc(this,lo),gf(this,cc,e),gf(this,Ms,r),gf(this,lc,n),gf(this,lo,{packages:i?.packages,types:i?.types}),S9(br(this,lo))}async resolvePackage({package:e}){return{package:await br(this,Zi,dm).load(e)}}async resolveType({type:e}){let r=[...yf(e)],n=await br(this,Zi,hm).loadMany(r),i={};for(let s=0;s<r.length;s++){let o=n[s];if(o instanceof Error)throw o;i[r[s]]=o}return{type:mm(e,i)}}async resolve({types:e=[],packages:r=[]}){let n=new Set;for(let p of e??[])yf(p,n);let i=[...n],[s,o]=await Promise.all([i.length>0?br(this,Zi,hm).loadMany(i):[],r.length>0?br(this,Zi,dm).loadMany(r):[]]),u={...br(this,lo)?.types};for(let[p,_]of i.entries()){let b=s[p];if(b instanceof Error)throw b;u[_]=b}let c={};for(let p of e??[]){let _=mm(p,u);c[p]={type:_}}let d={};for(let[p,_]of(r??[]).entries()){let b=br(this,lo)?.packages?.[_]??o[p];if(b instanceof Error)throw b;d[_]={package:b}}return{types:c,packages:d}}};cc=new WeakMap;Ms=new WeakMap;lc=new WeakMap;lo=new WeakMap;Zi=new WeakSet;dm=function(){return br(this,cc).readSync(["#mvrPackageDataLoader",br(this,Ms)??""],()=>{let t=new vf.DataLoader(async r=>{if(!br(this,Ms))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await _f(this,Zi,bO).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve package: ${i}`))}),e=br(this,lo)?.packages;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};hm=function(){return br(this,cc).readSync(["#mvrTypeDataLoader",br(this,Ms)??""],()=>{let t=new vf.DataLoader(async r=>{if(!br(this,Ms))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await _f(this,Zi,wO).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve type: ${i}`))}),e=br(this,lo)?.types;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};bO=async function(t){if(t.length===0)return{};let e=(0,vf.chunk)(t,br(this,lc)),r={};return await Promise.all(e.map(async n=>{let i=await _f(this,Zi,vm).call(this,"/v1/resolution/bulk",{names:n});if(i?.resolution)for(let s of Object.keys(i?.resolution)){let o=i.resolution[s]?.package_id;o&&(r[s]=o)}})),r};wO=async function(t){if(t.length===0)return{};let e=(0,vf.chunk)(t,br(this,lc)),r={};return await Promise.all(e.map(async n=>{let i=await _f(this,Zi,vm).call(this,"/v1/struct-definition/bulk",{types:n});if(i?.resolution)for(let s of Object.keys(i?.resolution)){let o=i.resolution[s]?.type_tag;o&&(r[s]=o)}})),r};vm=async function(t,e){if(!br(this,Ms))throw new Error("MVR Api URL is not set for the current client");let r=await fetch(`${br(this,Ms)}${t}`,{method:"POST",headers:{"Content-Type":"application/json",...M9},body:JSON.stringify(e)});if(!r.ok){let n=await r.json().catch(()=>({}));throw new Error(`Failed to resolve types: ${n?.message}`)}return r.json()};function S9(t){if(t?.packages)for(let[e,r]of Object.entries(t.packages)){if(!(0,_m.isValidNamedPackage)(e))throw new Error(`Invalid package name: ${e}`);if(!(0,co.isValidSuiAddress)((0,co.normalizeSuiAddress)(r)))throw new Error(`Invalid package ID: ${r}`)}if(t?.types)for(let[e,r]of Object.entries(t.types)){if((0,co.parseStructTag)(e).typeParams.length>0)throw new Error("Type overrides must be first-level only. If you want to supply generic types, just pass each type individually.");let n=(0,co.parseStructTag)(r);if(!(0,co.isValidSuiAddress)(n.address))throw new Error(`Invalid type: ${r}`)}}function yf(t,e=new Set){if(typeof t=="string"&&!ws(t))return e;let r=MO(t)?t:(0,co.parseStructTag)(t);ws(r.address)&&e.add(`${r.address}::${r.module}::${r.name}`);for(let n of r.typeParams)yf(n,e);return e}function mm(t,e){let r=MO(t)?t:(0,co.parseStructTag)(t),n=`${r.address}::${r.module}::${r.name}`,i=e[n];return(0,co.normalizeStructTag)({...r,address:i?i.split("::")[0]:r.address,typeParams:r.typeParams.map(s=>mm(s,e))})}function ws(t){return t.includes(w9)||t.includes("@")||t.includes(".sui")}function MO(t){return typeof t=="object"&&"address"in t&&"module"in t&&"name"in t&&"typeParams"in t}function k9(t){let e=new Set,r=new Set;for(let n of t.commands)switch(n.$kind){case"MakeMoveVec":n.MakeMoveVec.type&&yO([n.MakeMoveVec.type]).forEach(o=>{r.add(o)});break;case"MoveCall":let i=n.MoveCall,s=i.package.split("::")[0];if(ws(s)){if(!(0,_m.isValidNamedPackage)(s))throw new Error(`Invalid package name: ${s}`);e.add(s)}yO(i.typeArguments??[]).forEach(o=>{r.add(o)});break;default:break}return{packages:[...e],types:[...r]}}function O9(t,e){for(let r of t.commands){if(r.MakeMoveVec?.type){if(!ws(r.MakeMoveVec.type))continue;if(!e.types[r.MakeMoveVec.type])throw new Error(`No resolution found for type: ${r.MakeMoveVec.type}`);r.MakeMoveVec.type=e.types[r.MakeMoveVec.type].type}let n=r.MoveCall;if(!n)continue;let i=n.package.split("::"),s=i[0];if(ws(s)&&!e.packages[s])throw new Error(`No address found for package: ${s}`);ws(s)&&(i[0]=e.packages[s].package,n.package=i.join("::"));let o=n.typeArguments;if(o){for(let u=0;u<o.length;u++)if(ws(o[u])){if(!e.types[o[u]])throw new Error(`No resolution found for type: ${o[u]}`);o[u]=e.types[o[u]].type}n.typeArguments=o}}}function yO(t){let e=new Set;for(let r of t)if(ws(r)){if(!(0,_m.isValidNamedType)(r))throw new Error(`Invalid type with names: ${r}`);e.add(r)}return e}});var Mm=be((XY,AO)=>{"use strict";var wm=Object.defineProperty,E9=Object.getOwnPropertyDescriptor,A9=Object.getOwnPropertyNames,I9=Object.prototype.hasOwnProperty,T9=(t,e)=>{for(var r in e)wm(t,r,{get:e[r],enumerable:!0})},x9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of A9(e))!I9.call(t,i)&&i!==r&&wm(t,i,{get:()=>e[i],enumerable:!(n=E9(e,i))||n.enumerable});return t},P9=t=>x9(wm({},"__esModule",{value:!0}),t),OO={};T9(OO,{getClient:()=>EO,namedPackagesPlugin:()=>N9});AO.exports=P9(OO);var C9=cm(),j9=fc(),kO=fc(),bm=new WeakMap,N9=t=>{let e;if(t){let r=t.overrides??{packages:{},types:{}};bm.has(r)||bm.set(r,new C9.ClientCache),e=new j9.MvrClient({cache:bm.get(r),url:t.url,pageSize:t.pageSize,overrides:r})}return async(r,n,i)=>{let s=(0,kO.findNamesInTransaction)(r);if(s.types.length===0&&s.packages.length===0)return i();let o=await(e||EO(n).core.mvr).resolve({types:s.types,packages:s.packages});(0,kO.replaceNames)(r,o),await i()}};function EO(t){if(!t.client)throw new Error("No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.");return t.client}});var Em=be((JY,TO)=>{"use strict";var Om=Object.defineProperty,D9=Object.getOwnPropertyDescriptor,B9=Object.getOwnPropertyNames,R9=Object.prototype.hasOwnProperty,U9=(t,e)=>{for(var r in e)Om(t,r,{get:e[r],enumerable:!0})},L9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of B9(e))!R9.call(t,i)&&i!==r&&Om(t,i,{get:()=>e[i],enumerable:!(n=D9(e,i))||n.enumerable});return t},$9=t=>L9(Om({},"__esModule",{value:!0}),t),IO={};U9(IO,{suiClientResolveTransactionPlugin:()=>W9});TO.exports=$9(IO);var F9=Wi(),km=af(),q9=uo(),bf=Ua(),Sm=D0(),V9=to(),z9=50,G9=1000n,H9=5e10;function W9(t){return async function(r,n,i){return await Y9(r,t),await Z9(r,t),n.onlyTransactionKind||(await K9(r,t),await X9(r,t),await J9(r,t)),await i()}}async function K9(t,e){t.gasConfig.price||(t.gasConfig.price=String(await e.getReferenceGasPrice()))}async function X9(t,e){if(t.gasConfig.budget)return;let r=await e.dryRunTransactionBlock({transactionBlock:t.build({overrides:{gasData:{budget:String(H9),payment:[]}}})});if(r.effects.status.status!=="success")throw new Error(`Dry run failed, could not automatically determine a budget: ${r.effects.status.error}`,{cause:r});let n=G9*BigInt(t.gasConfig.price||1n),i=BigInt(r.effects.gasUsed.computationCost)+n,s=i+BigInt(r.effects.gasUsed.storageCost)-BigInt(r.effects.gasUsed.storageRebate);t.gasConfig.budget=String(s>i?s:i)}async function J9(t,e){if(!t.gasConfig.payment){let n=(await e.getCoins({owner:t.gasConfig.owner||t.sender,coinType:km.SUI_TYPE_ARG})).data.filter(i=>!t.inputs.find(o=>o.Object?.ImmOrOwnedObject?i.coinObjectId===o.Object.ImmOrOwnedObject.objectId:!1)).map(i=>({objectId:i.coinObjectId,digest:i.digest,version:i.version}));if(!n.length)throw new Error("No valid gas coins found for the transaction.");t.gasConfig.payment=n.map(i=>(0,F9.parse)(q9.ObjectRef,i))}}async function Z9(t,e){let r=t.inputs.filter(p=>p.UnresolvedObject&&!(p.UnresolvedObject.version||p.UnresolvedObject?.initialSharedVersion)),n=[...new Set(r.map(p=>(0,km.normalizeSuiObjectId)(p.UnresolvedObject.objectId)))],i=n.length?(0,V9.chunk)(n,z9):[],s=(await Promise.all(i.map(p=>e.multiGetObjects({ids:p,options:{showOwner:!0}})))).flat(),o=new Map(n.map((p,_)=>[p,s[_]])),u=Array.from(o).filter(([p,_])=>_.error).map(([p,_])=>JSON.stringify(_.error));if(u.length)throw new Error(`The following input objects are invalid: ${u.join(", ")}`);let c=s.map(p=>{if(p.error||!p.data)throw new Error(`Failed to fetch object: ${p.error}`);let _=p.data.owner,b=_&&typeof _=="object"&&"Shared"in _?_.Shared.initial_shared_version:null;return{objectId:p.data.objectId,digest:p.data.digest,version:p.data.version,initialSharedVersion:b}}),d=new Map(n.map((p,_)=>[p,c[_]]));for(let[p,_]of t.inputs.entries()){if(!_.UnresolvedObject)continue;let b,O=(0,km.normalizeSuiAddress)(_.UnresolvedObject.objectId),T=d.get(O);_.UnresolvedObject.initialSharedVersion??T?.initialSharedVersion?b=bf.Inputs.SharedObjectRef({objectId:O,initialSharedVersion:_.UnresolvedObject.initialSharedVersion||T?.initialSharedVersion,mutable:Q9(t,p)}):eB(t,p)&&(b=bf.Inputs.ReceivingRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})),t.inputs[t.inputs.indexOf(_)]=b??bf.Inputs.ObjectRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})}}async function Y9(t,e){let{inputs:r,commands:n}=t,i=[],s=new Set;n.forEach(u=>{if(u.MoveCall){if(u.MoveCall._argumentTypes)return;if(u.MoveCall.arguments.map(p=>p.$kind==="Input"?t.inputs[p.Input]:null).some(p=>p?.UnresolvedPure||p?.UnresolvedObject)){let p=`${u.MoveCall.package}::${u.MoveCall.module}::${u.MoveCall.function}`;s.add(p),i.push(u.MoveCall)}}});let o=new Map;s.size>0&&await Promise.all([...s].map(async u=>{let[c,d,p]=u.split("::"),_=await e.getNormalizedMoveFunction({package:c,module:d,function:p});o.set(u,_.parameters.map(b=>(0,Sm.normalizedTypeToMoveTypeSignature)(b)))})),i.length&&await Promise.all(i.map(async u=>{let c=o.get(`${u.package}::${u.module}::${u.function}`);if(!c)return;let p=c.length>0&&(0,Sm.isTxContext)(c.at(-1))?c.slice(0,c.length-1):c;u._argumentTypes=p})),n.forEach(u=>{if(!u.MoveCall)return;let c=u.MoveCall,d=`${c.package}::${c.module}::${c.function}`,p=c._argumentTypes;if(p){if(p.length!==u.MoveCall.arguments.length)throw new Error(`Incorrect number of arguments for ${d}`);p.forEach((_,b)=>{let O=c.arguments[b];if(O.$kind!=="Input")return;let T=r[O.Input];if(!T.UnresolvedPure&&!T.UnresolvedObject)return;let x=T.UnresolvedPure?.value??T.UnresolvedObject?.objectId,F=(0,Sm.getPureBcsSchema)(_.body);if(F){O.type="pure",r[r.indexOf(T)]=bf.Inputs.Pure(F.serialize(x));return}if(typeof x!="string")throw new Error(`Expect the argument to be an object id string, got ${JSON.stringify(x,null,2)}`);O.type="object";let R=T.UnresolvedPure?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:x}}:T;r[O.Input]=R})}})}function Q9(t,e){let r=!1;return t.getInputUses(e,(n,i)=>{if(i.MoveCall&&i.MoveCall._argumentTypes){let s=i.MoveCall.arguments.indexOf(n);r=i.MoveCall._argumentTypes[s].ref!=="&"||r}(i.$kind==="MakeMoveVec"||i.$kind==="MergeCoins"||i.$kind==="SplitCoins")&&(r=!0)}),r}function eB(t,e){let r=!1;return t.getInputUses(e,(n,i)=>{if(i.MoveCall&&i.MoveCall._argumentTypes){let s=i.MoveCall.arguments.indexOf(n);r=tB(i.MoveCall._argumentTypes[s])||r}}),r}function tB(t){return typeof t.body!="object"||!("datatype"in t.body)?!1:t.body.datatype.package==="0x2"&&t.body.datatype.module==="transfer"&&t.body.datatype.type==="Receiving"}});var Im=be((ZY,BO)=>{"use strict";var Am=Object.defineProperty,rB=Object.getOwnPropertyDescriptor,nB=Object.getOwnPropertyNames,iB=Object.prototype.hasOwnProperty,sB=(t,e)=>{for(var r in e)Am(t,r,{get:e[r],enumerable:!0})},oB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nB(e))!iB.call(t,i)&&i!==r&&Am(t,i,{get:()=>e[i],enumerable:!(n=rB(e,i))||n.enumerable});return t},aB=t=>oB(Am({},"__esModule",{value:!0}),t),jO={};sB(jO,{getClient:()=>DO,needsTransactionResolution:()=>NO,resolveTransactionPlugin:()=>fB});BO.exports=aB(jO);var uB=Ua(),xO=Rn(),cB=Mm(),lB=Em();function NO(t,e){return!!(t.inputs.some(r=>r.UnresolvedObject||r.UnresolvedPure)||!e.onlyTransactionKind&&(!t.gasConfig.price||!t.gasConfig.budget||!t.gasConfig.payment))}async function fB(t,e,r){if(dB(t),!NO(t,e))return await PO(t),r();let n=DO(e),i=n.core?.resolveTransactionPlugin()??(0,lB.suiClientResolveTransactionPlugin)(n);return(0,cB.namedPackagesPlugin)()(t,e,async()=>{await i(t,e,async()=>{await PO(t),await r()})})}function PO(t){t.inputs.forEach((e,r)=>{if(e.$kind!=="Object"&&e.$kind!=="Pure")throw new Error(`Input at index ${r} has not been resolved. Expected a Pure or Object input, but found ${JSON.stringify(e)}`)})}function DO(t){if(!t.client)throw new Error("No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.");return t.client}function dB(t){for(let e of t.commands)switch(e.$kind){case"SplitCoins":e.SplitCoins.amounts.forEach(r=>{CO(r,xO.bcs.U64,t)});break;case"TransferObjects":CO(e.TransferObjects.address,xO.bcs.Address,t);break}}function CO(t,e,r){if(t.$kind!=="Input")return;let n=r.inputs[t.Input];n.$kind==="UnresolvedPure"&&(r.inputs[t.Input]=uB.Inputs.Pure(e.serialize(n.UnresolvedPure.value)))}});var xm=be((YY,UO)=>{"use strict";var Tm=Object.defineProperty,hB=Object.getOwnPropertyDescriptor,pB=Object.getOwnPropertyNames,mB=Object.prototype.hasOwnProperty,gB=(t,e)=>{for(var r in e)Tm(t,r,{get:e[r],enumerable:!0})},yB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pB(e))!mB.call(t,i)&&i!==r&&Tm(t,i,{get:()=>e[i],enumerable:!(n=hB(e,i))||n.enumerable});return t},_B=t=>yB(Tm({},"__esModule",{value:!0}),t),RO={};gB(RO,{createObjectMethods:()=>vB});UO.exports=_B(RO);function vB(t){function e(r){return t(r)}return e.system=()=>e("0x5"),e.clock=()=>e("0x6"),e.random=()=>e("0x8"),e.denyList=()=>e("0x403"),e.option=({type:r,value:n})=>i=>i.moveCall({typeArguments:[r],target:`0x1::option::${n===null?"none":"some"}`,arguments:n===null?[]:[i.object(n)]}),e}});var jm=be((QY,$O)=>{"use strict";var Cm=Object.defineProperty,bB=Object.getOwnPropertyDescriptor,wB=Object.getOwnPropertyNames,MB=Object.prototype.hasOwnProperty,SB=(t,e)=>{for(var r in e)Cm(t,r,{get:e[r],enumerable:!0})},kB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of wB(e))!MB.call(t,i)&&i!==r&&Cm(t,i,{get:()=>e[i],enumerable:!(n=bB(e,i))||n.enumerable});return t},OB=t=>kB(Cm({},"__esModule",{value:!0}),t),LO={};SB(LO,{createPure:()=>AB});$O.exports=OB(LO);var EB=dr(),vi=Rn(),Pm=y0();function AB(t){function e(r,n){if(typeof r=="string")return t((0,Pm.pureBcsSchemaFromTypeName)(r).serialize(n));if(r instanceof Uint8Array||(0,EB.isSerializedBcs)(r))return t(r);throw new Error("tx.pure must be called either a bcs type name, or a serialized bcs value")}return e.u8=r=>t(vi.bcs.U8.serialize(r)),e.u16=r=>t(vi.bcs.U16.serialize(r)),e.u32=r=>t(vi.bcs.U32.serialize(r)),e.u64=r=>t(vi.bcs.U64.serialize(r)),e.u128=r=>t(vi.bcs.U128.serialize(r)),e.u256=r=>t(vi.bcs.U256.serialize(r)),e.bool=r=>t(vi.bcs.Bool.serialize(r)),e.string=r=>t(vi.bcs.String.serialize(r)),e.address=r=>t(vi.bcs.Address.serialize(r)),e.id=e.address,e.vector=(r,n)=>t(vi.bcs.vector((0,Pm.pureBcsSchemaFromTypeName)(r)).serialize(n)),e.option=(r,n)=>t(vi.bcs.option((0,Pm.pureBcsSchemaFromTypeName)(r)).serialize(n)),e}});var VO=be((eQ,qO)=>{"use strict";var Nm=Object.defineProperty,IB=Object.getOwnPropertyDescriptor,TB=Object.getOwnPropertyNames,xB=Object.prototype.hasOwnProperty,PB=(t,e)=>{for(var r in e)Nm(t,r,{get:e[r],enumerable:!0})},CB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of TB(e))!xB.call(t,i)&&i!==r&&Nm(t,i,{get:()=>e[i],enumerable:!(n=IB(e,i))||n.enumerable});return t},jB=t=>CB(Nm({},"__esModule",{value:!0}),t),FO={};PB(FO,{hashTypedData:()=>DB});qO.exports=jB(FO);var NB=I0();function DB(t,e){let r=Array.from(`${t}::`).map(i=>i.charCodeAt(0)),n=new Uint8Array(r.length+e.length);return n.set(r),n.set(e,r.length),(0,NB.blake2b)(n,{dkLen:32})}});var qa=be((tQ,HO)=>{"use strict";var Um=Object.defineProperty,BB=Object.getOwnPropertyDescriptor,RB=Object.getOwnPropertyNames,UB=Object.prototype.hasOwnProperty,LB=(t,e)=>{for(var r in e)Um(t,r,{get:e[r],enumerable:!0})},$B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of RB(e))!UB.call(t,i)&&i!==r&&Um(t,i,{get:()=>e[i],enumerable:!(n=BB(e,i))||n.enumerable});return t},FB=t=>$B(Um({},"__esModule",{value:!0}),t),GO={};LB(GO,{TransactionDataBuilder:()=>Rm});HO.exports=FB(GO);var qB=dr(),Dm=Wi(),wf=Rn(),VB=Nr(),Bm=uo(),zB=om(),GB=VO();function zO(t){return(0,VB.normalizeSuiAddress)(t).replace("0x","")}var Rm=class t{constructor(e){this.version=2,this.sender=e?.sender??null,this.expiration=e?.expiration??null,this.inputs=e?.inputs??[],this.commands=e?.commands??[],this.gasData=e?.gasData??{budget:null,price:null,owner:null,payment:null}}static fromKindBytes(e){let n=wf.bcs.TransactionKind.parse(e).ProgrammableTransaction;if(!n)throw new Error("Unable to deserialize from bytes.");return t.restore({version:2,sender:null,expiration:null,gasData:{budget:null,owner:null,payment:null,price:null},inputs:n.inputs,commands:n.commands})}static fromBytes(e){let n=wf.bcs.TransactionData.parse(e)?.V1,i=n.kind.ProgrammableTransaction;if(!n||!i)throw new Error("Unable to deserialize from bytes.");return t.restore({version:2,sender:n.sender,expiration:n.expiration,gasData:n.gasData,inputs:i.inputs,commands:i.commands})}static restore(e){return e.version===2?new t((0,Dm.parse)(Bm.TransactionData,e)):new t((0,Dm.parse)(Bm.TransactionData,(0,zB.transactionDataFromV1)(e)))}static getDigestFromBytes(e){let r=(0,GB.hashTypedData)("TransactionData",e);return(0,qB.toBase58)(r)}get gasConfig(){return this.gasData}set gasConfig(e){this.gasData=e}build({maxSizeBytes:e=1/0,overrides:r,onlyTransactionKind:n}={}){let i=this.inputs,s=this.commands,o={ProgrammableTransaction:{inputs:i,commands:s}};if(n)return wf.bcs.TransactionKind.serialize(o,{maxSize:e}).toBytes();let u=r?.expiration??this.expiration,c=r?.sender??this.sender,d={...this.gasData,...r?.gasConfig,...r?.gasData};if(!c)throw new Error("Missing transaction sender");if(!d.budget)throw new Error("Missing gas budget");if(!d.payment)throw new Error("Missing gas payment");if(!d.price)throw new Error("Missing gas price");let p={sender:zO(c),expiration:u||{None:!0},gasData:{payment:d.payment,owner:zO(this.gasData.owner??c),price:BigInt(d.price),budget:BigInt(d.budget)},kind:{ProgrammableTransaction:{inputs:i,commands:s}}};return wf.bcs.TransactionData.serialize({V1:p},{maxSize:e}).toBytes()}addInput(e,r){let n=this.inputs.length;return this.inputs.push(r),{Input:n,type:e,$kind:"Input"}}getInputUses(e,r){this.mapArguments((n,i)=>(n.$kind==="Input"&&n.Input===e&&r(n,i),n))}mapCommandArguments(e,r){let n=this.commands[e];switch(n.$kind){case"MoveCall":n.MoveCall.arguments=n.MoveCall.arguments.map(s=>r(s,n,e));break;case"TransferObjects":n.TransferObjects.objects=n.TransferObjects.objects.map(s=>r(s,n,e)),n.TransferObjects.address=r(n.TransferObjects.address,n,e);break;case"SplitCoins":n.SplitCoins.coin=r(n.SplitCoins.coin,n,e),n.SplitCoins.amounts=n.SplitCoins.amounts.map(s=>r(s,n,e));break;case"MergeCoins":n.MergeCoins.destination=r(n.MergeCoins.destination,n,e),n.MergeCoins.sources=n.MergeCoins.sources.map(s=>r(s,n,e));break;case"MakeMoveVec":n.MakeMoveVec.elements=n.MakeMoveVec.elements.map(s=>r(s,n,e));break;case"Upgrade":n.Upgrade.ticket=r(n.Upgrade.ticket,n,e);break;case"$Intent":let i=n.$Intent.inputs;n.$Intent.inputs={};for(let[s,o]of Object.entries(i))n.$Intent.inputs[s]=Array.isArray(o)?o.map(u=>r(u,n,e)):r(o,n,e);break;case"Publish":break;default:throw new Error(`Unexpected transaction kind: ${n.$kind}`)}}mapArguments(e){for(let r of this.commands.keys())this.mapCommandArguments(r,e)}replaceCommand(e,r,n=e){if(!Array.isArray(r)){this.commands[e]=r;return}let i=r.length-1;this.commands.splice(e,1,...r),i!==0&&this.mapArguments((s,o,u)=>{if(u<e+r.length)return s;switch(s.$kind){case"Result":s.Result===e&&(s.Result=n),s.Result>e&&(s.Result+=i);break;case"NestedResult":s.NestedResult[0]===e&&(s.NestedResult[0]=n),s.NestedResult[0]>e&&(s.NestedResult[0]+=i);break}return s})}getDigest(){let e=this.build({onlyTransactionKind:!1});return t.getDigestFromBytes(e)}snapshot(){return(0,Dm.parse)(Bm.TransactionData,this)}shallowClone(){return new t({version:this.version,sender:this.sender,expiration:this.expiration,gasData:{...this.gasData},inputs:[...this.inputs],commands:[...this.commands]})}}});var $m=be((rQ,JO)=>{"use strict";var Lm=Object.defineProperty,HB=Object.getOwnPropertyDescriptor,WB=Object.getOwnPropertyNames,KB=Object.prototype.hasOwnProperty,XB=(t,e)=>{for(var r in e)Lm(t,r,{get:e[r],enumerable:!0})},JB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of WB(e))!KB.call(t,i)&&i!==r&&Lm(t,i,{get:()=>e[i],enumerable:!(n=HB(e,i))||n.enumerable});return t},ZB=t=>JB(Lm({},"__esModule",{value:!0}),t),WO={};XB(WO,{extractMutableReference:()=>KO,extractReference:()=>XO,extractStructTag:()=>eR,getIdFromCallArg:()=>tR,isArgument:()=>rR});JO.exports=ZB(WO);var YB=Wi(),dc=Nr(),QB=uo();function KO(t){return typeof t=="object"&&"MutableReference"in t?t.MutableReference:void 0}function XO(t){return typeof t=="object"&&"Reference"in t?t.Reference:void 0}function eR(t){if(typeof t=="object"&&"Struct"in t)return t;let e=XO(t),r=KO(t);if(typeof e=="object"&&"Struct"in e)return e;if(typeof r=="object"&&"Struct"in r)return r}function tR(t){if(typeof t=="string")return(0,dc.normalizeSuiAddress)(t);if(t.Object)return t.Object.ImmOrOwnedObject?(0,dc.normalizeSuiAddress)(t.Object.ImmOrOwnedObject.objectId):t.Object.Receiving?(0,dc.normalizeSuiAddress)(t.Object.Receiving.objectId):(0,dc.normalizeSuiAddress)(t.Object.SharedObject.objectId);if(t.UnresolvedObject)return(0,dc.normalizeSuiAddress)(t.UnresolvedObject.objectId)}function rR(t){return(0,YB.is)(QB.Argument,t)}});var na=be((nQ,cE)=>{"use strict";var Gm=Object.defineProperty,nR=Object.getOwnPropertyDescriptor,iR=Object.getOwnPropertyNames,sR=Object.prototype.hasOwnProperty,eE=t=>{throw TypeError(t)},oR=(t,e)=>{for(var r in e)Gm(t,r,{get:e[r],enumerable:!0})},aR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of iR(e))!sR.call(t,i)&&i!==r&&Gm(t,i,{get:()=>e[i],enumerable:!(n=nR(e,i))||n.enumerable});return t},uR=t=>aR(Gm({},"__esModule",{value:!0}),t),Hm=(t,e,r)=>e.has(t)||eE("Cannot "+r),ye=(t,e,r)=>(Hm(t,e,"read from private field"),r?r.call(t):e.get(t)),Yi=(t,e,r)=>e.has(t)?eE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Jt=(t,e,r,n)=>(Hm(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),wr=(t,e,r)=>(Hm(t,e,"access private method"),r),tE={};oR(tE,{Transaction:()=>hR,isTransaction:()=>aE});cE.exports=uR(tE);var Sf=dr(),fo=Wi(),cR=Nr(),Qo=hf(),ea=uo(),ZO=om(),lR=aO(),Mf=Ua(),rE=Im(),fR=xm(),dR=jm(),hc=qa(),YO=$m(),ta,ra,Ss,Qi,Ln,$n,bi,ho,Ke,cr,nE,kf,Of,Ef,Af,Vm,Wm,iE,sE;function Fm(t,e=1/0){let r={$kind:"Result",get Result(){return typeof t=="function"?t():t}},n=[],i=s=>n[s]??(n[s]={$kind:"NestedResult",get NestedResult(){return[typeof t=="function"?t():t,s]}});return new Proxy(r,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(s,o){if(o in s)return Reflect.get(s,o);if(o===Symbol.iterator)return function*(){let c=0;for(;c<e;)yield i(c),c++};if(typeof o=="symbol")return;let u=parseInt(o,10);if(!(Number.isNaN(u)||u<0))return i(u)}})}var oE=Symbol.for("@mysten/transaction");function aE(t){return!!t&&typeof t=="object"&&t[oE]===!0}var QO={buildPlugins:new Map,serializationPlugins:new Map},qm=Symbol.for("@mysten/transaction/registry");function pc(){try{let t=globalThis;return t[qm]||(t[qm]=QO),t[qm]}catch{return QO}}var uE=class zm{constructor(){Yi(this,cr),Yi(this,ta),Yi(this,ra),Yi(this,Ss,new Map),Yi(this,Qi,[]),Yi(this,Ln,[]),Yi(this,$n,new Set),Yi(this,bi,new Set),Yi(this,ho,new Map),Yi(this,Ke),this.object=(0,fR.createObjectMethods)(r=>{if(typeof r=="function")return this.object(this.add(r));if(typeof r=="object"&&(0,fo.is)(ea.Argument,r))return r;let n=(0,YO.getIdFromCallArg)(r),i=ye(this,Ke).inputs.find(s=>n===(0,YO.getIdFromCallArg)(s));return i?.Object?.SharedObject&&typeof r=="object"&&r.Object?.SharedObject&&(i.Object.SharedObject.mutable=i.Object.SharedObject.mutable||r.Object.SharedObject.mutable),i?{$kind:"Input",Input:ye(this,Ke).inputs.indexOf(i),type:"object"}:wr(this,cr,Of).call(this,"object",typeof r=="string"?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:(0,cR.normalizeSuiAddress)(r)}}:r)});let e=pc();Jt(this,Ke,new hc.TransactionDataBuilder),Jt(this,ra,[...e.buildPlugins.values()]),Jt(this,ta,[...e.serializationPlugins.values()])}static fromKind(e){let r=new zm;return Jt(r,Ke,hc.TransactionDataBuilder.fromKindBytes(typeof e=="string"?(0,Sf.fromBase64)(e):e)),Jt(r,Qi,ye(r,Ke).inputs.slice()),Jt(r,Ln,ye(r,Ke).commands.slice()),Jt(r,$n,new Set(ye(r,Ln).map((n,i)=>i))),r}static from(e){let r=new zm;return aE(e)?Jt(r,Ke,new hc.TransactionDataBuilder(e.getData())):typeof e!="string"||!e.startsWith("{")?Jt(r,Ke,hc.TransactionDataBuilder.fromBytes(typeof e=="string"?(0,Sf.fromBase64)(e):e)):Jt(r,Ke,hc.TransactionDataBuilder.restore(JSON.parse(e))),Jt(r,Qi,ye(r,Ke).inputs.slice()),Jt(r,Ln,ye(r,Ke).commands.slice()),Jt(r,$n,new Set(ye(r,Ln).map((n,i)=>i))),r}static registerGlobalSerializationPlugin(e,r){pc().serializationPlugins.set(e,r??e)}static unregisterGlobalSerializationPlugin(e){pc().serializationPlugins.delete(e)}static registerGlobalBuildPlugin(e,r){pc().buildPlugins.set(e,r??e)}static unregisterGlobalBuildPlugin(e){pc().buildPlugins.delete(e)}addSerializationPlugin(e){ye(this,ta).push(e)}addBuildPlugin(e){ye(this,ra).push(e)}addIntentResolver(e,r){if(ye(this,Ss).has(e)&&ye(this,Ss).get(e)!==r)throw new Error(`Intent resolver for ${e} already exists`);ye(this,Ss).set(e,r)}setSender(e){ye(this,Ke).sender=e}setSenderIfNotSet(e){ye(this,Ke).sender||(ye(this,Ke).sender=e)}setExpiration(e){ye(this,Ke).expiration=e?(0,fo.parse)(ea.TransactionExpiration,e):null}setGasPrice(e){ye(this,Ke).gasConfig.price=String(e)}setGasBudget(e){ye(this,Ke).gasConfig.budget=String(e)}setGasBudgetIfNotSet(e){ye(this,Ke).gasData.budget==null&&(ye(this,Ke).gasConfig.budget=String(e))}setGasOwner(e){ye(this,Ke).gasConfig.owner=e}setGasPayment(e){ye(this,Ke).gasConfig.payment=e.map(r=>(0,fo.parse)(ea.ObjectRef,r))}get blockData(){return(0,ZO.serializeV1TransactionData)(ye(this,Ke).snapshot())}getData(){return ye(this,Ke).snapshot()}get[oE](){return!0}get pure(){return Object.defineProperty(this,"pure",{enumerable:!1,value:(0,dR.createPure)(e=>(0,Sf.isSerializedBcs)(e)?wr(this,cr,Of).call(this,"pure",{$kind:"Pure",Pure:{bytes:e.toBase64()}}):wr(this,cr,Of).call(this,"pure",(0,fo.is)(ea.NormalizedCallArg,e)?(0,fo.parse)(ea.NormalizedCallArg,e):e instanceof Uint8Array?Mf.Inputs.Pure(e):{$kind:"UnresolvedPure",UnresolvedPure:{value:e}}))}),this.pure}get gas(){return{$kind:"GasCoin",GasCoin:!0}}objectRef(...e){return this.object(Mf.Inputs.ObjectRef(...e))}receivingRef(...e){return this.object(Mf.Inputs.ReceivingRef(...e))}sharedObjectRef(...e){return this.object(Mf.Inputs.SharedObjectRef(...e))}add(e){if(typeof e=="function"){if(ye(this,ho).has(e))return ye(this,ho).get(e);let r=wr(this,cr,nE).call(this),n=e(r);if(!(n&&typeof n=="object"&&"then"in n))return Jt(this,$n,ye(r,$n)),ye(this,ho).set(e,n),n;let i=wr(this,cr,kf).call(this,{$kind:"$Intent",$Intent:{name:"AsyncTransactionThunk",inputs:{},data:{resultIndex:ye(this,Ke).commands.length,result:null}}});ye(this,bi).add(Promise.resolve(n).then(o=>{i.$Intent.data.result=o}));let s=Fm(()=>i.$Intent.data.resultIndex);return ye(this,ho).set(e,s),s}else wr(this,cr,kf).call(this,e);return Fm(ye(this,Ke).commands.length-1)}splitCoins(e,r){let n=Qo.Commands.SplitCoins(typeof e=="string"?this.object(e):wr(this,cr,Af).call(this,e),r.map(i=>typeof i=="number"||typeof i=="bigint"||typeof i=="string"?this.pure.u64(i):wr(this,cr,Ef).call(this,i)));return wr(this,cr,kf).call(this,n),Fm(ye(this,Ke).commands.length-1,r.length)}mergeCoins(e,r){return this.add(Qo.Commands.MergeCoins(this.object(e),r.map(n=>this.object(n))))}publish({modules:e,dependencies:r}){return this.add(Qo.Commands.Publish({modules:e,dependencies:r}))}upgrade({modules:e,dependencies:r,package:n,ticket:i}){return this.add(Qo.Commands.Upgrade({modules:e,dependencies:r,package:n,ticket:this.object(i)}))}moveCall({arguments:e,...r}){return this.add(Qo.Commands.MoveCall({...r,arguments:e?.map(n=>wr(this,cr,Ef).call(this,n))}))}transferObjects(e,r){return this.add(Qo.Commands.TransferObjects(e.map(n=>this.object(n)),typeof r=="string"?this.pure.address(r):wr(this,cr,Ef).call(this,r)))}makeMoveVec({type:e,elements:r}){return this.add(Qo.Commands.MakeMoveVec({type:e,elements:r.map(n=>this.object(n))}))}serialize(){return JSON.stringify((0,ZO.serializeV1TransactionData)(ye(this,Ke).snapshot()))}async toJSON(e={}){await this.prepareForSerialization(e);let r=this.isFullyResolved();return JSON.stringify((0,fo.parse)(lR.SerializedTransactionDataV2,r?{...ye(this,Ke).snapshot(),digest:ye(this,Ke).getDigest()}:ye(this,Ke).snapshot()),(n,i)=>typeof i=="bigint"?i.toString():i,2)}async sign(e){let{signer:r,...n}=e,i=await this.build(n);return r.signTransaction(i)}isFullyResolved(){return!(!ye(this,Ke).sender||ye(this,bi).size>0||ye(this,Ke).commands.some(e=>e.$Intent)||(0,rE.needsTransactionResolution)(ye(this,Ke),{}))}async build(e={}){return await this.prepareForSerialization(e),await wr(this,cr,Vm).call(this,e),ye(this,Ke).build({onlyTransactionKind:e.onlyTransactionKind})}async getDigest(e={}){return await wr(this,cr,Vm).call(this,e),ye(this,Ke).getDigest()}async prepareForSerialization(e){await wr(this,cr,iE).call(this),wr(this,cr,sE).call(this);let r=new Set;for(let i of ye(this,Ke).commands)i.$Intent&&r.add(i.$Intent.name);let n=[...ye(this,ta)];for(let i of r)if(!e.supportedIntents?.includes(i)){if(!ye(this,Ss).has(i))throw new Error(`Missing intent resolver for ${i}`);n.push(ye(this,Ss).get(i))}await wr(this,cr,Wm).call(this,n,e)}};ta=new WeakMap;ra=new WeakMap;Ss=new WeakMap;Qi=new WeakMap;Ln=new WeakMap;$n=new WeakMap;bi=new WeakMap;ho=new WeakMap;Ke=new WeakMap;cr=new WeakSet;nE=function(){let t=new uE;return Jt(t,Ke,ye(this,Ke)),Jt(t,ta,ye(this,ta)),Jt(t,ra,ye(this,ra)),Jt(t,Ss,ye(this,Ss)),Jt(t,bi,ye(this,bi)),Jt(t,$n,new Set(ye(this,$n))),Jt(t,ho,ye(this,ho)),ye(this,Qi).push(ye(t,Qi)),ye(this,Ln).push(ye(t,Ln)),t};kf=function(t){let e=ye(this,Ke).commands.length;return ye(this,Ln).push(t),ye(this,$n).add(e),ye(this,Ke).commands.push(t),ye(this,Ke).mapCommandArguments(e,r=>{if(r.$kind==="Result"&&!ye(this,$n).has(r.Result))throw new Error(`Result { Result: ${r.Result} } is not available to use the current transaction`);if(r.$kind==="NestedResult"&&!ye(this,$n).has(r.NestedResult[0]))throw new Error(`Result { NestedResult: [${r.NestedResult[0]}, ${r.NestedResult[1]}] } is not available to use the current transaction`);if(r.$kind==="Input"&&r.Input>=ye(this,Ke).inputs.length)throw new Error(`Input { Input: ${r.Input} } references an input that does not exist in the current transaction`);return r}),t};Of=function(t,e){return ye(this,Qi).push(e),ye(this,Ke).addInput(t,e)};Ef=function(t){return(0,Sf.isSerializedBcs)(t)?this.pure(t):wr(this,cr,Af).call(this,t)};Af=function(t){if(typeof t=="function"){let e=this.add(t);return typeof e=="function"?wr(this,cr,Af).call(this,e):(0,fo.parse)(ea.Argument,e)}return(0,fo.parse)(ea.Argument,t)};Vm=async function(t){if(!t.onlyTransactionKind&&!ye(this,Ke).sender)throw new Error("Missing transaction sender");await wr(this,cr,Wm).call(this,[...ye(this,ra),rE.resolveTransactionPlugin],t)};Wm=async function(t,e){let r=n=>{if(n>=t.length)return()=>{};let i=t[n];return async()=>{let s=r(n+1),o=!1,u=!1;if(await i(ye(this,Ke),e,async()=>{if(o)throw new Error(`next() was call multiple times in TransactionPlugin ${n}`);o=!0,await s(),u=!0}),!o)throw new Error(`next() was not called in TransactionPlugin ${n}`);if(!u)throw new Error(`next() was not awaited in TransactionPlugin ${n}`)}};await r(0)(),Jt(this,Qi,ye(this,Ke).inputs.slice()),Jt(this,Ln,ye(this,Ke).commands.slice())};iE=async function(){for(;ye(this,bi).size>0;){let t=Promise.all(ye(this,bi));ye(this,bi).clear(),ye(this,bi).add(t),await t,ye(this,bi).delete(t)}};sE=function(){let t=ye(this,Ke).commands,e=ye(this,Ke).inputs,r=ye(this,Ln).flat(1/0),n=ye(this,Qi).flat(1/0);if(r.length!==t.length)throw new Error("Unexpected number of commands found in transaction data");if(n.length!==e.length)throw new Error("Unexpected number of inputs found in transaction data");let i=r.filter(o=>o.$Intent?.name!=="AsyncTransactionThunk");ye(this,Ke).commands=i,ye(this,Ke).inputs=n,Jt(this,Ln,i),Jt(this,Qi,n),Jt(this,$n,new Set(i.map((o,u)=>u)));function s(o){let u=t[o];if(u.$Intent?.name==="AsyncTransactionThunk"){let d=u.$Intent.data.result;if(d==null)throw new Error("AsyncTransactionThunk has not been resolved");return s(d.Result)}let c=i.indexOf(u);if(c===-1)throw new Error("Unable to find original index for command");return c}ye(this,Ke).mapArguments(o=>{if(o.$kind==="Input"){let u=n.indexOf(e[o.Input]);if(u===-1)throw new Error("Input has not been resolved");return{...o,Input:u}}else if(o.$kind==="Result"){let u=s(o.Result);return{...o,Result:u}}else if(o.$kind==="NestedResult"){let u=s(o.NestedResult[0]);return{...o,NestedResult:[u,o.NestedResult[1]]}}return o});for(let[o,u]of t.entries())if(u.$Intent?.name==="AsyncTransactionThunk")try{u.$Intent.data.resultIndex=s(o)}catch{}};var hR=uE});var Ym=be((iQ,pE)=>{"use strict";var Zm=Object.defineProperty,pR=Object.getOwnPropertyDescriptor,mR=Object.getOwnPropertyNames,gR=Object.prototype.hasOwnProperty,fE=t=>{throw TypeError(t)},yR=(t,e)=>{for(var r in e)Zm(t,r,{get:e[r],enumerable:!0})},_R=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mR(e))!gR.call(t,i)&&i!==r&&Zm(t,i,{get:()=>e[i],enumerable:!(n=pR(e,i))||n.enumerable});return t},vR=t=>_R(Zm({},"__esModule",{value:!0}),t),dE=(t,e,r)=>e.has(t)||fE("Cannot "+r),Mr=(t,e,r)=>(dE(t,e,"read from private field"),r?r.call(t):e.get(t)),Xm=(t,e,r)=>e.has(t)?fE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),lE=(t,e,r,n)=>(dE(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),hE={};yR(hE,{AsyncCache:()=>Tf,InMemoryCache:()=>xf,ObjectCache:()=>Jm});pE.exports=vR(hE);var Km=Nr(),ia,Wr,If,Tf=class{async getObject(e){let[r,n]=await Promise.all([this.get("OwnedObject",e),this.get("SharedOrImmutableObject",e)]);return r??n??null}async getObjects(e){return Promise.all([...e.map(r=>this.getObject(r))])}async addObject(e){return e.owner?await this.set("OwnedObject",e.objectId,e):await this.set("SharedOrImmutableObject",e.objectId,e),e}async addObjects(e){await Promise.all(e.map(async r=>this.addObject(r)))}async deleteObject(e){await Promise.all([this.delete("OwnedObject",e),this.delete("SharedOrImmutableObject",e)])}async deleteObjects(e){await Promise.all(e.map(r=>this.deleteObject(r)))}async getMoveFunctionDefinition(e){let r=`${(0,Km.normalizeSuiAddress)(e.package)}::${e.module}::${e.function}`;return this.get("MoveFunction",r)}async addMoveFunctionDefinition(e){let r=(0,Km.normalizeSuiAddress)(e.package),n=`${r}::${e.module}::${e.function}`,i={...e,package:r};return await this.set("MoveFunction",n,i),i}async deleteMoveFunctionDefinition(e){let r=`${(0,Km.normalizeSuiAddress)(e.package)}::${e.module}::${e.function}`;await this.delete("MoveFunction",r)}async getCustom(e){return this.get("Custom",e)}async setCustom(e,r){return this.set("Custom",e,r)}async deleteCustom(e){return this.delete("Custom",e)}},xf=class extends Tf{constructor(){super(...arguments),Xm(this,ia,{OwnedObject:new Map,SharedOrImmutableObject:new Map,MoveFunction:new Map,Custom:new Map})}async get(e,r){return Mr(this,ia)[e].get(r)??null}async set(e,r,n){Mr(this,ia)[e].set(r,n)}async delete(e,r){Mr(this,ia)[e].delete(r)}async clear(e){if(e)Mr(this,ia)[e].clear();else for(let r of Object.values(Mr(this,ia)))r.clear()}};ia=new WeakMap;var Jm=class{constructor({cache:e=new xf,onEffects:r}){Xm(this,Wr),Xm(this,If),lE(this,Wr,e),lE(this,If,r)}asPlugin(){return async(e,r,n)=>{let i=e.inputs.filter(u=>u.UnresolvedObject).map(u=>u.UnresolvedObject.objectId),s=(await Mr(this,Wr).getObjects(i)).filter(u=>u!==null),o=new Map(s.map(u=>[u.objectId,u]));for(let u of e.inputs){if(!u.UnresolvedObject)continue;let c=o.get(u.UnresolvedObject.objectId);c&&(c.initialSharedVersion&&!u.UnresolvedObject.initialSharedVersion?u.UnresolvedObject.initialSharedVersion=c.initialSharedVersion:(c.version&&!u.UnresolvedObject.version&&(u.UnresolvedObject.version=c.version),c.digest&&!u.UnresolvedObject.digest&&(u.UnresolvedObject.digest=c.digest)))}await Promise.all(e.commands.map(async u=>{if(u.MoveCall){let c=await this.getMoveFunctionDefinition({package:u.MoveCall.package,module:u.MoveCall.module,function:u.MoveCall.function});c&&(u.MoveCall._argumentTypes=c.parameters)}})),await n(),await Promise.all(e.commands.map(async u=>{u.MoveCall?._argumentTypes&&await Mr(this,Wr).addMoveFunctionDefinition({package:u.MoveCall.package,module:u.MoveCall.module,function:u.MoveCall.function,parameters:u.MoveCall._argumentTypes})}))}}async clear(){await Mr(this,Wr).clear()}async getMoveFunctionDefinition(e){return Mr(this,Wr).getMoveFunctionDefinition(e)}async getObjects(e){return Mr(this,Wr).getObjects(e)}async deleteObjects(e){return Mr(this,Wr).deleteObjects(e)}async clearOwnedObjects(){await Mr(this,Wr).clear("OwnedObject")}async clearCustom(){await Mr(this,Wr).clear("Custom")}async getCustom(e){return Mr(this,Wr).getCustom(e)}async setCustom(e,r){return Mr(this,Wr).setCustom(e,r)}async deleteCustom(e){return Mr(this,Wr).deleteCustom(e)}async applyEffects(e){var r;if(!e.V2)throw new Error(`Unsupported transaction effects version ${e.$kind}`);let{lamportVersion:n,changedObjects:i}=e.V2,s=[],o=[];i.forEach(([u,c])=>{if(c.outputState.NotExist)s.push(u);else if(c.outputState.ObjectWrite){let[d,p]=c.outputState.ObjectWrite;o.push({objectId:u,digest:d,version:n,owner:p.AddressOwner??p.ObjectOwner??null,initialSharedVersion:p.Shared?.initialSharedVersion??null})}}),await Promise.all([Mr(this,Wr).addObjects(o),Mr(this,Wr).deleteObjects(s),(r=Mr(this,If))==null?void 0:r.call(this,e)])}};Wr=new WeakMap;If=new WeakMap});var rg=be((sQ,vE)=>{"use strict";var tg=Object.defineProperty,bR=Object.getOwnPropertyDescriptor,wR=Object.getOwnPropertyNames,MR=Object.prototype.hasOwnProperty,gE=t=>{throw TypeError(t)},SR=(t,e)=>{for(var r in e)tg(t,r,{get:e[r],enumerable:!0})},kR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of wR(e))!MR.call(t,i)&&i!==r&&tg(t,i,{get:()=>e[i],enumerable:!(n=bR(e,i))||n.enumerable});return t},OR=t=>kR(tg({},"__esModule",{value:!0}),t),yE=(t,e,r)=>e.has(t)||gE("Cannot "+r),mc=(t,e,r)=>(yE(t,e,"read from private field"),r?r.call(t):e.get(t)),mE=(t,e,r)=>e.has(t)?gE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Qm=(t,e,r,n)=>(yE(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_E={};SR(_E,{CachingTransactionExecutor:()=>eg});vE.exports=OR(_E);var ER=Rn(),AR=Ym(),IR=na(),Va,za,eg=class{constructor({client:e,...r}){mE(this,Va),mE(this,za,null),Qm(this,Va,e),this.cache=new AR.ObjectCache(r)}async reset(){await Promise.all([this.cache.clearOwnedObjects(),this.cache.clearCustom(),this.waitForLastTransaction()])}async buildTransaction({transaction:e,...r}){return e.addBuildPlugin(this.cache.asPlugin()),e.build({client:mc(this,Va),...r})}async executeTransaction({transaction:e,options:r,...n}){let i=(0,IR.isTransaction)(e)?await this.buildTransaction({transaction:e}):e,s=await mc(this,Va).executeTransactionBlock({...n,transactionBlock:i,options:{...r,showRawEffects:!0}});if(s.rawEffects){let o=ER.bcs.TransactionEffects.parse(Uint8Array.from(s.rawEffects));await this.applyEffects(o)}return s}async signAndExecuteTransaction({options:e,transaction:r,...n}){r.setSenderIfNotSet(n.signer.toSuiAddress());let i=await this.buildTransaction({transaction:r}),{signature:s}=await n.signer.signTransaction(i);return await this.executeTransaction({transaction:i,signature:s,options:e})}async applyEffects(e){Qm(this,za,e.V2?.transactionDigest??null),await this.cache.applyEffects(e)}async waitForLastTransaction(){mc(this,za)&&(await mc(this,Va).waitForTransaction({digest:mc(this,za)}),Qm(this,za,null))}};Va=new WeakMap;za=new WeakMap});var og=be((oQ,SE)=>{"use strict";var sg=Object.defineProperty,TR=Object.getOwnPropertyDescriptor,xR=Object.getOwnPropertyNames,PR=Object.prototype.hasOwnProperty,bE=t=>{throw TypeError(t)},CR=(t,e)=>{for(var r in e)sg(t,r,{get:e[r],enumerable:!0})},jR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xR(e))!PR.call(t,i)&&i!==r&&sg(t,i,{get:()=>e[i],enumerable:!(n=TR(e,i))||n.enumerable});return t},NR=t=>jR(sg({},"__esModule",{value:!0}),t),DR=(t,e,r)=>e.has(t)||bE("Cannot "+r),wi=(t,e,r)=>(DR(t,e,"read from private field"),r?r.call(t):e.get(t)),wE=(t,e,r)=>e.has(t)?bE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),ME={};CR(ME,{ParallelQueue:()=>ig,SerialQueue:()=>ng});SE.exports=NR(ME);var po,sa,ng=class{constructor(){wE(this,po,[])}async runTask(e){return new Promise((r,n)=>{wi(this,po).push(()=>{e().finally(()=>{wi(this,po).shift(),wi(this,po).length>0&&wi(this,po)[0]()}).then(r,n)}),wi(this,po).length===1&&wi(this,po)[0]()})}};po=new WeakMap;var ig=class{constructor(e){wE(this,sa,[]),this.activeTasks=0,this.maxTasks=e}runTask(e){return new Promise((r,n)=>{this.activeTasks<this.maxTasks?(this.activeTasks++,e().finally(()=>{wi(this,sa).length>0?wi(this,sa).shift()():this.activeTasks--}).then(r,n)):wi(this,sa).push(()=>{e().finally(()=>{wi(this,sa).length>0?wi(this,sa).shift()():this.activeTasks--}).then(r,n)})})}};sa=new WeakMap});var fg=be((aQ,TE)=>{"use strict";var lg=Object.defineProperty,BR=Object.getOwnPropertyDescriptor,RR=Object.getOwnPropertyNames,UR=Object.prototype.hasOwnProperty,OE=t=>{throw TypeError(t)},LR=(t,e)=>{for(var r in e)lg(t,r,{get:e[r],enumerable:!0})},$R=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of RR(e))!UR.call(t,i)&&i!==r&&lg(t,i,{get:()=>e[i],enumerable:!(n=BR(e,i))||n.enumerable});return t},FR=t=>$R(lg({},"__esModule",{value:!0}),t),EE=(t,e,r)=>e.has(t)||OE("Cannot "+r),Kr=(t,e,r)=>(EE(t,e,"read from private field"),r?r.call(t):e.get(t)),Ga=(t,e,r)=>e.has(t)?OE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),ag=(t,e,r,n)=>(EE(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),AE={};LR(AE,{SerialTransactionExecutor:()=>cg,getGasCoinFromEffects:()=>IE});TE.exports=FR(AE);var qR=dr(),kE=na(),VR=rg(),zR=og(),Pf,gc,Mi,Cf,ug,jf,cg=class{constructor({signer:e,defaultGasBudget:r=50000000n,...n}){Ga(this,Pf,new zR.SerialQueue),Ga(this,gc),Ga(this,Mi),Ga(this,Cf),Ga(this,ug,async i=>{if(!i.V2)return;let s=IE(i).ref;s?Kr(this,Mi).cache.setCustom("gasCoin",s):Kr(this,Mi).cache.deleteCustom("gasCoin")}),Ga(this,jf,async i=>{let s=await Kr(this,Mi).cache.getCustom("gasCoin"),o=kE.Transaction.from(i);return s&&o.setGasPayment([s]),o.setGasBudgetIfNotSet(Kr(this,Cf)),o.setSenderIfNotSet(Kr(this,gc).toSuiAddress()),Kr(this,Mi).buildTransaction({transaction:o})}),ag(this,gc,e),ag(this,Cf,r),ag(this,Mi,new VR.CachingTransactionExecutor({client:n.client,cache:n.cache,onEffects:i=>Kr(this,ug).call(this,i)}))}async applyEffects(e){return Kr(this,Mi).applyEffects(e)}async buildTransaction(e){return Kr(this,Pf).runTask(()=>Kr(this,jf).call(this,e))}resetCache(){return Kr(this,Mi).reset()}waitForLastTransaction(){return Kr(this,Mi).waitForLastTransaction()}executeTransaction(e,r,n=[]){return Kr(this,Pf).runTask(async()=>{let i=(0,kE.isTransaction)(e)?await Kr(this,jf).call(this,e):e,{signature:s}=await Kr(this,gc).signTransaction(i),o=await Kr(this,Mi).executeTransaction({signature:[s,...n],transaction:i,options:r}).catch(async c=>{throw await this.resetCache(),c}),u=Uint8Array.from(o.rawEffects);return{digest:o.digest,effects:(0,qR.toBase64)(u),data:o}})}};Pf=new WeakMap;gc=new WeakMap;Mi=new WeakMap;Cf=new WeakMap;ug=new WeakMap;jf=new WeakMap;function IE(t){if(!t.V2)throw new Error("Unexpected effects version");let e=t.V2.changedObjects[t.V2.gasObjectIndex];if(!e)throw new Error("Gas object not found in effects");let[r,{outputState:n}]=e;if(!n.ObjectWrite)throw new Error("Unexpected gas object state");let[i,s]=n.ObjectWrite;return{ref:{objectId:r,digest:i,version:t.V2.lamportVersion},owner:s.AddressOwner||s.ObjectOwner}}});var FE=be((uQ,$E)=>{"use strict";var pg=Object.defineProperty,GR=Object.getOwnPropertyDescriptor,HR=Object.getOwnPropertyNames,WR=Object.prototype.hasOwnProperty,CE=t=>{throw TypeError(t)},KR=(t,e)=>{for(var r in e)pg(t,r,{get:e[r],enumerable:!0})},XR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of HR(e))!WR.call(t,i)&&i!==r&&pg(t,i,{get:()=>e[i],enumerable:!(n=GR(e,i))||n.enumerable});return t},JR=t=>XR(pg({},"__esModule",{value:!0}),t),mg=(t,e,r)=>e.has(t)||CE("Cannot "+r),qe=(t,e,r)=>(mg(t,e,"read from private field"),r?r.call(t):e.get(t)),Sr=(t,e,r)=>e.has(t)?CE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),or=(t,e,r,n)=>(mg(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Fn=(t,e,r)=>(mg(t,e,"access private method"),r),xE=(t,e,r,n)=>({set _(i){or(t,e,i,r)},get _(){return qe(t,e,n)}}),jE={};KR(jE,{ParallelTransactionExecutor:()=>hg});$E.exports=JR(jE);var ZR=dr(),YR=to(),NE=Rn(),QR=na(),eU=qa(),tU=rg(),PE=og(),DE=fg(),mo,es,Df,vc,_c,bc,Bf,Wa,un,go,aa,oa,gg,Nf,wc,Ha,Ka,ks,pn,BE,RE,Mc,yg,UE,dg,LE,yc={coinBatchSize:20,initialCoinBalance:200000000n,minimumCoinBalance:50000000n,maxPoolSize:50,epochBoundaryWindow:1e3},hg=class{constructor(e){Sr(this,pn),Sr(this,mo),Sr(this,es),Sr(this,Df),Sr(this,vc),Sr(this,_c),Sr(this,bc),Sr(this,Bf),Sr(this,Wa),Sr(this,un),Sr(this,go,[]),Sr(this,aa),Sr(this,oa,new Map),Sr(this,gg,new PE.SerialQueue),Sr(this,Nf),Sr(this,wc,null),Sr(this,Ha,null),Sr(this,Ka,0),Sr(this,ks,null),or(this,mo,e.signer),or(this,es,e.client),or(this,Df,e.coinBatchSize??yc.coinBatchSize),or(this,vc,e.initialCoinBalance??yc.initialCoinBalance),or(this,_c,e.minimumCoinBalance??yc.minimumCoinBalance),or(this,Bf,e.defaultGasBudget??qe(this,_c)),or(this,bc,e.epochBoundaryWindow??yc.epochBoundaryWindow),or(this,Wa,e.maxPoolSize??yc.maxPoolSize),or(this,aa,new tU.CachingTransactionExecutor({client:e.client,cache:e.cache})),or(this,Nf,new PE.ParallelQueue(qe(this,Wa))),or(this,un,e.sourceCoins?new Map(e.sourceCoins.map(r=>[r,null])):null)}resetCache(){return or(this,ks,null),Fn(this,pn,Mc).call(this,()=>qe(this,aa).reset())}async waitForLastTransaction(){await Fn(this,pn,Mc).call(this,()=>Fn(this,pn,yg).call(this))}async executeTransaction(e,r,n=[]){let{promise:i,resolve:s,reject:o}=(0,YR.promiseWithResolvers)(),u=await Fn(this,pn,BE).call(this,e),c=()=>{qe(this,Nf).runTask(()=>Fn(this,pn,RE).call(this,e,u,r,n).then(s,o))},d=new Set;return u.forEach(p=>{qe(this,oa).get(p)?(d.add(p),qe(this,oa).get(p).push(()=>{d.delete(p),d.size===0&&c()})):qe(this,oa).set(p,[])}),d.size===0&&c(),i}};mo=new WeakMap;es=new WeakMap;Df=new WeakMap;vc=new WeakMap;_c=new WeakMap;bc=new WeakMap;Bf=new WeakMap;Wa=new WeakMap;un=new WeakMap;go=new WeakMap;aa=new WeakMap;oa=new WeakMap;gg=new WeakMap;Nf=new WeakMap;wc=new WeakMap;Ha=new WeakMap;Ka=new WeakMap;ks=new WeakMap;pn=new WeakSet;BE=async function(t){let e=new Set,r=!1;return t.addSerializationPlugin(async(n,i,s)=>{await s(),!r&&(r=!0,n.inputs.forEach(o=>{o.Object?.ImmOrOwnedObject?.objectId?e.add(o.Object.ImmOrOwnedObject.objectId):o.Object?.Receiving?.objectId?e.add(o.Object.Receiving.objectId):o.UnresolvedObject?.objectId&&!o.UnresolvedObject.initialSharedVersion&&e.add(o.UnresolvedObject.objectId)}))}),await t.prepareForSerialization({client:qe(this,es)}),e};RE=async function(t,e,r,n=[]){let i;try{t.setSenderIfNotSet(qe(this,mo).toSuiAddress()),await qe(this,gg).runTask(async()=>{t.getData().gasData.price||t.setGasPrice(await Fn(this,pn,dg).call(this)),t.setGasBudgetIfNotSet(qe(this,Bf)),await Fn(this,pn,Mc).call(this),i=await Fn(this,pn,UE).call(this),xE(this,Ka)._++,t.setGasPayment([{objectId:i.id,version:i.version,digest:i.digest}]),await qe(this,aa).buildTransaction({transaction:t,onlyTransactionKind:!0})});let s=await t.build({client:qe(this,es)}),{signature:o}=await qe(this,mo).signTransaction(s),u=await qe(this,aa).executeTransaction({transaction:s,signature:[o,...n],options:{...r,showEffects:!0}}),c=Uint8Array.from(u.rawEffects),d=NE.bcs.TransactionEffects.parse(c),p=(0,DE.getGasCoinFromEffects)(d),_=d.V2?.gasUsed;if(i&&_&&p.owner===qe(this,mo).toSuiAddress()){let b=BigInt(_.computationCost)+BigInt(_.storageCost)+BigInt(_.storageCost)-BigInt(_.storageRebate),O=!1;new eU.TransactionDataBuilder(t.getData()).mapArguments(T=>(T.$kind==="GasCoin"&&(O=!0),T)),!O&&i.balance>=qe(this,_c)?qe(this,go).push({id:p.ref.objectId,version:p.ref.version,digest:p.ref.digest,balance:i.balance-b}):(qe(this,un)||or(this,un,new Map),qe(this,un).set(p.ref.objectId,p.ref))}return or(this,wc,u.digest),{digest:u.digest,effects:(0,ZR.toBase64)(c),data:u}}catch(s){throw i&&(qe(this,un)||or(this,un,new Map),qe(this,un).set(i.id,null)),await Fn(this,pn,Mc).call(this,async()=>{await Promise.all([qe(this,aa).cache.deleteObjects([...e]),Fn(this,pn,yg).call(this)])}),s}finally{e.forEach(s=>{let o=qe(this,oa).get(s);o&&o.length>0?o.shift()():o&&qe(this,oa).delete(s)}),xE(this,Ka)._--}};Mc=async function(t){qe(this,Ha)&&await qe(this,Ha),or(this,Ha,t?.().then(()=>{or(this,Ha,null)},()=>{})??null)};yg=async function(){let t=qe(this,wc);t&&(or(this,wc,null),await qe(this,es).waitForTransaction({digest:t}))};UE=async function(){if(qe(this,go).length===0&&qe(this,Ka)<=qe(this,Wa)&&await Fn(this,pn,LE).call(this),qe(this,go).length===0)throw new Error("No coins available");return qe(this,go).shift()};dg=async function(){if((qe(this,ks)?qe(this,ks).expiration-qe(this,bc)-Date.now():0)>0)return qe(this,ks).price;if(qe(this,ks)){let r=Math.max(qe(this,ks).expiration+qe(this,bc)-Date.now(),1e3);await new Promise(n=>setTimeout(n,r))}let e=await qe(this,es).getLatestSuiSystemState();return or(this,ks,{price:BigInt(e.referenceGasPrice),expiration:Number.parseInt(e.epochStartTimestampMs,10)+Number.parseInt(e.epochDurationMs,10)}),Fn(this,pn,dg).call(this)};LE=async function(){let t=Math.min(qe(this,Df),qe(this,Wa)-(qe(this,go).length+qe(this,Ka))+1);if(t===0)return;let e=new QR.Transaction,r=qe(this,mo).toSuiAddress();if(e.setSender(r),qe(this,un)){let d=[],p=[];for(let[_,b]of qe(this,un))b?d.push(b):p.push(_);if(p.length>0){let _=await qe(this,es).multiGetObjects({ids:p});d.push(..._.filter(b=>b.data!==null).map(({data:b})=>({objectId:b.objectId,version:b.version,digest:b.digest})))}e.setGasPayment(d),or(this,un,new Map)}let n=new Array(t).fill(qe(this,vc)),i=e.splitCoins(e.gas,n),s=[];for(let d=0;d<n.length;d++)s.push(i[d]);e.transferObjects(s,r),await this.waitForLastTransaction();let o=await qe(this,es).signAndExecuteTransaction({transaction:e,signer:qe(this,mo),options:{showRawEffects:!0}}),u=NE.bcs.TransactionEffects.parse(Uint8Array.from(o.rawEffects));u.V2?.changedObjects.forEach(([d,{outputState:p}],_)=>{_===u.V2?.gasObjectIndex||!p.ObjectWrite||qe(this,go).push({id:d,version:u.V2.lamportVersion,digest:p.ObjectWrite[0],balance:BigInt(qe(this,vc))})}),qe(this,un)||or(this,un,new Map);let c=(0,DE.getGasCoinFromEffects)(u).ref;qe(this,un).set(c.objectId,c),await qe(this,es).waitForTransaction({digest:o.digest})}});var KE=be((cQ,WE)=>{"use strict";var _g=Object.defineProperty,rU=Object.getOwnPropertyDescriptor,nU=Object.getOwnPropertyNames,iU=Object.prototype.hasOwnProperty,sU=(t,e)=>{for(var r in e)_g(t,r,{get:e[r],enumerable:!0})},oU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nU(e))!iU.call(t,i)&&i!==r&&_g(t,i,{get:()=>e[i],enumerable:!(n=rU(e,i))||n.enumerable});return t},aU=t=>oU(_g({},"__esModule",{value:!0}),t),zE={};sU(zE,{coinWithBalance:()=>lU,getSuiClient:()=>HE});WE.exports=aU(zE);var Rf=Wi(),uU=Rn(),GE=Nr(),Uf=hf(),qE=Ua(),cU=Im(),Lf="CoinWithBalance",VE=(0,GE.normalizeStructTag)("0x2::sui::SUI");function lU({type:t=VE,balance:e,useGasCoin:r=!0}){let n=null;return i=>{if(n)return n;i.addIntentResolver(Lf,dU);let s=t==="gas"?t:(0,GE.normalizeStructTag)(t);return n=i.add(Uf.Commands.Intent({name:Lf,inputs:{},data:{type:s===VE&&r?"gas":s,balance:BigInt(e)}})),n}}var fU=(0,Rf.object)({type:(0,Rf.string)(),balance:(0,Rf.bigint)()});async function dU(t,e,r){let n=new Set,i=new Map;if(!t.sender)throw new Error("Sender must be set to resolve CoinWithBalance");for(let d of t.commands)if(d.$kind==="$Intent"&&d.$Intent.name===Lf){let{type:p,balance:_}=(0,Rf.parse)(fU,d.$Intent.data);p!=="gas"&&_>0n&&n.add(p),i.set(p,(i.get(p)??0n)+_)}let s=new Set;for(let d of t.inputs)d.Object?.ImmOrOwnedObject&&s.add(d.Object.ImmOrOwnedObject.objectId),d.UnresolvedObject?.objectId&&s.add(d.UnresolvedObject.objectId);let o=new Map,u=HE(e);await Promise.all([...n].map(async d=>{o.set(d,await hU({coinType:d,balance:i.get(d),client:u,owner:t.sender,usedIds:s}))}));let c=new Map;c.set("gas",{$kind:"GasCoin",GasCoin:!0});for(let[d,p]of t.commands.entries()){if(p.$kind!=="$Intent"||p.$Intent.name!==Lf)continue;let{type:_,balance:b}=p.$Intent.data;if(b===0n&&_!=="gas"){t.replaceCommand(d,Uf.Commands.MoveCall({target:"0x2::coin::zero",typeArguments:[_]}));continue}let O=[];if(!c.has(_)){let[T,...x]=o.get(_).map(F=>t.addInput("object",qE.Inputs.ObjectRef({objectId:F.coinObjectId,digest:F.digest,version:F.version})));x.length>0&&O.push(Uf.Commands.MergeCoins(T,x)),c.set(_,T)}O.push(Uf.Commands.SplitCoins(c.get(_),[t.addInput("pure",qE.Inputs.Pure(uU.bcs.u64().serialize(b)))])),t.replaceCommand(d,O),t.mapArguments(T=>T.$kind==="Result"&&T.Result===d?{$kind:"NestedResult",NestedResult:[d+O.length-1,0]}:T)}return r()}async function hU({coinType:t,balance:e,client:r,owner:n,usedIds:i}){let s=e,o=[];return u();async function u(c=null){let{data:d,hasNextPage:p,nextCursor:_}=await r.getCoins({owner:n,coinType:t,cursor:c}),b=d.sort((O,T)=>Number(BigInt(T.balance)-BigInt(O.balance)));for(let O of b){if(i.has(O.coinObjectId))continue;let T=BigInt(O.balance);if(o.push(O),s-=T,s<=0)return o}if(p)return u(_);throw new Error(`Not enough coins of type ${t} to satisfy requested balance`)}}function HE(t){let e=(0,cU.getClient)(t);if(!e.jsonRpc)throw new Error("CoinWithBalance intent currently only works with SuiClient");return e}});var ZE=be((lQ,JE)=>{"use strict";var vg=Object.defineProperty,pU=Object.getOwnPropertyDescriptor,mU=Object.getOwnPropertyNames,gU=Object.prototype.hasOwnProperty,yU=(t,e)=>{for(var r in e)vg(t,r,{get:e[r],enumerable:!0})},_U=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mU(e))!gU.call(t,i)&&i!==r&&vg(t,i,{get:()=>e[i],enumerable:!(n=pU(e,i))||n.enumerable});return t},vU=t=>_U(vg({},"__esModule",{value:!0}),t),XE={};yU(XE,{Arguments:()=>MU});JE.exports=vU(XE);var bU=xm(),wU=jm(),MU={pure:(0,wU.createPure)(t=>e=>e.pure(t)),object:(0,bU.createObjectMethods)(t=>e=>e.object(t)),sharedObjectRef:(...t)=>e=>e.sharedObjectRef(...t),objectRef:(...t)=>e=>e.objectRef(...t),receivingRef:(...t)=>e=>e.receivingRef(...t)}});var iA=be((fQ,nA)=>{"use strict";var bg=Object.defineProperty,SU=Object.getOwnPropertyDescriptor,kU=Object.getOwnPropertyNames,OU=Object.prototype.hasOwnProperty,EU=(t,e)=>{for(var r in e)bg(t,r,{get:e[r],enumerable:!0})},AU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of kU(e))!OU.call(t,i)&&i!==r&&bg(t,i,{get:()=>e[i],enumerable:!(n=SU(e,i))||n.enumerable});return t},IU=t=>AU(bg({},"__esModule",{value:!0}),t),rA={};EU(rA,{Arguments:()=>NU.Arguments,AsyncCache:()=>tA.AsyncCache,Commands:()=>QE.Commands,Inputs:()=>TU.Inputs,ObjectCache:()=>tA.ObjectCache,ParallelTransactionExecutor:()=>CU.ParallelTransactionExecutor,SerialTransactionExecutor:()=>PU.SerialTransactionExecutor,Transaction:()=>eA.Transaction,TransactionDataBuilder:()=>xU.TransactionDataBuilder,UpgradePolicy:()=>QE.UpgradePolicy,coinWithBalance:()=>jU.coinWithBalance,getPureBcsSchema:()=>YE.getPureBcsSchema,isArgument:()=>BU.isArgument,isTransaction:()=>eA.isTransaction,namedPackagesPlugin:()=>DU.namedPackagesPlugin,normalizedTypeToMoveTypeSignature:()=>YE.normalizedTypeToMoveTypeSignature});nA.exports=IU(rA);var YE=D0(),TU=Ua(),QE=hf(),eA=na(),xU=qa(),tA=Ym(),PU=fg(),CU=FE(),jU=KE(),NU=ZE(),DU=Mm(),BU=$m()});var wg=be((sA,$f)=>{"use strict";(function(t){"use strict";var e,r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,s="[BigNumber Error] ",o=s+"Number primitive has more than 15 significant digits: ",u=1e14,c=14,d=9007199254740991,p=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],_=1e7,b=1e9;function O(ae){var te,he,A,I=f.prototype={constructor:f,toString:null,valueOf:null},C=new f(1),D=20,N=4,k=-7,m=21,a=-1e7,l=1e7,h=!1,y=1,v=0,M={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},w="0123456789abcdefghijklmnopqrstuvwxyz",g=!0;function f(E,P){var j,L,U,W,q,$,X,G,K=this;if(!(K instanceof f))return new f(E,P);if(P==null){if(E&&E._isBigNumber===!0){K.s=E.s,!E.c||E.e>l?K.c=K.e=null:E.e<a?K.c=[K.e=0]:(K.e=E.e,K.c=E.c.slice());return}if(($=typeof E=="number")&&E*0==0){if(K.s=1/E<0?(E=-E,-1):1,E===~~E){for(W=0,q=E;q>=10;q/=10,W++);W>l?K.c=K.e=null:(K.e=W,K.c=[E]);return}G=String(E)}else{if(!r.test(G=String(E)))return A(K,G,$);K.s=G.charCodeAt(0)==45?(G=G.slice(1),-1):1}(W=G.indexOf("."))>-1&&(G=G.replace(".","")),(q=G.search(/e/i))>0?(W<0&&(W=q),W+=+G.slice(q+1),G=G.substring(0,q)):W<0&&(W=G.length)}else{if(R(P,2,w.length,"Base"),P==10&&g)return K=new f(E),Z(K,D+K.e+1,N);if(G=String(E),$=typeof E=="number"){if(E*0!=0)return A(K,G,$,P);if(K.s=1/E<0?(G=G.slice(1),-1):1,f.DEBUG&&G.replace(/^0\.0*|\./,"").length>15)throw Error(o+E)}else K.s=G.charCodeAt(0)===45?(G=G.slice(1),-1):1;for(j=w.slice(0,P),W=q=0,X=G.length;q<X;q++)if(j.indexOf(L=G.charAt(q))<0){if(L=="."){if(q>W){W=X;continue}}else if(!U&&(G==G.toUpperCase()&&(G=G.toLowerCase())||G==G.toLowerCase()&&(G=G.toUpperCase()))){U=!0,q=-1,W=0;continue}return A(K,String(E),$,P)}$=!1,G=he(G,P,10,K.s),(W=G.indexOf("."))>-1?G=G.replace(".",""):W=G.length}for(q=0;G.charCodeAt(q)===48;q++);for(X=G.length;G.charCodeAt(--X)===48;);if(G=G.slice(q,++X)){if(X-=q,$&&f.DEBUG&&X>15&&(E>d||E!==i(E)))throw Error(o+K.s*E);if((W=W-q-1)>l)K.c=K.e=null;else if(W<a)K.c=[K.e=0];else{if(K.e=W,K.c=[],q=(W+1)%c,W<0&&(q+=c),q<X){for(q&&K.c.push(+G.slice(0,q)),X-=c;q<X;)K.c.push(+G.slice(q,q+=c));q=c-(G=G.slice(q)).length}else q-=X;for(;q--;G+="0");K.c.push(+G)}}else K.c=[K.e=0]}f.clone=O,f.ROUND_UP=0,f.ROUND_DOWN=1,f.ROUND_CEIL=2,f.ROUND_FLOOR=3,f.ROUND_HALF_UP=4,f.ROUND_HALF_DOWN=5,f.ROUND_HALF_EVEN=6,f.ROUND_HALF_CEIL=7,f.ROUND_HALF_FLOOR=8,f.EUCLID=9,f.config=f.set=function(E){var P,j;if(E!=null)if(typeof E=="object"){if(E.hasOwnProperty(P="DECIMAL_PLACES")&&(j=E[P],R(j,0,b,P),D=j),E.hasOwnProperty(P="ROUNDING_MODE")&&(j=E[P],R(j,0,8,P),N=j),E.hasOwnProperty(P="EXPONENTIAL_AT")&&(j=E[P],j&&j.pop?(R(j[0],-b,0,P),R(j[1],0,b,P),k=j[0],m=j[1]):(R(j,-b,b,P),k=-(m=j<0?-j:j))),E.hasOwnProperty(P="RANGE"))if(j=E[P],j&&j.pop)R(j[0],-b,-1,P),R(j[1],1,b,P),a=j[0],l=j[1];else if(R(j,-b,b,P),j)a=-(l=j<0?-j:j);else throw Error(s+P+" cannot be zero: "+j);if(E.hasOwnProperty(P="CRYPTO"))if(j=E[P],j===!!j)if(j)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))h=j;else throw h=!j,Error(s+"crypto unavailable");else h=j;else throw Error(s+P+" not true or false: "+j);if(E.hasOwnProperty(P="MODULO_MODE")&&(j=E[P],R(j,0,9,P),y=j),E.hasOwnProperty(P="POW_PRECISION")&&(j=E[P],R(j,0,b,P),v=j),E.hasOwnProperty(P="FORMAT"))if(j=E[P],typeof j=="object")M=j;else throw Error(s+P+" not an object: "+j);if(E.hasOwnProperty(P="ALPHABET"))if(j=E[P],typeof j=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(j))g=j.slice(0,10)=="0123456789",w=j;else throw Error(s+P+" invalid: "+j)}else throw Error(s+"Object expected: "+E);return{DECIMAL_PLACES:D,ROUNDING_MODE:N,EXPONENTIAL_AT:[k,m],RANGE:[a,l],CRYPTO:h,MODULO_MODE:y,POW_PRECISION:v,FORMAT:M,ALPHABET:w}},f.isBigNumber=function(E){if(!E||E._isBigNumber!==!0)return!1;if(!f.DEBUG)return!0;var P,j,L=E.c,U=E.e,W=E.s;e:if({}.toString.call(L)=="[object Array]"){if((W===1||W===-1)&&U>=-b&&U<=b&&U===i(U)){if(L[0]===0){if(U===0&&L.length===1)return!0;break e}if(P=(U+1)%c,P<1&&(P+=c),String(L[0]).length==P){for(P=0;P<L.length;P++)if(j=L[P],j<0||j>=u||j!==i(j))break e;if(j!==0)return!0}}}else if(L===null&&U===null&&(W===null||W===1||W===-1))return!0;throw Error(s+"Invalid BigNumber: "+E)},f.maximum=f.max=function(){return V(arguments,-1)},f.minimum=f.min=function(){return V(arguments,1)},f.random=(function(){var E=9007199254740992,P=Math.random()*E&2097151?function(){return i(Math.random()*E)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(j){var L,U,W,q,$,X=0,G=[],K=new f(C);if(j==null?j=D:R(j,0,b),q=n(j/c),h)if(crypto.getRandomValues){for(L=crypto.getRandomValues(new Uint32Array(q*=2));X<q;)$=L[X]*131072+(L[X+1]>>>11),$>=9e15?(U=crypto.getRandomValues(new Uint32Array(2)),L[X]=U[0],L[X+1]=U[1]):(G.push($%1e14),X+=2);X=q/2}else if(crypto.randomBytes){for(L=crypto.randomBytes(q*=7);X<q;)$=(L[X]&31)*281474976710656+L[X+1]*1099511627776+L[X+2]*4294967296+L[X+3]*16777216+(L[X+4]<<16)+(L[X+5]<<8)+L[X+6],$>=9e15?crypto.randomBytes(7).copy(L,X):(G.push($%1e14),X+=7);X=q/7}else throw h=!1,Error(s+"crypto unavailable");if(!h)for(;X<q;)$=P(),$<9e15&&(G[X++]=$%1e14);for(q=G[--X],j%=c,q&&j&&($=p[c-j],G[X]=i(q/$)*$);G[X]===0;G.pop(),X--);if(X<0)G=[W=0];else{for(W=-1;G[0]===0;G.splice(0,1),W-=c);for(X=1,$=G[0];$>=10;$/=10,X++);X<c&&(W-=c-X)}return K.e=W,K.c=G,K}})(),f.sum=function(){for(var E=1,P=arguments,j=new f(P[0]);E<P.length;)j=j.plus(P[E++]);return j},he=(function(){var E="0123456789";function P(j,L,U,W){for(var q,$=[0],X,G=0,K=j.length;G<K;){for(X=$.length;X--;$[X]*=L);for($[0]+=W.indexOf(j.charAt(G++)),q=0;q<$.length;q++)$[q]>U-1&&($[q+1]==null&&($[q+1]=0),$[q+1]+=$[q]/U|0,$[q]%=U)}return $.reverse()}return function(j,L,U,W,q){var $,X,G,K,ie,oe,pe,Fe,_e=j.indexOf("."),Ie=D,Le=N;for(_e>=0&&(K=v,v=0,j=j.replace(".",""),Fe=new f(L),oe=Fe.pow(j.length-_e),v=K,Fe.c=P(ee(x(oe.c),oe.e,"0"),10,U,E),Fe.e=Fe.c.length),pe=P(j,L,U,q?($=w,E):($=E,w)),G=K=pe.length;pe[--K]==0;pe.pop());if(!pe[0])return $.charAt(0);if(_e<0?--G:(oe.c=pe,oe.e=G,oe.s=W,oe=te(oe,Fe,Ie,Le,U),pe=oe.c,ie=oe.r,G=oe.e),X=G+Ie+1,_e=pe[X],K=U/2,ie=ie||X<0||pe[X+1]!=null,ie=Le<4?(_e!=null||ie)&&(Le==0||Le==(oe.s<0?3:2)):_e>K||_e==K&&(Le==4||ie||Le==6&&pe[X-1]&1||Le==(oe.s<0?8:7)),X<1||!pe[0])j=ie?ee($.charAt(1),-Ie,$.charAt(0)):$.charAt(0);else{if(pe.length=X,ie)for(--U;++pe[--X]>U;)pe[X]=0,X||(++G,pe=[1].concat(pe));for(K=pe.length;!pe[--K];);for(_e=0,j="";_e<=K;j+=$.charAt(pe[_e++]));j=ee(j,G,$.charAt(0))}return j}})(),te=(function(){function E(L,U,W){var q,$,X,G,K=0,ie=L.length,oe=U%_,pe=U/_|0;for(L=L.slice();ie--;)X=L[ie]%_,G=L[ie]/_|0,q=pe*X+G*oe,$=oe*X+q%_*_+K,K=($/W|0)+(q/_|0)+pe*G,L[ie]=$%W;return K&&(L=[K].concat(L)),L}function P(L,U,W,q){var $,X;if(W!=q)X=W>q?1:-1;else for($=X=0;$<W;$++)if(L[$]!=U[$]){X=L[$]>U[$]?1:-1;break}return X}function j(L,U,W,q){for(var $=0;W--;)L[W]-=$,$=L[W]<U[W]?1:0,L[W]=$*q+L[W]-U[W];for(;!L[0]&&L.length>1;L.splice(0,1));}return function(L,U,W,q,$){var X,G,K,ie,oe,pe,Fe,_e,Ie,Le,me,Ue,It,Ee,tt,kt,Oe,Ve=L.s==U.s?1:-1,wt=L.c,ve=U.c;if(!wt||!wt[0]||!ve||!ve[0])return new f(!L.s||!U.s||(wt?ve&&wt[0]==ve[0]:!ve)?NaN:wt&&wt[0]==0||!ve?Ve*0:Ve/0);for(_e=new f(Ve),Ie=_e.c=[],G=L.e-U.e,Ve=W+G+1,$||($=u,G=T(L.e/c)-T(U.e/c),Ve=Ve/c|0),K=0;ve[K]==(wt[K]||0);K++);if(ve[K]>(wt[K]||0)&&G--,Ve<0)Ie.push(1),ie=!0;else{for(Ee=wt.length,kt=ve.length,K=0,Ve+=2,oe=i($/(ve[0]+1)),oe>1&&(ve=E(ve,oe,$),wt=E(wt,oe,$),kt=ve.length,Ee=wt.length),It=kt,Le=wt.slice(0,kt),me=Le.length;me<kt;Le[me++]=0);Oe=ve.slice(),Oe=[0].concat(Oe),tt=ve[0],ve[1]>=$/2&&tt++;do{if(oe=0,X=P(ve,Le,kt,me),X<0){if(Ue=Le[0],kt!=me&&(Ue=Ue*$+(Le[1]||0)),oe=i(Ue/tt),oe>1)for(oe>=$&&(oe=$-1),pe=E(ve,oe,$),Fe=pe.length,me=Le.length;P(pe,Le,Fe,me)==1;)oe--,j(pe,kt<Fe?Oe:ve,Fe,$),Fe=pe.length,X=1;else oe==0&&(X=oe=1),pe=ve.slice(),Fe=pe.length;if(Fe<me&&(pe=[0].concat(pe)),j(Le,pe,me,$),me=Le.length,X==-1)for(;P(ve,Le,kt,me)<1;)oe++,j(Le,kt<me?Oe:ve,me,$),me=Le.length}else X===0&&(oe++,Le=[0]);Ie[K++]=oe,Le[0]?Le[me++]=wt[It]||0:(Le=[wt[It]],me=1)}while((It++<Ee||Le[0]!=null)&&Ve--);ie=Le[0]!=null,Ie[0]||Ie.splice(0,1)}if($==u){for(K=1,Ve=Ie[0];Ve>=10;Ve/=10,K++);Z(_e,W+(_e.e=K+G*c-1)+1,q,ie)}else _e.e=G,_e.r=+ie;return _e}})();function S(E,P,j,L){var U,W,q,$,X;if(j==null?j=N:R(j,0,8),!E.c)return E.toString();if(U=E.c[0],q=E.e,P==null)X=x(E.c),X=L==1||L==2&&(q<=k||q>=m)?J(X,q):ee(X,q,"0");else if(E=Z(new f(E),P,j),W=E.e,X=x(E.c),$=X.length,L==1||L==2&&(P<=W||W<=k)){for(;$<P;X+="0",$++);X=J(X,W)}else if(P-=q+(L===2&&W>q),X=ee(X,W,"0"),W+1>$){if(--P>0)for(X+=".";P--;X+="0");}else if(P+=W-$,P>0)for(W+1==$&&(X+=".");P--;X+="0");return E.s<0&&U?"-"+X:X}function V(E,P){for(var j,L,U=1,W=new f(E[0]);U<E.length;U++)L=new f(E[U]),(!L.s||(j=F(W,L))===P||j===0&&W.s===P)&&(W=L);return W}function z(E,P,j){for(var L=1,U=P.length;!P[--U];P.pop());for(U=P[0];U>=10;U/=10,L++);return(j=L+j*c-1)>l?E.c=E.e=null:j<a?E.c=[E.e=0]:(E.e=j,E.c=P),E}A=(function(){var E=/^(-?)0([xbo])(?=\w[\w.]*$)/i,P=/^([^.]+)\.$/,j=/^\.([^.]+)$/,L=/^-?(Infinity|NaN)$/,U=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(W,q,$,X){var G,K=$?q:q.replace(U,"");if(L.test(K))W.s=isNaN(K)?null:K<0?-1:1;else{if(!$&&(K=K.replace(E,function(ie,oe,pe){return G=(pe=pe.toLowerCase())=="x"?16:pe=="b"?2:8,!X||X==G?oe:ie}),X&&(G=X,K=K.replace(P,"$1").replace(j,"0.$1")),q!=K))return new f(K,G);if(f.DEBUG)throw Error(s+"Not a"+(X?" base "+X:"")+" number: "+q);W.s=null}W.c=W.e=null}})();function Z(E,P,j,L){var U,W,q,$,X,G,K,ie=E.c,oe=p;if(ie){e:{for(U=1,$=ie[0];$>=10;$/=10,U++);if(W=P-U,W<0)W+=c,q=P,X=ie[G=0],K=i(X/oe[U-q-1]%10);else if(G=n((W+1)/c),G>=ie.length)if(L){for(;ie.length<=G;ie.push(0));X=K=0,U=1,W%=c,q=W-c+1}else break e;else{for(X=$=ie[G],U=1;$>=10;$/=10,U++);W%=c,q=W-c+U,K=q<0?0:i(X/oe[U-q-1]%10)}if(L=L||P<0||ie[G+1]!=null||(q<0?X:X%oe[U-q-1]),L=j<4?(K||L)&&(j==0||j==(E.s<0?3:2)):K>5||K==5&&(j==4||L||j==6&&(W>0?q>0?X/oe[U-q]:0:ie[G-1])%10&1||j==(E.s<0?8:7)),P<1||!ie[0])return ie.length=0,L?(P-=E.e+1,ie[0]=oe[(c-P%c)%c],E.e=-P||0):ie[0]=E.e=0,E;if(W==0?(ie.length=G,$=1,G--):(ie.length=G+1,$=oe[c-W],ie[G]=q>0?i(X/oe[U-q]%oe[q])*$:0),L)for(;;)if(G==0){for(W=1,q=ie[0];q>=10;q/=10,W++);for(q=ie[0]+=$,$=1;q>=10;q/=10,$++);W!=$&&(E.e++,ie[0]==u&&(ie[0]=1));break}else{if(ie[G]+=$,ie[G]!=u)break;ie[G--]=0,$=1}for(W=ie.length;ie[--W]===0;ie.pop());}E.e>l?E.c=E.e=null:E.e<a&&(E.c=[E.e=0])}return E}function ce(E){var P,j=E.e;return j===null?E.toString():(P=x(E.c),P=j<=k||j>=m?J(P,j):ee(P,j,"0"),E.s<0?"-"+P:P)}return I.absoluteValue=I.abs=function(){var E=new f(this);return E.s<0&&(E.s=1),E},I.comparedTo=function(E,P){return F(this,new f(E,P))},I.decimalPlaces=I.dp=function(E,P){var j,L,U,W=this;if(E!=null)return R(E,0,b),P==null?P=N:R(P,0,8),Z(new f(W),E+W.e+1,P);if(!(j=W.c))return null;if(L=((U=j.length-1)-T(this.e/c))*c,U=j[U])for(;U%10==0;U/=10,L--);return L<0&&(L=0),L},I.dividedBy=I.div=function(E,P){return te(this,new f(E,P),D,N)},I.dividedToIntegerBy=I.idiv=function(E,P){return te(this,new f(E,P),0,1)},I.exponentiatedBy=I.pow=function(E,P){var j,L,U,W,q,$,X,G,K,ie=this;if(E=new f(E),E.c&&!E.isInteger())throw Error(s+"Exponent not an integer: "+ce(E));if(P!=null&&(P=new f(P)),$=E.e>14,!ie.c||!ie.c[0]||ie.c[0]==1&&!ie.e&&ie.c.length==1||!E.c||!E.c[0])return K=new f(Math.pow(+ce(ie),$?E.s*(2-H(E)):+ce(E))),P?K.mod(P):K;if(X=E.s<0,P){if(P.c?!P.c[0]:!P.s)return new f(NaN);L=!X&&ie.isInteger()&&P.isInteger(),L&&(ie=ie.mod(P))}else{if(E.e>9&&(ie.e>0||ie.e<-1||(ie.e==0?ie.c[0]>1||$&&ie.c[1]>=24e7:ie.c[0]<8e13||$&&ie.c[0]<=9999975e7)))return W=ie.s<0&&H(E)?-0:0,ie.e>-1&&(W=1/W),new f(X?1/W:W);v&&(W=n(v/c+2))}for($?(j=new f(.5),X&&(E.s=1),G=H(E)):(U=Math.abs(+ce(E)),G=U%2),K=new f(C);;){if(G){if(K=K.times(ie),!K.c)break;W?K.c.length>W&&(K.c.length=W):L&&(K=K.mod(P))}if(U){if(U=i(U/2),U===0)break;G=U%2}else if(E=E.times(j),Z(E,E.e+1,1),E.e>14)G=H(E);else{if(U=+ce(E),U===0)break;G=U%2}ie=ie.times(ie),W?ie.c&&ie.c.length>W&&(ie.c.length=W):L&&(ie=ie.mod(P))}return L?K:(X&&(K=C.div(K)),P?K.mod(P):W?Z(K,v,N,q):K)},I.integerValue=function(E){var P=new f(this);return E==null?E=N:R(E,0,8),Z(P,P.e+1,E)},I.isEqualTo=I.eq=function(E,P){return F(this,new f(E,P))===0},I.isFinite=function(){return!!this.c},I.isGreaterThan=I.gt=function(E,P){return F(this,new f(E,P))>0},I.isGreaterThanOrEqualTo=I.gte=function(E,P){return(P=F(this,new f(E,P)))===1||P===0},I.isInteger=function(){return!!this.c&&T(this.e/c)>this.c.length-2},I.isLessThan=I.lt=function(E,P){return F(this,new f(E,P))<0},I.isLessThanOrEqualTo=I.lte=function(E,P){return(P=F(this,new f(E,P)))===-1||P===0},I.isNaN=function(){return!this.s},I.isNegative=function(){return this.s<0},I.isPositive=function(){return this.s>0},I.isZero=function(){return!!this.c&&this.c[0]==0},I.minus=function(E,P){var j,L,U,W,q=this,$=q.s;if(E=new f(E,P),P=E.s,!$||!P)return new f(NaN);if($!=P)return E.s=-P,q.plus(E);var X=q.e/c,G=E.e/c,K=q.c,ie=E.c;if(!X||!G){if(!K||!ie)return K?(E.s=-P,E):new f(ie?q:NaN);if(!K[0]||!ie[0])return ie[0]?(E.s=-P,E):new f(K[0]?q:N==3?-0:0)}if(X=T(X),G=T(G),K=K.slice(),$=X-G){for((W=$<0)?($=-$,U=K):(G=X,U=ie),U.reverse(),P=$;P--;U.push(0));U.reverse()}else for(L=(W=($=K.length)<(P=ie.length))?$:P,$=P=0;P<L;P++)if(K[P]!=ie[P]){W=K[P]<ie[P];break}if(W&&(U=K,K=ie,ie=U,E.s=-E.s),P=(L=ie.length)-(j=K.length),P>0)for(;P--;K[j++]=0);for(P=u-1;L>$;){if(K[--L]<ie[L]){for(j=L;j&&!K[--j];K[j]=P);--K[j],K[L]+=u}K[L]-=ie[L]}for(;K[0]==0;K.splice(0,1),--G);return K[0]?z(E,K,G):(E.s=N==3?-1:1,E.c=[E.e=0],E)},I.modulo=I.mod=function(E,P){var j,L,U=this;return E=new f(E,P),!U.c||!E.s||E.c&&!E.c[0]?new f(NaN):!E.c||U.c&&!U.c[0]?new f(U):(y==9?(L=E.s,E.s=1,j=te(U,E,0,3),E.s=L,j.s*=L):j=te(U,E,0,y),E=U.minus(j.times(E)),!E.c[0]&&y==1&&(E.s=U.s),E)},I.multipliedBy=I.times=function(E,P){var j,L,U,W,q,$,X,G,K,ie,oe,pe,Fe,_e,Ie,Le=this,me=Le.c,Ue=(E=new f(E,P)).c;if(!me||!Ue||!me[0]||!Ue[0])return!Le.s||!E.s||me&&!me[0]&&!Ue||Ue&&!Ue[0]&&!me?E.c=E.e=E.s=null:(E.s*=Le.s,!me||!Ue?E.c=E.e=null:(E.c=[0],E.e=0)),E;for(L=T(Le.e/c)+T(E.e/c),E.s*=Le.s,X=me.length,ie=Ue.length,X<ie&&(Fe=me,me=Ue,Ue=Fe,U=X,X=ie,ie=U),U=X+ie,Fe=[];U--;Fe.push(0));for(_e=u,Ie=_,U=ie;--U>=0;){for(j=0,oe=Ue[U]%Ie,pe=Ue[U]/Ie|0,q=X,W=U+q;W>U;)G=me[--q]%Ie,K=me[q]/Ie|0,$=pe*G+K*oe,G=oe*G+$%Ie*Ie+Fe[W]+j,j=(G/_e|0)+($/Ie|0)+pe*K,Fe[W--]=G%_e;Fe[W]=j}return j?++L:Fe.splice(0,1),z(E,Fe,L)},I.negated=function(){var E=new f(this);return E.s=-E.s||null,E},I.plus=function(E,P){var j,L=this,U=L.s;if(E=new f(E,P),P=E.s,!U||!P)return new f(NaN);if(U!=P)return E.s=-P,L.minus(E);var W=L.e/c,q=E.e/c,$=L.c,X=E.c;if(!W||!q){if(!$||!X)return new f(U/0);if(!$[0]||!X[0])return X[0]?E:new f($[0]?L:U*0)}if(W=T(W),q=T(q),$=$.slice(),U=W-q){for(U>0?(q=W,j=X):(U=-U,j=$),j.reverse();U--;j.push(0));j.reverse()}for(U=$.length,P=X.length,U-P<0&&(j=X,X=$,$=j,P=U),U=0;P;)U=($[--P]=$[P]+X[P]+U)/u|0,$[P]=u===$[P]?0:$[P]%u;return U&&($=[U].concat($),++q),z(E,$,q)},I.precision=I.sd=function(E,P){var j,L,U,W=this;if(E!=null&&E!==!!E)return R(E,1,b),P==null?P=N:R(P,0,8),Z(new f(W),E,P);if(!(j=W.c))return null;if(U=j.length-1,L=U*c+1,U=j[U]){for(;U%10==0;U/=10,L--);for(U=j[0];U>=10;U/=10,L++);}return E&&W.e+1>L&&(L=W.e+1),L},I.shiftedBy=function(E){return R(E,-d,d),this.times("1e"+E)},I.squareRoot=I.sqrt=function(){var E,P,j,L,U,W=this,q=W.c,$=W.s,X=W.e,G=D+4,K=new f("0.5");if($!==1||!q||!q[0])return new f(!$||$<0&&(!q||q[0])?NaN:q?W:1/0);if($=Math.sqrt(+ce(W)),$==0||$==1/0?(P=x(q),(P.length+X)%2==0&&(P+="0"),$=Math.sqrt(+P),X=T((X+1)/2)-(X<0||X%2),$==1/0?P="5e"+X:(P=$.toExponential(),P=P.slice(0,P.indexOf("e")+1)+X),j=new f(P)):j=new f($+""),j.c[0]){for(X=j.e,$=X+G,$<3&&($=0);;)if(U=j,j=K.times(U.plus(te(W,U,G,1))),x(U.c).slice(0,$)===(P=x(j.c)).slice(0,$))if(j.e<X&&--$,P=P.slice($-3,$+1),P=="9999"||!L&&P=="4999"){if(!L&&(Z(U,U.e+D+2,0),U.times(U).eq(W))){j=U;break}G+=4,$+=4,L=1}else{(!+P||!+P.slice(1)&&P.charAt(0)=="5")&&(Z(j,j.e+D+2,1),E=!j.times(j).eq(W));break}}return Z(j,j.e+D+1,N,E)},I.toExponential=function(E,P){return E!=null&&(R(E,0,b),E++),S(this,E,P,1)},I.toFixed=function(E,P){return E!=null&&(R(E,0,b),E=E+this.e+1),S(this,E,P)},I.toFormat=function(E,P,j){var L,U=this;if(j==null)E!=null&&P&&typeof P=="object"?(j=P,P=null):E&&typeof E=="object"?(j=E,E=P=null):j=M;else if(typeof j!="object")throw Error(s+"Argument not an object: "+j);if(L=U.toFixed(E,P),U.c){var W,q=L.split("."),$=+j.groupSize,X=+j.secondaryGroupSize,G=j.groupSeparator||"",K=q[0],ie=q[1],oe=U.s<0,pe=oe?K.slice(1):K,Fe=pe.length;if(X&&(W=$,$=X,X=W,Fe-=W),$>0&&Fe>0){for(W=Fe%$||$,K=pe.substr(0,W);W<Fe;W+=$)K+=G+pe.substr(W,$);X>0&&(K+=G+pe.slice(W)),oe&&(K="-"+K)}L=ie?K+(j.decimalSeparator||"")+((X=+j.fractionGroupSize)?ie.replace(new RegExp("\\d{"+X+"}\\B","g"),"$&"+(j.fractionGroupSeparator||"")):ie):K}return(j.prefix||"")+L+(j.suffix||"")},I.toFraction=function(E){var P,j,L,U,W,q,$,X,G,K,ie,oe,pe=this,Fe=pe.c;if(E!=null&&($=new f(E),!$.isInteger()&&($.c||$.s!==1)||$.lt(C)))throw Error(s+"Argument "+($.isInteger()?"out of range: ":"not an integer: ")+ce($));if(!Fe)return new f(pe);for(P=new f(C),G=j=new f(C),L=X=new f(C),oe=x(Fe),W=P.e=oe.length-pe.e-1,P.c[0]=p[(q=W%c)<0?c+q:q],E=!E||$.comparedTo(P)>0?W>0?P:G:$,q=l,l=1/0,$=new f(oe),X.c[0]=0;K=te($,P,0,1),U=j.plus(K.times(L)),U.comparedTo(E)!=1;)j=L,L=U,G=X.plus(K.times(U=G)),X=U,P=$.minus(K.times(U=P)),$=U;return U=te(E.minus(j),L,0,1),X=X.plus(U.times(G)),j=j.plus(U.times(L)),X.s=G.s=pe.s,W=W*2,ie=te(G,L,W,N).minus(pe).abs().comparedTo(te(X,j,W,N).minus(pe).abs())<1?[G,L]:[X,j],l=q,ie},I.toNumber=function(){return+ce(this)},I.toPrecision=function(E,P){return E!=null&&R(E,1,b),S(this,E,P,2)},I.toString=function(E){var P,j=this,L=j.s,U=j.e;return U===null?L?(P="Infinity",L<0&&(P="-"+P)):P="NaN":(E==null?P=U<=k||U>=m?J(x(j.c),U):ee(x(j.c),U,"0"):E===10&&g?(j=Z(new f(j),D+U+1,N),P=ee(x(j.c),j.e,"0")):(R(E,2,w.length,"Base"),P=he(ee(x(j.c),U,"0"),10,E,L,!0)),L<0&&j.c[0]&&(P="-"+P)),P},I.valueOf=I.toJSON=function(){return ce(this)},I._isBigNumber=!0,ae!=null&&f.set(ae),f}function T(ae){var te=ae|0;return ae>0||ae===te?te:te-1}function x(ae){for(var te,he,A=1,I=ae.length,C=ae[0]+"";A<I;){for(te=ae[A++]+"",he=c-te.length;he--;te="0"+te);C+=te}for(I=C.length;C.charCodeAt(--I)===48;);return C.slice(0,I+1||1)}function F(ae,te){var he,A,I=ae.c,C=te.c,D=ae.s,N=te.s,k=ae.e,m=te.e;if(!D||!N)return null;if(he=I&&!I[0],A=C&&!C[0],he||A)return he?A?0:-N:D;if(D!=N)return D;if(he=D<0,A=k==m,!I||!C)return A?0:!I^he?1:-1;if(!A)return k>m^he?1:-1;for(N=(k=I.length)<(m=C.length)?k:m,D=0;D<N;D++)if(I[D]!=C[D])return I[D]>C[D]^he?1:-1;return k==m?0:k>m^he?1:-1}function R(ae,te,he,A){if(ae<te||ae>he||ae!==i(ae))throw Error(s+(A||"Argument")+(typeof ae=="number"?ae<te||ae>he?" out of range: ":" not an integer: ":" not a primitive number: ")+String(ae))}function H(ae){var te=ae.c.length-1;return T(ae.e/c)==te&&ae.c[te]%2!=0}function J(ae,te){return(ae.length>1?ae.charAt(0)+"."+ae.slice(1):ae)+(te<0?"e":"e+")+te}function ee(ae,te,he){var A,I;if(te<0){for(I=he+".";++te;I+=he);ae=I+ae}else if(A=ae.length,++te>A){for(I=he,te-=A;--te;I+=he);ae+=I}else te<A&&(ae=ae.slice(0,te)+"."+ae.slice(te));return ae}e=O(),e.default=e.BigNumber=e,typeof define=="function"&&define.amd?define(function(){return e}):typeof $f<"u"&&$f.exports?$f.exports=e:(t||(t=typeof self<"u"&&self?self:window),t.BigNumber=e)})(sA)});var cA=be((dQ,uA)=>{"use strict";var oA=wg(),aA=uA.exports;(function(){"use strict";function t(d){return d<10?"0"+d:d}var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,r=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,n,i,s={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},o;function u(d){return r.lastIndex=0,r.test(d)?'"'+d.replace(r,function(p){var _=s[p];return typeof _=="string"?_:"\\u"+("0000"+p.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+d+'"'}function c(d,p){var _,b,O,T,x=n,F,R=p[d],H=R!=null&&(R instanceof oA||oA.isBigNumber(R));switch(R&&typeof R=="object"&&typeof R.toJSON=="function"&&(R=R.toJSON(d)),typeof o=="function"&&(R=o.call(p,d,R)),typeof R){case"string":return H?R:u(R);case"number":return isFinite(R)?String(R):"null";case"boolean":case"null":case"bigint":return String(R);case"object":if(!R)return"null";if(n+=i,F=[],Object.prototype.toString.apply(R)==="[object Array]"){for(T=R.length,_=0;_<T;_+=1)F[_]=c(_,R)||"null";return O=F.length===0?"[]":n?`[
8
+ `+n+F.join(`,
9
+ `+n)+`
10
+ `+x+"]":"["+F.join(",")+"]",n=x,O}if(o&&typeof o=="object")for(T=o.length,_=0;_<T;_+=1)typeof o[_]=="string"&&(b=o[_],O=c(b,R),O&&F.push(u(b)+(n?": ":":")+O));else Object.keys(R).forEach(function(J){var ee=c(J,R);ee&&F.push(u(J)+(n?": ":":")+ee)});return O=F.length===0?"{}":n?`{
11
+ `+n+F.join(`,
12
+ `+n)+`
13
+ `+x+"}":"{"+F.join(",")+"}",n=x,O}}typeof aA.stringify!="function"&&(aA.stringify=function(d,p,_){var b;if(n="",i="",typeof _=="number")for(b=0;b<_;b+=1)i+=" ";else typeof _=="string"&&(i=_);if(o=p,p&&typeof p!="function"&&(typeof p!="object"||typeof p.length!="number"))throw new Error("JSON.stringify");return c("",{"":d})})})()});var fA=be((hQ,lA)=>{"use strict";var Ff=null,RU=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,UU=/(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/,LU=function(t){"use strict";var e={strict:!1,storeAsString:!1,alwaysParseAsBig:!1,useNativeBigInt:!1,protoAction:"error",constructorAction:"error"};if(t!=null){if(t.strict===!0&&(e.strict=!0),t.storeAsString===!0&&(e.storeAsString=!0),e.alwaysParseAsBig=t.alwaysParseAsBig===!0?t.alwaysParseAsBig:!1,e.useNativeBigInt=t.useNativeBigInt===!0?t.useNativeBigInt:!1,typeof t.constructorAction<"u")if(t.constructorAction==="error"||t.constructorAction==="ignore"||t.constructorAction==="preserve")e.constructorAction=t.constructorAction;else throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${t.constructorAction}`);if(typeof t.protoAction<"u")if(t.protoAction==="error"||t.protoAction==="ignore"||t.protoAction==="preserve")e.protoAction=t.protoAction;else throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${t.protoAction}`)}var r,n,i={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
14
+ `,r:"\r",t:" "},s,o=function(x){throw{name:"SyntaxError",message:x,at:r,text:s}},u=function(x){return x&&x!==n&&o("Expected '"+x+"' instead of '"+n+"'"),n=s.charAt(r),r+=1,n},c=function(){var x,F="";for(n==="-"&&(F="-",u("-"));n>="0"&&n<="9";)F+=n,u();if(n===".")for(F+=".";u()&&n>="0"&&n<="9";)F+=n;if(n==="e"||n==="E")for(F+=n,u(),(n==="-"||n==="+")&&(F+=n,u());n>="0"&&n<="9";)F+=n,u();if(x=+F,!isFinite(x))o("Bad number");else return Ff==null&&(Ff=wg()),F.length>15?e.storeAsString?F:e.useNativeBigInt?BigInt(F):new Ff(F):e.alwaysParseAsBig?e.useNativeBigInt?BigInt(x):new Ff(x):x},d=function(){var x,F,R="",H;if(n==='"')for(var J=r;u();){if(n==='"')return r-1>J&&(R+=s.substring(J,r-1)),u(),R;if(n==="\\"){if(r-1>J&&(R+=s.substring(J,r-1)),u(),n==="u"){for(H=0,F=0;F<4&&(x=parseInt(u(),16),!!isFinite(x));F+=1)H=H*16+x;R+=String.fromCharCode(H)}else if(typeof i[n]=="string")R+=i[n];else break;J=r}}o("Bad string")},p=function(){for(;n&&n<=" ";)u()},_=function(){switch(n){case"t":return u("t"),u("r"),u("u"),u("e"),!0;case"f":return u("f"),u("a"),u("l"),u("s"),u("e"),!1;case"n":return u("n"),u("u"),u("l"),u("l"),null}o("Unexpected '"+n+"'")},b,O=function(){var x=[];if(n==="["){if(u("["),p(),n==="]")return u("]"),x;for(;n;){if(x.push(b()),p(),n==="]")return u("]"),x;u(","),p()}}o("Bad array")},T=function(){var x,F=Object.create(null);if(n==="{"){if(u("{"),p(),n==="}")return u("}"),F;for(;n;){if(x=d(),p(),u(":"),e.strict===!0&&Object.hasOwnProperty.call(F,x)&&o('Duplicate key "'+x+'"'),RU.test(x)===!0?e.protoAction==="error"?o("Object contains forbidden prototype property"):e.protoAction==="ignore"?b():F[x]=b():UU.test(x)===!0?e.constructorAction==="error"?o("Object contains forbidden constructor property"):e.constructorAction==="ignore"?b():F[x]=b():F[x]=b(),p(),n==="}")return u("}"),F;u(","),p()}}o("Bad object")};return b=function(){switch(p(),n){case"{":return T();case"[":return O();case'"':return d();case"-":return c();default:return n>="0"&&n<="9"?c():_()}},function(x,F){var R;return s=x+"",r=0,n=" ",R=b(),p(),n&&o("Syntax error"),typeof F=="function"?(function H(J,ee){var ae,te,he=J[ee];return he&&typeof he=="object"&&Object.keys(he).forEach(function(A){te=H(he,A),te!==void 0?he[A]=te:delete he[A]}),F.call(J,ee,he)})({"":R},""):R}};lA.exports=LU});var pA=be((pQ,qf)=>{"use strict";var dA=cA().stringify,hA=fA();qf.exports=function(t){return{parse:hA(t),stringify:dA}};qf.exports.parse=hA();qf.exports.stringify=dA});var Vf=be((mQ,gA)=>{"use strict";var kg=Object.defineProperty,$U=Object.getOwnPropertyDescriptor,FU=Object.getOwnPropertyNames,qU=Object.prototype.hasOwnProperty,VU=(t,e)=>{for(var r in e)kg(t,r,{get:e[r],enumerable:!0})},zU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of FU(e))!qU.call(t,i)&&i!==r&&kg(t,i,{get:()=>e[i],enumerable:!(n=$U(e,i))||n.enumerable});return t},GU=t=>zU(kg({},"__esModule",{value:!0}),t),mA={};VU(mA,{JsonRpcError:()=>Mg,SuiHTTPStatusError:()=>Sg,SuiHTTPTransportError:()=>Sc});gA.exports=GU(mA);var HU={"-32700":"ParseError","-32701":"OversizedRequest","-32702":"OversizedResponse","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError","-32604":"ServerBusy","-32000":"CallExecutionFailed","-32001":"UnknownError","-32003":"SubscriptionClosed","-32004":"SubscriptionClosedWithError","-32005":"BatchesNotSupported","-32006":"TooManySubscriptions","-32050":"TransientError","-32002":"TransactionExecutionClientError"},Sc=class extends Error{},Mg=class extends Sc{constructor(e,r){super(e),this.code=r,this.type=HU[r]??"ServerError"}},Sg=class extends Sc{constructor(e,r,n){super(e),this.status=r,this.statusText=n}}});var kA=be((gQ,SA)=>{"use strict";var Ag=Object.defineProperty,WU=Object.getOwnPropertyDescriptor,KU=Object.getOwnPropertyNames,XU=Object.prototype.hasOwnProperty,yA=t=>{throw TypeError(t)},JU=(t,e)=>{for(var r in e)Ag(t,r,{get:e[r],enumerable:!0})},ZU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of KU(e))!XU.call(t,i)&&i!==r&&Ag(t,i,{get:()=>e[i],enumerable:!(n=WU(e,i))||n.enumerable});return t},YU=t=>ZU(Ag({},"__esModule",{value:!0}),t),Ig=(t,e,r)=>e.has(t)||yA("Cannot "+r),tr=(t,e,r)=>(Ig(t,e,"read from private field"),r?r.call(t):e.get(t)),ua=(t,e,r)=>e.has(t)?yA("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Xa=(t,e,r,n)=>(Ig(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_A=(t,e,r)=>(Ig(t,e,"access private method"),r),QU=(t,e,r,n)=>({set _(i){Xa(t,e,i,r)},get _(){return tr(t,e,n)}}),vA={};JU(vA,{DEFAULT_CLIENT_OPTIONS:()=>MA,WebsocketClient:()=>Og});SA.exports=YU(vA);var eL=Vf(),yo,kc,Os,ca,Oc,la,zf,bA,wA;function tL(t){let e=new URL(t);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var MA={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Og=class{constructor(e,r={}){if(ua(this,zf),ua(this,yo,0),ua(this,kc,0),ua(this,Os,null),ua(this,ca,null),ua(this,Oc,new Set),ua(this,la,new Map),this.endpoint=e,this.options={...MA,...r},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=tL(this.endpoint))}async makeRequest(e,r,n){let i=await _A(this,zf,bA).call(this);return new Promise((s,o)=>{Xa(this,yo,tr(this,yo)+1),tr(this,la).set(tr(this,yo),{resolve:s,reject:o,timeout:setTimeout(()=>{tr(this,la).delete(tr(this,yo)),o(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n?.addEventListener("abort",()=>{tr(this,la).delete(tr(this,yo)),o(n.reason)}),i.send(JSON.stringify({jsonrpc:"2.0",id:tr(this,yo),method:e,params:r}))}).then(({error:s,result:o})=>{if(s)throw new eL.JsonRpcError(s.message,s.code);return o})}async subscribe(e){let r=new Eg(e);return tr(this,Oc).add(r),await r.subscribe(this),()=>r.unsubscribe(this)}};yo=new WeakMap;kc=new WeakMap;Os=new WeakMap;ca=new WeakMap;Oc=new WeakMap;la=new WeakMap;zf=new WeakSet;bA=function(){return tr(this,ca)?tr(this,ca):(Xa(this,ca,new Promise(t=>{tr(this,Os)?.close(),Xa(this,Os,new this.options.WebSocketConstructor(this.endpoint)),tr(this,Os).addEventListener("open",()=>{Xa(this,kc,0),t(tr(this,Os))}),tr(this,Os).addEventListener("close",()=>{QU(this,kc)._++,tr(this,kc)<=this.options.maxReconnects&&setTimeout(()=>{_A(this,zf,wA).call(this)},this.options.reconnectTimeout)}),tr(this,Os).addEventListener("message",({data:e})=>{let r;try{r=JSON.parse(e)}catch(n){console.error(new Error(`Failed to parse RPC message: ${e}`,{cause:n}));return}if("id"in r&&r.id!=null&&tr(this,la).has(r.id)){let{resolve:n,timeout:i}=tr(this,la).get(r.id);clearTimeout(i),n(r)}else if("params"in r){let{params:n}=r;tr(this,Oc).forEach(i=>{i.subscriptionId===n.subscription&&n.subscription===i.subscriptionId&&i.onMessage(n.result)})}})})),tr(this,ca))};wA=async function(){return tr(this,Os)?.close(),Xa(this,ca,null),Promise.allSettled([...tr(this,Oc)].map(t=>t.subscribe(this)))};var Eg=class{constructor(e){this.subscriptionId=null,this.subscribed=!1,this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:r}=this;return this.subscribed=!1,r==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[r]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let r=await e.makeRequest(this.input.method,this.input.params,this.input.signal);this.subscribed&&(this.subscriptionId=r)}}});var Ng=be((yQ,xA)=>{"use strict";var Cg=Object.defineProperty,rL=Object.getOwnPropertyDescriptor,nL=Object.getOwnPropertyNames,iL=Object.prototype.hasOwnProperty,AA=t=>{throw TypeError(t)},sL=(t,e)=>{for(var r in e)Cg(t,r,{get:e[r],enumerable:!0})},oL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nL(e))!iL.call(t,i)&&i!==r&&Cg(t,i,{get:()=>e[i],enumerable:!(n=rL(e,i))||n.enumerable});return t},aL=t=>oL(Cg({},"__esModule",{value:!0}),t),jg=(t,e,r)=>e.has(t)||AA("Cannot "+r),qn=(t,e,r)=>(jg(t,e,"read from private field"),r?r.call(t):e.get(t)),Gf=(t,e,r)=>e.has(t)?AA("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Tg=(t,e,r,n)=>(jg(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),uL=(t,e,r)=>(jg(t,e,"access private method"),r),IA={};sL(IA,{SuiHTTPTransport:()=>Pg});xA.exports=aL(IA);var OA=fm(),EA=Vf(),cL=kA(),Ec,Si,Ac,xg,TA,Pg=class{constructor(e){Gf(this,xg),Gf(this,Ec,0),Gf(this,Si),Gf(this,Ac),Tg(this,Si,e)}fetch(e,r){let n=qn(this,Si).fetch??fetch;if(!n)throw new Error("The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.");return n(e,r)}async request(e){Tg(this,Ec,qn(this,Ec)+1);let r=await this.fetch(qn(this,Si).rpc?.url??qn(this,Si).url,{method:"POST",signal:e.signal,headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":OA.PACKAGE_VERSION,"Client-Target-Api-Version":OA.TARGETED_RPC_VERSION,"Client-Request-Method":e.method,...qn(this,Si).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:qn(this,Ec),method:e.method,params:e.params})});if(!r.ok)throw new EA.SuiHTTPStatusError(`Unexpected status code: ${r.status}`,r.status,r.statusText);let n=await r.json();if("error"in n&&n.error!=null)throw new EA.JsonRpcError(n.error.message,n.error.code);return n.result}async subscribe(e){let r=await uL(this,xg,TA).call(this).subscribe(e);return e.signal&&(e.signal.throwIfAborted(),e.signal.addEventListener("abort",()=>{r()})),async()=>!!await r()}};Ec=new WeakMap;Si=new WeakMap;Ac=new WeakMap;xg=new WeakSet;TA=function(){if(!qn(this,Ac)){let t=qn(this,Si).WebSocketConstructor??WebSocket;if(!t)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");Tg(this,Ac,new cL.WebsocketClient(qn(this,Si).websocket?.url??qn(this,Si).url,{WebSocketConstructor:t,...qn(this,Si).websocket}))}return qn(this,Ac)}});var jA=be((_Q,CA)=>{"use strict";var Dg=Object.defineProperty,lL=Object.getOwnPropertyDescriptor,fL=Object.getOwnPropertyNames,dL=Object.prototype.hasOwnProperty,hL=(t,e)=>{for(var r in e)Dg(t,r,{get:e[r],enumerable:!0})},pL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fL(e))!dL.call(t,i)&&i!==r&&Dg(t,i,{get:()=>e[i],enumerable:!(n=lL(e,i))||n.enumerable});return t},mL=t=>pL(Dg({},"__esModule",{value:!0}),t),PA={};hL(PA,{getFullnodeUrl:()=>gL});CA.exports=mL(PA);function gL(t){switch(t){case"mainnet":return"https://fullnode.mainnet.sui.io:443";case"testnet":return"https://fullnode.testnet.sui.io:443";case"devnet":return"https://fullnode.devnet.sui.io:443";case"localnet":return"http://127.0.0.1:9000";default:throw new Error(`Unknown network: ${t}`)}}});var BA=be((vQ,DA)=>{"use strict";var NA=Object.defineProperty,yL=Object.getOwnPropertyDescriptor,_L=Object.getOwnPropertyNames,vL=Object.prototype.hasOwnProperty,bL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _L(e))!vL.call(t,i)&&i!==r&&NA(t,i,{get:()=>e[i],enumerable:!(n=yL(e,i))||n.enumerable});return t},wL=t=>bL(NA({},"__esModule",{value:!0}),t),ML={};DA.exports=wL(ML)});var LA=be((bQ,UA)=>{"use strict";var RA=Object.defineProperty,SL=Object.getOwnPropertyDescriptor,kL=Object.getOwnPropertyNames,OL=Object.prototype.hasOwnProperty,EL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of kL(e))!OL.call(t,i)&&i!==r&&RA(t,i,{get:()=>e[i],enumerable:!(n=SL(e,i))||n.enumerable});return t},AL=t=>EL(RA({},"__esModule",{value:!0}),t),IL={};UA.exports=AL(IL)});var qA=be((wQ,FA)=>{"use strict";var $A=Object.defineProperty,TL=Object.getOwnPropertyDescriptor,xL=Object.getOwnPropertyNames,PL=Object.prototype.hasOwnProperty,CL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xL(e))!PL.call(t,i)&&i!==r&&$A(t,i,{get:()=>e[i],enumerable:!(n=TL(e,i))||n.enumerable});return t},jL=t=>CL($A({},"__esModule",{value:!0}),t),NL={};FA.exports=jL(NL)});var GA=be((MQ,zA)=>{"use strict";var VA=Object.defineProperty,DL=Object.getOwnPropertyDescriptor,BL=Object.getOwnPropertyNames,RL=Object.prototype.hasOwnProperty,UL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of BL(e))!RL.call(t,i)&&i!==r&&VA(t,i,{get:()=>e[i],enumerable:!(n=DL(e,i))||n.enumerable});return t},LL=t=>UL(VA({},"__esModule",{value:!0}),t),$L={};zA.exports=LL($L)});var KA=be((SQ,WA)=>{"use strict";var HA=Object.defineProperty,FL=Object.getOwnPropertyDescriptor,qL=Object.getOwnPropertyNames,VL=Object.prototype.hasOwnProperty,zL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of qL(e))!VL.call(t,i)&&i!==r&&HA(t,i,{get:()=>e[i],enumerable:!(n=FL(e,i))||n.enumerable});return t},GL=t=>zL(HA({},"__esModule",{value:!0}),t),HL={};WA.exports=GL(HL)});var ZA=be((kQ,JA)=>{"use strict";var XA=Object.defineProperty,WL=Object.getOwnPropertyDescriptor,KL=Object.getOwnPropertyNames,XL=Object.prototype.hasOwnProperty,JL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of KL(e))!XL.call(t,i)&&i!==r&&XA(t,i,{get:()=>e[i],enumerable:!(n=WL(e,i))||n.enumerable});return t},ZL=t=>JL(XA({},"__esModule",{value:!0}),t),YL={};JA.exports=ZL(YL)});var QA=be((OQ,_o)=>{"use strict";var YA=Object.defineProperty,QL=Object.getOwnPropertyDescriptor,e$=Object.getOwnPropertyNames,t$=Object.prototype.hasOwnProperty,Bg=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of e$(e))!t$.call(t,i)&&i!==r&&YA(t,i,{get:()=>e[i],enumerable:!(n=QL(e,i))||n.enumerable});return t},Ja=(t,e,r)=>(Bg(t,e,"default"),r&&Bg(r,e,"default")),r$=t=>Bg(YA({},"__esModule",{value:!0}),t),fa={};_o.exports=r$(fa);Ja(fa,BA(),_o.exports);Ja(fa,LA(),_o.exports);Ja(fa,qA(),_o.exports);Ja(fa,GA(),_o.exports);Ja(fa,KA(),_o.exports);Ja(fa,ZA(),_o.exports)});var Lg=be((EQ,t6)=>{"use strict";var Ug=Object.defineProperty,n$=Object.getOwnPropertyDescriptor,i$=Object.getOwnPropertyNames,s$=Object.prototype.hasOwnProperty,o$=(t,e)=>{for(var r in e)Ug(t,r,{get:e[r],enumerable:!0})},a$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of i$(e))!s$.call(t,i)&&i!==r&&Ug(t,i,{get:()=>e[i],enumerable:!(n=n$(e,i))||n.enumerable});return t},u$=t=>a$(Ug({},"__esModule",{value:!0}),t),e6={};o$(e6,{Experimental_BaseClient:()=>Rg});t6.exports=u$(e6);var c$=cm(),Rg=class{constructor({network:e,base:r}){this.cache=new c$.ClientCache,this.network=e,this.base=r??this}$extend(...e){return Object.create(this,Object.fromEntries(e.map(r=>{if("experimental_asClientExtension"in r){let{name:n,register:i}=r.experimental_asClientExtension();return[n,{value:i(this)}]}return[r.name,{value:r.register(this)}]})))}}});var i6=be((AQ,n6)=>{"use strict";var Fg=Object.defineProperty,l$=Object.getOwnPropertyDescriptor,f$=Object.getOwnPropertyNames,d$=Object.prototype.hasOwnProperty,h$=(t,e)=>{for(var r in e)Fg(t,r,{get:e[r],enumerable:!0})},p$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of f$(e))!d$.call(t,i)&&i!==r&&Fg(t,i,{get:()=>e[i],enumerable:!(n=l$(e,i))||n.enumerable});return t},m$=t=>p$(Fg({},"__esModule",{value:!0}),t),r6={};h$(r6,{Experimental_CoreClient:()=>$g});n6.exports=m$(r6);var g$=Jl(),y$=P0(),Hf=Nr(),_$=Lg(),v$=fc(),$g=class extends _$.Experimental_BaseClient{constructor(e){super(e),this.core=this,this.mvr=new v$.MvrClient({cache:this.base.cache.scope("core"),url:e.mvr?.url,pageSize:e.mvr?.pageSize,overrides:e.mvr?.overrides})}async getObject(e){let{objectId:r}=e,{objects:[n]}=await this.getObjects({objectIds:[r],signal:e.signal});if(n instanceof Error)throw n;return{object:n}}async getDynamicField(e){let r=(0,y$.deriveDynamicFieldID)(e.parentId,g$.TypeTagSerializer.parseFromStr(e.name.type),e.name.bcs),{objects:[n]}=await this.getObjects({objectIds:[r],signal:e.signal});if(n instanceof Error)throw n;let i=(0,Hf.parseStructTag)(n.type),s=await n.content;return{dynamicField:{id:n.id,digest:n.digest,version:n.version,type:n.type,name:{type:typeof i.typeParams[0]=="string"?i.typeParams[0]:(0,Hf.normalizeStructTag)(i.typeParams[0]),bcs:e.name.bcs},value:{type:typeof i.typeParams[1]=="string"?i.typeParams[1]:(0,Hf.normalizeStructTag)(i.typeParams[1]),bcs:s.slice(Hf.SUI_ADDRESS_LENGTH+e.name.bcs.length)}}}}async waitForTransaction({signal:e,timeout:r=60*1e3,...n}){let i=e?AbortSignal.any([AbortSignal.timeout(r),e]):AbortSignal.timeout(r),s=new Promise((o,u)=>{i.addEventListener("abort",()=>u(i.reason))});for(s.catch(()=>{});;){i.throwIfAborted();try{return await this.getTransaction({...n,signal:i})}catch{await Promise.race([new Promise(u=>setTimeout(u,2e3)),s])}}}}});var a6=be((IQ,o6)=>{"use strict";var Vg=Object.defineProperty,b$=Object.getOwnPropertyDescriptor,w$=Object.getOwnPropertyNames,M$=Object.prototype.hasOwnProperty,S$=(t,e)=>{for(var r in e)Vg(t,r,{get:e[r],enumerable:!0})},k$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of w$(e))!M$.call(t,i)&&i!==r&&Vg(t,i,{get:()=>e[i],enumerable:!(n=b$(e,i))||n.enumerable});return t},O$=t=>k$(Vg({},"__esModule",{value:!0}),t),s6={};S$(s6,{ObjectError:()=>qg,SuiClientError:()=>Wf});o6.exports=O$(s6);var Wf=class extends Error{},qg=class t extends Wf{constructor(e,r){super(r),this.code=e}static fromResponse(e,r){switch(e.code){case"notExists":return new t(e.code,`Object ${e.object_id} does not exist`);case"dynamicFieldNotFound":return new t(e.code,`Dynamic field not found for object ${e.parent_object_id}`);case"deleted":return new t(e.code,`Object ${e.object_id} has been deleted`);case"displayError":return new t(e.code,`Display error: ${e.error}`);case"unknown":default:return new t(e.code,`Unknown error while loading object${r?` ${r}`:""}`)}}}});var l6=be((TQ,c6)=>{"use strict";var zg=Object.defineProperty,E$=Object.getOwnPropertyDescriptor,A$=Object.getOwnPropertyNames,I$=Object.prototype.hasOwnProperty,T$=(t,e)=>{for(var r in e)zg(t,r,{get:e[r],enumerable:!0})},x$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of A$(e))!I$.call(t,i)&&i!==r&&zg(t,i,{get:()=>e[i],enumerable:!(n=E$(e,i))||n.enumerable});return t},P$=t=>x$(zg({},"__esModule",{value:!0}),t),u6={};T$(u6,{parseTransactionBcs:()=>N$,parseTransactionEffectsBcs:()=>D$});c6.exports=P$(u6);var C$=Rn(),j$=qa();function N$(t){return{...j$.TransactionDataBuilder.fromBytes(t).snapshot(),bcs:t}}function D$(t){let e=C$.bcs.TransactionEffects.parse(t);switch(e.$kind){case"V1":return B$({bytes:t,effects:e.V1});case"V2":return R$({bytes:t,effects:e.V2});default:throw new Error(`Unknown transaction effects version: ${e.$kind}`)}}function B$(t){throw new Error("V1 effects are not supported yet")}function R$({bytes:t,effects:e}){let r=e.changedObjects.map(([n,i])=>({id:n,inputState:i.inputState.$kind==="Exist"?"Exists":"DoesNotExist",inputVersion:i.inputState.Exist?.[0][0]??null,inputDigest:i.inputState.Exist?.[0][1]??null,inputOwner:i.inputState.Exist?.[1]??null,outputState:i.outputState.$kind==="NotExist"?"DoesNotExist":i.outputState.$kind,outputVersion:i.outputState.$kind==="PackageWrite"?i.outputState.PackageWrite?.[0]:i.outputState.ObjectWrite?e.lamportVersion:null,outputDigest:i.outputState.$kind==="PackageWrite"?i.outputState.PackageWrite?.[1]:i.outputState.ObjectWrite?.[0]??null,outputOwner:i.outputState.ObjectWrite?i.outputState.ObjectWrite[1]:null,idOperation:i.idOperation.$kind}));return{bcs:t,digest:e.transactionDigest,version:2,status:e.status.$kind==="Success"?{success:!0,error:null}:{success:!1,error:e.status.Failed.error.$kind},gasUsed:e.gasUsed,transactionDigest:e.transactionDigest,gasObject:e.gasObjectIndex===null?null:r[e.gasObjectIndex]??null,eventsDigest:e.eventsDigest,dependencies:e.dependencies,lamportVersion:e.lamportVersion,changedObjects:r,unchangedSharedObjects:e.unchangedSharedObjects.map(([n,i])=>({kind:i.$kind,objectId:n,version:i.$kind==="ReadOnlyRoot"?i.ReadOnlyRoot[0]:i[i.$kind],digest:i.$kind==="ReadOnlyRoot"?i.ReadOnlyRoot[1]:null})),auxiliaryDataDigest:e.auxDataDigest}}});var v6=be((xQ,_6)=>{"use strict";var Hg=Object.defineProperty,U$=Object.getOwnPropertyDescriptor,L$=Object.getOwnPropertyNames,$$=Object.prototype.hasOwnProperty,p6=t=>{throw TypeError(t)},F$=(t,e)=>{for(var r in e)Hg(t,r,{get:e[r],enumerable:!0})},q$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L$(e))!$$.call(t,i)&&i!==r&&Hg(t,i,{get:()=>e[i],enumerable:!(n=U$(e,i))||n.enumerable});return t},V$=t=>q$(Hg({},"__esModule",{value:!0}),t),m6=(t,e,r)=>e.has(t)||p6("Cannot "+r),Sn=(t,e,r)=>(m6(t,e,"read from private field"),r?r.call(t):e.get(t)),z$=(t,e,r)=>e.has(t)?p6("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),G$=(t,e,r,n)=>(m6(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),g6={};F$(g6,{JSONRpcTransport:()=>Gg});_6.exports=V$(g6);var Wg=dr(),Ya=Rn(),H$=na(),W$=i6(),f6=a6(),y6=l6(),K$=Em(),X$=qa(),J$=to(),Xr,Gg=class extends W$.Experimental_CoreClient{constructor({jsonRpcClient:e,mvr:r}){super({network:e.network,base:e,mvr:r}),z$(this,Xr),G$(this,Xr,e)}async getObjects(e){let r=(0,J$.chunk)(e.objectIds,50),n=[];for(let i of r){let s=await Sn(this,Xr).multiGetObjects({ids:i,options:{showOwner:!0,showType:!0,showBcs:!0},signal:e.signal});for(let[o,u]of s.entries())u.error?n.push(f6.ObjectError.fromResponse(u.error,i[o])):n.push(d6(u.data))}return{objects:n}}async getOwnedObjects(e){let r=await Sn(this,Xr).getOwnedObjects({owner:e.address,limit:e.limit,cursor:e.cursor,options:{showOwner:!0,showType:!0,showBcs:!0},filter:e.type?{StructType:e.type}:null,signal:e.signal});return{objects:r.data.map(n=>{if(n.error)throw f6.ObjectError.fromResponse(n.error);return d6(n.data)}),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getCoins(e){let r=await Sn(this,Xr).getCoins({owner:e.address,coinType:e.coinType,limit:e.limit,cursor:e.cursor,signal:e.signal});return{objects:r.data.map(n=>({id:n.coinObjectId,version:n.version,digest:n.digest,balance:n.balance,type:`0x2::coin::Coin<${n.coinType}>`,content:Promise.resolve(Q$.serialize({id:n.coinObjectId,balance:{value:n.balance}}).toBytes()),owner:{$kind:"ObjectOwner",ObjectOwner:e.address}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getBalance(e){let r=await Sn(this,Xr).getBalance({owner:e.address,coinType:e.coinType,signal:e.signal});return{balance:{coinType:r.coinType,balance:r.totalBalance}}}async getAllBalances(e){return{balances:(await Sn(this,Xr).getAllBalances({owner:e.address,signal:e.signal})).map(n=>({coinType:n.coinType,balance:n.totalBalance})),hasNextPage:!1,cursor:null}}async getTransaction(e){let r=await Sn(this,Xr).getTransactionBlock({digest:e.digest,options:{showRawInput:!0,showObjectChanges:!0,showRawEffects:!0,showEvents:!0,showEffects:!0},signal:e.signal});return{transaction:h6(r)}}async executeTransaction(e){let r=await Sn(this,Xr).executeTransactionBlock({transactionBlock:e.transaction,signature:e.signatures,options:{showRawEffects:!0,showEvents:!0,showObjectChanges:!0,showRawInput:!0,showEffects:!0},signal:e.signal});return{transaction:h6(r)}}async dryRunTransaction(e){let r=H$.Transaction.from(e.transaction),n=await Sn(this,Xr).dryRunTransactionBlock({transactionBlock:e.transaction,signal:e.signal}),{effects:i,objectTypes:s}=Z$({effects:n.effects,objectChanges:n.objectChanges});return{transaction:{digest:await r.getDigest(),epoch:null,effects:i,objectTypes:Promise.resolve(s),signatures:[],transaction:(0,y6.parseTransactionBcs)(e.transaction)}}}async getReferenceGasPrice(e){let r=await Sn(this,Xr).getReferenceGasPrice({signal:e?.signal});return{referenceGasPrice:String(r)}}async getDynamicFields(e){let r=await Sn(this,Xr).getDynamicFields({parentId:e.parentId,limit:e.limit,cursor:e.cursor});return{dynamicFields:r.data.map(n=>({id:n.objectId,type:n.objectType,name:{type:n.name.type,bcs:(0,Wg.fromBase64)(n.bcsName)}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor}}async verifyZkLoginSignature(e){let r=await Sn(this,Xr).verifyZkLoginSignature({bytes:e.bytes,signature:e.signature,intentScope:e.intentScope,author:e.author});return{success:r.success,errors:r.errors}}resolveNameServiceNames(e){return Sn(this,Xr).resolveNameServiceNames(e)}resolveTransactionPlugin(){return(0,K$.suiClientResolveTransactionPlugin)(Sn(this,Xr))}};Xr=new WeakMap;function d6(t){return{id:t.objectId,version:t.version,digest:t.digest,type:t.type,content:Promise.resolve(t.bcs?.dataType==="moveObject"?(0,Wg.fromBase64)(t.bcs.bcsBytes):new Uint8Array),owner:Za(t.owner)}}function Za(t){if(t==="Immutable")return{$kind:"Immutable",Immutable:!0};if("ConsensusV2"in t)return{$kind:"ConsensusV2",ConsensusV2:{authenticator:{$kind:"SingleOwner",SingleOwner:t.ConsensusV2.authenticator.SingleOwner},startVersion:t.ConsensusV2.start_version}};if("AddressOwner"in t)return{$kind:"AddressOwner",AddressOwner:t.AddressOwner};if("ObjectOwner"in t)return{$kind:"ObjectOwner",ObjectOwner:t.ObjectOwner};if("Shared"in t)return{$kind:"Shared",Shared:{initialSharedVersion:t.Shared.initial_shared_version}};throw new Error(`Unknown owner type: ${JSON.stringify(t)}`)}function h6(t){let e=Ya.bcs.SenderSignedData.parse((0,Wg.fromBase64)(t.rawTransaction))[0],r={};t.objectChanges?.forEach(s=>{s.type!=="published"&&(r[s.objectId]=s.objectType)});let n=Ya.bcs.TransactionData.serialize(e.intentMessage.value).toBytes(),i=X$.TransactionDataBuilder.restore({version:2,sender:e.intentMessage.value.V1.sender,expiration:e.intentMessage.value.V1.expiration,gasData:e.intentMessage.value.V1.gasData,inputs:e.intentMessage.value.V1.kind.ProgrammableTransaction.inputs,commands:e.intentMessage.value.V1.kind.ProgrammableTransaction.commands});return{digest:t.digest,epoch:t.effects?.executedEpoch??null,effects:(0,y6.parseTransactionEffectsBcs)(new Uint8Array(t.rawEffects)),objectTypes:Promise.resolve(r),transaction:{...i,bcs:n},signatures:e.txSignatures}}function Z$({bytes:t,effects:e,objectChanges:r}){let n=[],i=[],s={};return r?.forEach(o=>{switch(o.type){case"published":n.push({id:o.packageId,inputState:"DoesNotExist",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"PackageWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:null,idOperation:"Created"});break;case"transferred":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:o.digest,inputOwner:{$kind:"AddressOwner",AddressOwner:o.sender},outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:Za(o.recipient),idOperation:"None"}),s[o.objectId]=o.objectType;break;case"mutated":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.previousVersion,inputDigest:null,inputOwner:Za(o.owner),outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:Za(o.owner),idOperation:"None"}),s[o.objectId]=o.objectType;break;case"deleted":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:e.deleted?.find(u=>u.objectId===o.objectId)?.digest??null,inputOwner:null,outputState:"DoesNotExist",outputVersion:null,outputDigest:null,outputOwner:null,idOperation:"Deleted"}),s[o.objectId]=o.objectType;break;case"wrapped":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:null,inputOwner:{$kind:"AddressOwner",AddressOwner:o.sender},outputState:"ObjectWrite",outputVersion:o.version,outputDigest:e.wrapped?.find(u=>u.objectId===o.objectId)?.digest??null,outputOwner:{$kind:"ObjectOwner",ObjectOwner:o.sender},idOperation:"None"}),s[o.objectId]=o.objectType;break;case"created":n.push({id:o.objectId,inputState:"DoesNotExist",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:Za(o.owner),idOperation:"Created"}),s[o.objectId]=o.objectType;break}}),{objectTypes:s,effects:{bcs:t??null,digest:e.transactionDigest,version:2,status:e.status.status==="success"?{success:!0,error:null}:{success:!1,error:e.status.error},gasUsed:e.gasUsed,transactionDigest:e.transactionDigest,gasObject:{id:e.gasObject?.reference.objectId,inputState:"Exists",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"ObjectWrite",outputVersion:e.gasObject.reference.version,outputDigest:e.gasObject.reference.digest,outputOwner:Za(e.gasObject.owner),idOperation:"None"},eventsDigest:e.eventsDigest??null,dependencies:e.dependencies??[],lamportVersion:e.gasObject.reference.version,changedObjects:n,unchangedSharedObjects:i,auxiliaryDataDigest:null}}}var Y$=Ya.bcs.struct("Balance",{value:Ya.bcs.u64()}),Q$=Ya.bcs.struct("Coin",{id:Ya.bcs.Address,balance:Y$})});var S6=be((PQ,M6)=>{"use strict";var Xg=Object.defineProperty,eF=Object.getOwnPropertyDescriptor,tF=Object.getOwnPropertyNames,rF=Object.prototype.hasOwnProperty,nF=(t,e)=>{for(var r in e)Xg(t,r,{get:e[r],enumerable:!0})},iF=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tF(e))!rF.call(t,i)&&i!==r&&Xg(t,i,{get:()=>e[i],enumerable:!(n=eF(e,i))||n.enumerable});return t},sF=t=>iF(Xg({},"__esModule",{value:!0}),t),b6={};nF(b6,{SuiClient:()=>Kg,isSuiClient:()=>fF});M6.exports=sF(b6);var Qa=dr(),oF=Lg(),aF=v6(),uF=na(),ar=Nr(),cF=Xl(),lF=Ng(),Es=Xu(),eu=fc(),w6=Symbol.for("@mysten/SuiClient");function fF(t){return typeof t=="object"&&t!==null&&t[w6]===!0}var Kg=class extends oF.Experimental_BaseClient{constructor(e){super({network:e.network??"unknown"}),this.jsonRpc=this,this.transport=e.transport??new lF.SuiHTTPTransport({url:e.url}),this.core=new aF.JSONRpcTransport({jsonRpcClient:this,mvr:e.mvr})}get[w6](){return!0}async getRpcApiVersion({signal:e}={}){return(await this.transport.request({method:"rpc.discover",params:[],signal:e})).info.version}async getCoins({coinType:e,owner:r,cursor:n,limit:i,signal:s}){if(!r||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(r)))throw new Error("Invalid Sui address");return e&&(0,eu.hasMvrName)(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getCoins",params:[r,e,n,i],signal:s})}async getAllCoins(e){if(!e.owner||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllCoins",params:[e.owner,e.cursor,e.limit],signal:e.signal})}async getBalance({owner:e,coinType:r,signal:n}){if(!e||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(e)))throw new Error("Invalid Sui address");return r&&(0,eu.hasMvrName)(r)&&(r=(await this.core.mvr.resolveType({type:r})).type),await this.transport.request({method:"suix_getBalance",params:[e,r],signal:n})}async getAllBalances(e){if(!e.owner||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllBalances",params:[e.owner],signal:e.signal})}async getCoinMetadata({coinType:e,signal:r}){return e&&(0,eu.hasMvrName)(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getCoinMetadata",params:[e],signal:r})}async getTotalSupply({coinType:e,signal:r}){return e&&(0,eu.hasMvrName)(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getTotalSupply",params:[e],signal:r})}async call(e,r,{signal:n}={}){return await this.transport.request({method:e,params:r,signal:n})}async getMoveFunctionArgTypes({package:e,module:r,function:n,signal:i}){return e&&(0,Es.isValidNamedPackage)(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getMoveFunctionArgTypes",params:[e,r,n],signal:i})}async getNormalizedMoveModulesByPackage({package:e,signal:r}){return e&&(0,Es.isValidNamedPackage)(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveModulesByPackage",params:[e],signal:r})}async getNormalizedMoveModule({package:e,module:r,signal:n}){return e&&(0,Es.isValidNamedPackage)(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveModule",params:[e,r],signal:n})}async getNormalizedMoveFunction({package:e,module:r,function:n,signal:i}){return e&&(0,Es.isValidNamedPackage)(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveFunction",params:[e,r,n],signal:i})}async getNormalizedMoveStruct({package:e,module:r,struct:n,signal:i}){return e&&(0,Es.isValidNamedPackage)(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveStruct",params:[e,r,n],signal:i})}async getOwnedObjects(e){if(!e.owner||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(e.owner)))throw new Error("Invalid Sui address");let r=e.filter?{...e.filter}:void 0;return r&&"MoveModule"in r&&(0,Es.isValidNamedPackage)(r.MoveModule.package)?r.MoveModule={module:r.MoveModule.module,package:(await this.core.mvr.resolvePackage({package:r.MoveModule.package})).package}:r&&"StructType"in r&&(0,eu.hasMvrName)(r.StructType)&&(r.StructType=(await this.core.mvr.resolveType({type:r.StructType})).type),await this.transport.request({method:"suix_getOwnedObjects",params:[e.owner,{filter:r,options:e.options},e.cursor,e.limit],signal:e.signal})}async getObject(e){if(!e.id||!(0,ar.isValidSuiObjectId)((0,ar.normalizeSuiObjectId)(e.id)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"sui_getObject",params:[e.id,e.options],signal:e.signal})}async tryGetPastObject(e){return await this.transport.request({method:"sui_tryGetPastObject",params:[e.id,e.version,e.options],signal:e.signal})}async multiGetObjects(e){if(e.ids.forEach(n=>{if(!n||!(0,ar.isValidSuiObjectId)((0,ar.normalizeSuiObjectId)(n)))throw new Error(`Invalid Sui Object id ${n}`)}),e.ids.length!==new Set(e.ids).size)throw new Error(`Duplicate object ids in batch call ${e.ids}`);return await this.transport.request({method:"sui_multiGetObjects",params:[e.ids,e.options],signal:e.signal})}async queryTransactionBlocks({filter:e,options:r,cursor:n,limit:i,order:s,signal:o}){return e&&"MoveFunction"in e&&(0,Es.isValidNamedPackage)(e.MoveFunction.package)&&(e={...e,MoveFunction:{package:(await this.core.mvr.resolvePackage({package:e.MoveFunction.package})).package}}),await this.transport.request({method:"suix_queryTransactionBlocks",params:[{filter:e,options:r},n,i,(s||"descending")==="descending"],signal:o})}async getTransactionBlock(e){if(!(0,ar.isValidTransactionDigest)(e.digest))throw new Error("Invalid Transaction digest");return await this.transport.request({method:"sui_getTransactionBlock",params:[e.digest,e.options],signal:e.signal})}async multiGetTransactionBlocks(e){if(e.digests.forEach(n=>{if(!(0,ar.isValidTransactionDigest)(n))throw new Error(`Invalid Transaction digest ${n}`)}),e.digests.length!==new Set(e.digests).size)throw new Error(`Duplicate digests in batch call ${e.digests}`);return await this.transport.request({method:"sui_multiGetTransactionBlocks",params:[e.digests,e.options],signal:e.signal})}async executeTransactionBlock({transactionBlock:e,signature:r,options:n,requestType:i,signal:s}){let o=await this.transport.request({method:"sui_executeTransactionBlock",params:[typeof e=="string"?e:(0,Qa.toBase64)(e),Array.isArray(r)?r:[r],n],signal:s});if(i==="WaitForLocalExecution")try{await this.waitForTransaction({digest:o.digest})}catch{}return o}async signAndExecuteTransaction({transaction:e,signer:r,...n}){let i;e instanceof Uint8Array?i=e:(e.setSenderIfNotSet(r.toSuiAddress()),i=await e.build({client:this}));let{signature:s,bytes:o}=await r.signTransaction(i);return this.executeTransactionBlock({transactionBlock:o,signature:s,...n})}async getTotalTransactionBlocks({signal:e}={}){let r=await this.transport.request({method:"sui_getTotalTransactionBlocks",params:[],signal:e});return BigInt(r)}async getReferenceGasPrice({signal:e}={}){let r=await this.transport.request({method:"suix_getReferenceGasPrice",params:[],signal:e});return BigInt(r)}async getStakes(e){if(!e.owner||!(0,ar.isValidSuiAddress)((0,ar.normalizeSuiAddress)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getStakes",params:[e.owner],signal:e.signal})}async getStakesByIds(e){return e.stakedSuiIds.forEach(r=>{if(!r||!(0,ar.isValidSuiObjectId)((0,ar.normalizeSuiObjectId)(r)))throw new Error(`Invalid Sui Stake id ${r}`)}),await this.transport.request({method:"suix_getStakesByIds",params:[e.stakedSuiIds],signal:e.signal})}async getLatestSuiSystemState({signal:e}={}){return await this.transport.request({method:"suix_getLatestSuiSystemState",params:[],signal:e})}async queryEvents({query:e,cursor:r,limit:n,order:i,signal:s}){return e&&"MoveEventType"in e&&(0,eu.hasMvrName)(e.MoveEventType)&&(e={...e,MoveEventType:(await this.core.mvr.resolveType({type:e.MoveEventType})).type}),e&&"MoveEventModule"in e&&(0,Es.isValidNamedPackage)(e.MoveEventModule.package)&&(e={...e,MoveEventModule:{module:e.MoveEventModule.module,package:(await this.core.mvr.resolvePackage({package:e.MoveEventModule.package})).package}}),"MoveModule"in e&&(0,Es.isValidNamedPackage)(e.MoveModule.package)&&(e={...e,MoveModule:{module:e.MoveModule.module,package:(await this.core.mvr.resolvePackage({package:e.MoveModule.package})).package}}),await this.transport.request({method:"suix_queryEvents",params:[e,r,n,(i||"descending")==="descending"],signal:s})}async subscribeEvent(e){return this.transport.subscribe({method:"suix_subscribeEvent",unsubscribe:"suix_unsubscribeEvent",params:[e.filter],onMessage:e.onMessage,signal:e.signal})}async subscribeTransaction(e){return this.transport.subscribe({method:"suix_subscribeTransaction",unsubscribe:"suix_unsubscribeTransaction",params:[e.filter],onMessage:e.onMessage,signal:e.signal})}async devInspectTransactionBlock(e){let r;if((0,uF.isTransaction)(e.transactionBlock))e.transactionBlock.setSenderIfNotSet(e.sender),r=(0,Qa.toBase64)(await e.transactionBlock.build({client:this,onlyTransactionKind:!0}));else if(typeof e.transactionBlock=="string")r=e.transactionBlock;else if(e.transactionBlock instanceof Uint8Array)r=(0,Qa.toBase64)(e.transactionBlock);else throw new Error("Unknown transaction block format.");return e.signal?.throwIfAborted(),await this.transport.request({method:"sui_devInspectTransactionBlock",params:[e.sender,r,e.gasPrice?.toString(),e.epoch],signal:e.signal})}async dryRunTransactionBlock(e){return await this.transport.request({method:"sui_dryRunTransactionBlock",params:[typeof e.transactionBlock=="string"?e.transactionBlock:(0,Qa.toBase64)(e.transactionBlock)]})}async getDynamicFields(e){if(!e.parentId||!(0,ar.isValidSuiObjectId)((0,ar.normalizeSuiObjectId)(e.parentId)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"suix_getDynamicFields",params:[e.parentId,e.cursor,e.limit],signal:e.signal})}async getDynamicFieldObject(e){return await this.transport.request({method:"suix_getDynamicFieldObject",params:[e.parentId,e.name],signal:e.signal})}async getLatestCheckpointSequenceNumber({signal:e}={}){let r=await this.transport.request({method:"sui_getLatestCheckpointSequenceNumber",params:[],signal:e});return String(r)}async getCheckpoint(e){return await this.transport.request({method:"sui_getCheckpoint",params:[e.id],signal:e.signal})}async getCheckpoints(e){return await this.transport.request({method:"sui_getCheckpoints",params:[e.cursor,e?.limit,e.descendingOrder],signal:e.signal})}async getCommitteeInfo(e){return await this.transport.request({method:"suix_getCommitteeInfo",params:[e?.epoch],signal:e?.signal})}async getNetworkMetrics({signal:e}={}){return await this.transport.request({method:"suix_getNetworkMetrics",params:[],signal:e})}async getAddressMetrics({signal:e}={}){return await this.transport.request({method:"suix_getLatestAddressMetrics",params:[],signal:e})}async getEpochMetrics(e){return await this.transport.request({method:"suix_getEpochMetrics",params:[e?.cursor,e?.limit,e?.descendingOrder],signal:e?.signal})}async getAllEpochAddressMetrics(e){return await this.transport.request({method:"suix_getAllEpochAddressMetrics",params:[e?.descendingOrder],signal:e?.signal})}async getEpochs(e){return await this.transport.request({method:"suix_getEpochs",params:[e?.cursor,e?.limit,e?.descendingOrder],signal:e?.signal})}async getMoveCallMetrics({signal:e}={}){return await this.transport.request({method:"suix_getMoveCallMetrics",params:[],signal:e})}async getCurrentEpoch({signal:e}={}){return await this.transport.request({method:"suix_getCurrentEpoch",params:[],signal:e})}async getValidatorsApy({signal:e}={}){return await this.transport.request({method:"suix_getValidatorsApy",params:[],signal:e})}async getChainIdentifier({signal:e}={}){let r=await this.getCheckpoint({id:"0",signal:e}),n=(0,Qa.fromBase58)(r.digest);return(0,Qa.toHex)(n.slice(0,4))}async resolveNameServiceAddress(e){return await this.transport.request({method:"suix_resolveNameServiceAddress",params:[e.name],signal:e.signal})}async resolveNameServiceNames({format:e="dot",...r}){let{nextCursor:n,hasNextPage:i,data:s}=await this.transport.request({method:"suix_resolveNameServiceNames",params:[r.address,r.cursor,r.limit],signal:r.signal});return{hasNextPage:i,nextCursor:n,data:s.map(o=>(0,cF.normalizeSuiNSName)(o,e))}}async getProtocolConfig(e){return await this.transport.request({method:"sui_getProtocolConfig",params:[e?.version],signal:e?.signal})}async verifyZkLoginSignature(e){return await this.transport.request({method:"sui_verifyZkLoginSignature",params:[e.bytes,e.signature,e.intentScope,e.author],signal:e.signal})}async waitForTransaction({signal:e,timeout:r=60*1e3,pollInterval:n=2*1e3,...i}){let s=AbortSignal.timeout(r),o=new Promise((u,c)=>{s.addEventListener("abort",()=>c(s.reason))});for(o.catch(()=>{});!s.aborted;){e?.throwIfAborted();try{return await this.getTransactionBlock(i)}catch{await Promise.race([new Promise(c=>setTimeout(c,n)),o])}}throw s.throwIfAborted(),new Error("Unexpected error while waiting for transaction block.")}experimental_asClientExtension(){return{name:"jsonRPC",register:()=>this}}}});var O6=be((CQ,ey)=>{"use strict";var Yg=Object.defineProperty,dF=Object.getOwnPropertyDescriptor,hF=Object.getOwnPropertyNames,pF=Object.prototype.hasOwnProperty,mF=(t,e)=>{for(var r in e)Yg(t,r,{get:e[r],enumerable:!0})},Zg=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of hF(e))!pF.call(t,i)&&i!==r&&Yg(t,i,{get:()=>e[i],enumerable:!(n=dF(e,i))||n.enumerable});return t},gF=(t,e,r)=>(Zg(t,e,"default"),r&&Zg(r,e,"default")),yF=t=>Zg(Yg({},"__esModule",{value:!0}),t),Qg={};mF(Qg,{JsonRpcError:()=>Jg.JsonRpcError,SuiClient:()=>k6.SuiClient,SuiHTTPStatusError:()=>Jg.SuiHTTPStatusError,SuiHTTPTransport:()=>_F.SuiHTTPTransport,SuiHTTPTransportError:()=>Jg.SuiHTTPTransportError,getFullnodeUrl:()=>vF.getFullnodeUrl,isSuiClient:()=>k6.isSuiClient});ey.exports=yF(Qg);var _F=Ng(),vF=jA();gF(Qg,QA(),ey.exports);var k6=S6(),Jg=Vf()});var AI=be(Y=>{"use strict";var ty=iA(),bF=pA(),Zt=af(),E6=O6(),A6=xr("@pythnetwork/pyth-sui-js");function wF(t){return t&&t.__esModule?t:{default:t}}var MF=wF(bF),SF=Object.create,ly=Object.defineProperty,kF=Object.defineProperties,OF=Object.getOwnPropertyDescriptor,EF=Object.getOwnPropertyDescriptors,q6=Object.getOwnPropertyNames,I6=Object.getOwnPropertySymbols,AF=Object.getPrototypeOf,V6=Object.prototype.hasOwnProperty,IF=Object.prototype.propertyIsEnumerable,T6=(t,e,r)=>e in t?ly(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ic=(t,e)=>{for(var r in e||(e={}))V6.call(e,r)&&T6(t,r,e[r]);if(I6)for(var r of I6(e))IF.call(e,r)&&T6(t,r,e[r]);return t},Jf=(t,e)=>kF(t,EF(e)),TF=(t=>typeof xr<"u"?xr:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof xr<"u"?xr:e)[r]}):t)(function(t){if(typeof xr<"u")return xr.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),xF=(t,e)=>function(){return e||(0,t[q6(t)[0]])((e={exports:{}}).exports,e),e.exports},PF=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of q6(e))!V6.call(t,i)&&i!==r&&ly(t,i,{get:()=>e[i],enumerable:!(n=OF(e,i))||n.enumerable});return t},su=(t,e,r)=>(r=t!=null?SF(AF(t)):{},PF(!t||!t.__esModule?ly(r,"default",{value:t,enumerable:!0}):r,t)),Br=(t,e,r)=>new Promise((n,i)=>{var s=c=>{try{u(r.next(c))}catch(d){i(d)}},o=c=>{try{u(r.throw(c))}catch(d){i(d)}},u=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,o);u((r=r.apply(t,e)).next())}),ou=xF({"node_modules/bn.js/lib/bn.js"(t,e){(function(r,n){function i(m,a){if(!m)throw new Error(a||"Assertion failed")}function s(m,a){m.super_=a;var l=function(){};l.prototype=a.prototype,m.prototype=new l,m.prototype.constructor=m}function o(m,a,l){if(o.isBN(m))return m;this.negative=0,this.words=null,this.length=0,this.red=null,m!==null&&((a==="le"||a==="be")&&(l=a,a=10),this._init(m||0,a||10,l||"be"))}typeof r=="object"?r.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=TF("buffer").Buffer}catch{}o.isBN=function(a){return a instanceof o?!0:a!==null&&typeof a=="object"&&a.constructor.wordSize===o.wordSize&&Array.isArray(a.words)},o.max=function(a,l){return a.cmp(l)>0?a:l},o.min=function(a,l){return a.cmp(l)<0?a:l},o.prototype._init=function(a,l,h){if(typeof a=="number")return this._initNumber(a,l,h);if(typeof a=="object")return this._initArray(a,l,h);l==="hex"&&(l=16),i(l===(l|0)&&l>=2&&l<=36),a=a.toString().replace(/\s+/g,"");var y=0;a[0]==="-"&&(y++,this.negative=1),y<a.length&&(l===16?this._parseHex(a,y,h):(this._parseBase(a,l,y),h==="le"&&this._initArray(this.toArray(),l,h)))},o.prototype._initNumber=function(a,l,h){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[a&67108863],this.length=1):a<4503599627370496?(this.words=[a&67108863,a/67108864&67108863],this.length=2):(i(a<9007199254740992),this.words=[a&67108863,a/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),l,h)},o.prototype._initArray=function(a,l,h){if(i(typeof a.length=="number"),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var v,M,w=0;if(h==="be")for(y=a.length-1,v=0;y>=0;y-=3)M=a[y]|a[y-1]<<8|a[y-2]<<16,this.words[v]|=M<<w&67108863,this.words[v+1]=M>>>26-w&67108863,w+=24,w>=26&&(w-=26,v++);else if(h==="le")for(y=0,v=0;y<a.length;y+=3)M=a[y]|a[y+1]<<8|a[y+2]<<16,this.words[v]|=M<<w&67108863,this.words[v+1]=M>>>26-w&67108863,w+=24,w>=26&&(w-=26,v++);return this._strip()};function c(m,a){var l=m.charCodeAt(a);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;i(!1,"Invalid character in "+m)}function d(m,a,l){var h=c(m,l);return l-1>=a&&(h|=c(m,l-1)<<4),h}o.prototype._parseHex=function(a,l,h){this.length=Math.ceil((a.length-l)/6),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var v=0,M=0,w;if(h==="be")for(y=a.length-1;y>=l;y-=2)w=d(a,l,y)<<v,this.words[M]|=w&67108863,v>=18?(v-=18,M+=1,this.words[M]|=w>>>26):v+=8;else{var g=a.length-l;for(y=g%2===0?l+1:l;y<a.length;y+=2)w=d(a,l,y)<<v,this.words[M]|=w&67108863,v>=18?(v-=18,M+=1,this.words[M]|=w>>>26):v+=8}this._strip()};function p(m,a,l,h){for(var y=0,v=0,M=Math.min(m.length,l),w=a;w<M;w++){var g=m.charCodeAt(w)-48;y*=h,g>=49?v=g-49+10:g>=17?v=g-17+10:v=g,i(g>=0&&v<h,"Invalid character"),y+=v}return y}o.prototype._parseBase=function(a,l,h){this.words=[0],this.length=1;for(var y=0,v=1;v<=67108863;v*=l)y++;y--,v=v/l|0;for(var M=a.length-h,w=M%y,g=Math.min(M,M-w)+h,f=0,S=h;S<g;S+=y)f=p(a,S,S+y,l),this.imuln(v),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(w!==0){var V=1;for(f=p(a,S,a.length,l),S=0;S<w;S++)V*=l;this.imuln(V),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this._strip()},o.prototype.copy=function(a){a.words=new Array(this.length);for(var l=0;l<this.length;l++)a.words[l]=this.words[l];a.length=this.length,a.negative=this.negative,a.red=this.red};function _(m,a){m.words=a.words,m.length=a.length,m.negative=a.negative,m.red=a.red}if(o.prototype._move=function(a){_(a,this)},o.prototype.clone=function(){var a=new o(null);return this.copy(a),a},o.prototype._expand=function(a){for(;this.length<a;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=b}catch{o.prototype.inspect=b}else o.prototype.inspect=b;function b(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var O=["","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"],T=[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],x=[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];o.prototype.toString=function(a,l){a=a||10,l=l|0||1;var h;if(a===16||a==="hex"){h="";for(var y=0,v=0,M=0;M<this.length;M++){var w=this.words[M],g=((w<<y|v)&16777215).toString(16);v=w>>>24-y&16777215,y+=2,y>=26&&(y-=26,M--),v!==0||M!==this.length-1?h=O[6-g.length]+g+h:h=g+h}for(v!==0&&(h=v.toString(16)+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(a===(a|0)&&a>=2&&a<=36){var f=T[a],S=x[a];h="";var V=this.clone();for(V.negative=0;!V.isZero();){var z=V.modrn(S).toString(a);V=V.idivn(S),V.isZero()?h=z+h:h=O[f-z.length]+z+h}for(this.isZero()&&(h="0"+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var a=this.words[0];return this.length===2?a+=this.words[1]*67108864:this.length===3&&this.words[2]===1?a+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-a:a},o.prototype.toJSON=function(){return this.toString(16,2)},u&&(o.prototype.toBuffer=function(a,l){return this.toArrayLike(u,a,l)}),o.prototype.toArray=function(a,l){return this.toArrayLike(Array,a,l)};var F=function(a,l){return a.allocUnsafe?a.allocUnsafe(l):new a(l)};o.prototype.toArrayLike=function(a,l,h){this._strip();var y=this.byteLength(),v=h||Math.max(1,y);i(y<=v,"byte array longer than desired length"),i(v>0,"Requested array length <= 0");var M=F(a,v),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](M,y),M},o.prototype._toArrayLikeLE=function(a,l){for(var h=0,y=0,v=0,M=0;v<this.length;v++){var w=this.words[v]<<M|y;a[h++]=w&255,h<a.length&&(a[h++]=w>>8&255),h<a.length&&(a[h++]=w>>16&255),M===6?(h<a.length&&(a[h++]=w>>24&255),y=0,M=0):(y=w>>>24,M+=2)}if(h<a.length)for(a[h++]=y;h<a.length;)a[h++]=0},o.prototype._toArrayLikeBE=function(a,l){for(var h=a.length-1,y=0,v=0,M=0;v<this.length;v++){var w=this.words[v]<<M|y;a[h--]=w&255,h>=0&&(a[h--]=w>>8&255),h>=0&&(a[h--]=w>>16&255),M===6?(h>=0&&(a[h--]=w>>24&255),y=0,M=0):(y=w>>>24,M+=2)}if(h>=0)for(a[h--]=y;h>=0;)a[h--]=0},Math.clz32?o.prototype._countBits=function(a){return 32-Math.clz32(a)}:o.prototype._countBits=function(a){var l=a,h=0;return l>=4096&&(h+=13,l>>>=13),l>=64&&(h+=7,l>>>=7),l>=8&&(h+=4,l>>>=4),l>=2&&(h+=2,l>>>=2),h+l},o.prototype._zeroBits=function(a){if(a===0)return 26;var l=a,h=0;return(l&8191)===0&&(h+=13,l>>>=13),(l&127)===0&&(h+=7,l>>>=7),(l&15)===0&&(h+=4,l>>>=4),(l&3)===0&&(h+=2,l>>>=2),(l&1)===0&&h++,h},o.prototype.bitLength=function(){var a=this.words[this.length-1],l=this._countBits(a);return(this.length-1)*26+l};function R(m){for(var a=new Array(m.bitLength()),l=0;l<a.length;l++){var h=l/26|0,y=l%26;a[l]=m.words[h]>>>y&1}return a}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,l=0;l<this.length;l++){var h=this._zeroBits(this.words[l]);if(a+=h,h!==26)break}return a},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(a){return this.negative!==0?this.abs().inotn(a).iaddn(1):this.clone()},o.prototype.fromTwos=function(a){return this.testn(a-1)?this.notn(a).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(a){for(;this.length<a.length;)this.words[this.length++]=0;for(var l=0;l<a.length;l++)this.words[l]=this.words[l]|a.words[l];return this._strip()},o.prototype.ior=function(a){return i((this.negative|a.negative)===0),this.iuor(a)},o.prototype.or=function(a){return this.length>a.length?this.clone().ior(a):a.clone().ior(this)},o.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},o.prototype.iuand=function(a){var l;this.length>a.length?l=a:l=this;for(var h=0;h<l.length;h++)this.words[h]=this.words[h]&a.words[h];return this.length=l.length,this._strip()},o.prototype.iand=function(a){return i((this.negative|a.negative)===0),this.iuand(a)},o.prototype.and=function(a){return this.length>a.length?this.clone().iand(a):a.clone().iand(this)},o.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},o.prototype.iuxor=function(a){var l,h;this.length>a.length?(l=this,h=a):(l=a,h=this);for(var y=0;y<h.length;y++)this.words[y]=l.words[y]^h.words[y];if(this!==l)for(;y<l.length;y++)this.words[y]=l.words[y];return this.length=l.length,this._strip()},o.prototype.ixor=function(a){return i((this.negative|a.negative)===0),this.iuxor(a)},o.prototype.xor=function(a){return this.length>a.length?this.clone().ixor(a):a.clone().ixor(this)},o.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},o.prototype.inotn=function(a){i(typeof a=="number"&&a>=0);var l=Math.ceil(a/26)|0,h=a%26;this._expand(l),h>0&&l--;for(var y=0;y<l;y++)this.words[y]=~this.words[y]&67108863;return h>0&&(this.words[y]=~this.words[y]&67108863>>26-h),this._strip()},o.prototype.notn=function(a){return this.clone().inotn(a)},o.prototype.setn=function(a,l){i(typeof a=="number"&&a>=0);var h=a/26|0,y=a%26;return this._expand(h+1),l?this.words[h]=this.words[h]|1<<y:this.words[h]=this.words[h]&~(1<<y),this._strip()},o.prototype.iadd=function(a){var l;if(this.negative!==0&&a.negative===0)return this.negative=0,l=this.isub(a),this.negative^=1,this._normSign();if(this.negative===0&&a.negative!==0)return a.negative=0,l=this.isub(a),a.negative=1,l._normSign();var h,y;this.length>a.length?(h=this,y=a):(h=a,y=this);for(var v=0,M=0;M<y.length;M++)l=(h.words[M]|0)+(y.words[M]|0)+v,this.words[M]=l&67108863,v=l>>>26;for(;v!==0&&M<h.length;M++)l=(h.words[M]|0)+v,this.words[M]=l&67108863,v=l>>>26;if(this.length=h.length,v!==0)this.words[this.length]=v,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];return this},o.prototype.add=function(a){var l;return a.negative!==0&&this.negative===0?(a.negative=0,l=this.sub(a),a.negative^=1,l):a.negative===0&&this.negative!==0?(this.negative=0,l=a.sub(this),this.negative=1,l):this.length>a.length?this.clone().iadd(a):a.clone().iadd(this)},o.prototype.isub=function(a){if(a.negative!==0){a.negative=0;var l=this.iadd(a);return a.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var h=this.cmp(a);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var y,v;h>0?(y=this,v=a):(y=a,v=this);for(var M=0,w=0;w<v.length;w++)l=(y.words[w]|0)-(v.words[w]|0)+M,M=l>>26,this.words[w]=l&67108863;for(;M!==0&&w<y.length;w++)l=(y.words[w]|0)+M,M=l>>26,this.words[w]=l&67108863;if(M===0&&w<y.length&&y!==this)for(;w<y.length;w++)this.words[w]=y.words[w];return this.length=Math.max(this.length,w),y!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(a){return this.clone().isub(a)};function H(m,a,l){l.negative=a.negative^m.negative;var h=m.length+a.length|0;l.length=h,h=h-1|0;var y=m.words[0]|0,v=a.words[0]|0,M=y*v,w=M&67108863,g=M/67108864|0;l.words[0]=w;for(var f=1;f<h;f++){for(var S=g>>>26,V=g&67108863,z=Math.min(f,a.length-1),Z=Math.max(0,f-m.length+1);Z<=z;Z++){var ce=f-Z|0;y=m.words[ce]|0,v=a.words[Z]|0,M=y*v+V,S+=M/67108864|0,V=M&67108863}l.words[f]=V|0,g=S|0}return g!==0?l.words[f]=g|0:l.length--,l._strip()}var J=function(a,l,h){var y=a.words,v=l.words,M=h.words,w=0,g,f,S,V=y[0]|0,z=V&8191,Z=V>>>13,ce=y[1]|0,E=ce&8191,P=ce>>>13,j=y[2]|0,L=j&8191,U=j>>>13,W=y[3]|0,q=W&8191,$=W>>>13,X=y[4]|0,G=X&8191,K=X>>>13,ie=y[5]|0,oe=ie&8191,pe=ie>>>13,Fe=y[6]|0,_e=Fe&8191,Ie=Fe>>>13,Le=y[7]|0,me=Le&8191,Ue=Le>>>13,It=y[8]|0,Ee=It&8191,tt=It>>>13,kt=y[9]|0,Oe=kt&8191,Ve=kt>>>13,wt=v[0]|0,ve=wt&8191,lt=wt>>>13,Rt=v[1]|0,Te=Rt&8191,ft=Rt>>>13,Ut=v[2]|0,xe=Ut&8191,dt=Ut>>>13,Lt=v[3]|0,Pe=Lt&8191,ht=Lt>>>13,$t=v[4]|0,Ce=$t&8191,pt=$t>>>13,Ft=v[5]|0,je=Ft&8191,mt=Ft>>>13,qt=v[6]|0,Ne=qt&8191,gt=qt>>>13,Vt=v[7]|0,De=Vt&8191,yt=Vt>>>13,zt=v[8]|0,Be=zt&8191,_t=zt>>>13,Gt=v[9]|0,Re=Gt&8191,ct=Gt>>>13;h.negative=a.negative^l.negative,h.length=19,g=Math.imul(z,ve),f=Math.imul(z,lt),f=f+Math.imul(Z,ve)|0,S=Math.imul(Z,lt);var zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(zn>>>26)|0,zn&=67108863,g=Math.imul(E,ve),f=Math.imul(E,lt),f=f+Math.imul(P,ve)|0,S=Math.imul(P,lt),g=g+Math.imul(z,Te)|0,f=f+Math.imul(z,ft)|0,f=f+Math.imul(Z,Te)|0,S=S+Math.imul(Z,ft)|0;var Gn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Gn>>>26)|0,Gn&=67108863,g=Math.imul(L,ve),f=Math.imul(L,lt),f=f+Math.imul(U,ve)|0,S=Math.imul(U,lt),g=g+Math.imul(E,Te)|0,f=f+Math.imul(E,ft)|0,f=f+Math.imul(P,Te)|0,S=S+Math.imul(P,ft)|0,g=g+Math.imul(z,xe)|0,f=f+Math.imul(z,dt)|0,f=f+Math.imul(Z,xe)|0,S=S+Math.imul(Z,dt)|0;var Hn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Hn>>>26)|0,Hn&=67108863,g=Math.imul(q,ve),f=Math.imul(q,lt),f=f+Math.imul($,ve)|0,S=Math.imul($,lt),g=g+Math.imul(L,Te)|0,f=f+Math.imul(L,ft)|0,f=f+Math.imul(U,Te)|0,S=S+Math.imul(U,ft)|0,g=g+Math.imul(E,xe)|0,f=f+Math.imul(E,dt)|0,f=f+Math.imul(P,xe)|0,S=S+Math.imul(P,dt)|0,g=g+Math.imul(z,Pe)|0,f=f+Math.imul(z,ht)|0,f=f+Math.imul(Z,Pe)|0,S=S+Math.imul(Z,ht)|0;var Wn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Wn>>>26)|0,Wn&=67108863,g=Math.imul(G,ve),f=Math.imul(G,lt),f=f+Math.imul(K,ve)|0,S=Math.imul(K,lt),g=g+Math.imul(q,Te)|0,f=f+Math.imul(q,ft)|0,f=f+Math.imul($,Te)|0,S=S+Math.imul($,ft)|0,g=g+Math.imul(L,xe)|0,f=f+Math.imul(L,dt)|0,f=f+Math.imul(U,xe)|0,S=S+Math.imul(U,dt)|0,g=g+Math.imul(E,Pe)|0,f=f+Math.imul(E,ht)|0,f=f+Math.imul(P,Pe)|0,S=S+Math.imul(P,ht)|0,g=g+Math.imul(z,Ce)|0,f=f+Math.imul(z,pt)|0,f=f+Math.imul(Z,Ce)|0,S=S+Math.imul(Z,pt)|0;var Kn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Kn>>>26)|0,Kn&=67108863,g=Math.imul(oe,ve),f=Math.imul(oe,lt),f=f+Math.imul(pe,ve)|0,S=Math.imul(pe,lt),g=g+Math.imul(G,Te)|0,f=f+Math.imul(G,ft)|0,f=f+Math.imul(K,Te)|0,S=S+Math.imul(K,ft)|0,g=g+Math.imul(q,xe)|0,f=f+Math.imul(q,dt)|0,f=f+Math.imul($,xe)|0,S=S+Math.imul($,dt)|0,g=g+Math.imul(L,Pe)|0,f=f+Math.imul(L,ht)|0,f=f+Math.imul(U,Pe)|0,S=S+Math.imul(U,ht)|0,g=g+Math.imul(E,Ce)|0,f=f+Math.imul(E,pt)|0,f=f+Math.imul(P,Ce)|0,S=S+Math.imul(P,pt)|0,g=g+Math.imul(z,je)|0,f=f+Math.imul(z,mt)|0,f=f+Math.imul(Z,je)|0,S=S+Math.imul(Z,mt)|0;var Xn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Xn>>>26)|0,Xn&=67108863,g=Math.imul(_e,ve),f=Math.imul(_e,lt),f=f+Math.imul(Ie,ve)|0,S=Math.imul(Ie,lt),g=g+Math.imul(oe,Te)|0,f=f+Math.imul(oe,ft)|0,f=f+Math.imul(pe,Te)|0,S=S+Math.imul(pe,ft)|0,g=g+Math.imul(G,xe)|0,f=f+Math.imul(G,dt)|0,f=f+Math.imul(K,xe)|0,S=S+Math.imul(K,dt)|0,g=g+Math.imul(q,Pe)|0,f=f+Math.imul(q,ht)|0,f=f+Math.imul($,Pe)|0,S=S+Math.imul($,ht)|0,g=g+Math.imul(L,Ce)|0,f=f+Math.imul(L,pt)|0,f=f+Math.imul(U,Ce)|0,S=S+Math.imul(U,pt)|0,g=g+Math.imul(E,je)|0,f=f+Math.imul(E,mt)|0,f=f+Math.imul(P,je)|0,S=S+Math.imul(P,mt)|0,g=g+Math.imul(z,Ne)|0,f=f+Math.imul(z,gt)|0,f=f+Math.imul(Z,Ne)|0,S=S+Math.imul(Z,gt)|0;var Jn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Jn>>>26)|0,Jn&=67108863,g=Math.imul(me,ve),f=Math.imul(me,lt),f=f+Math.imul(Ue,ve)|0,S=Math.imul(Ue,lt),g=g+Math.imul(_e,Te)|0,f=f+Math.imul(_e,ft)|0,f=f+Math.imul(Ie,Te)|0,S=S+Math.imul(Ie,ft)|0,g=g+Math.imul(oe,xe)|0,f=f+Math.imul(oe,dt)|0,f=f+Math.imul(pe,xe)|0,S=S+Math.imul(pe,dt)|0,g=g+Math.imul(G,Pe)|0,f=f+Math.imul(G,ht)|0,f=f+Math.imul(K,Pe)|0,S=S+Math.imul(K,ht)|0,g=g+Math.imul(q,Ce)|0,f=f+Math.imul(q,pt)|0,f=f+Math.imul($,Ce)|0,S=S+Math.imul($,pt)|0,g=g+Math.imul(L,je)|0,f=f+Math.imul(L,mt)|0,f=f+Math.imul(U,je)|0,S=S+Math.imul(U,mt)|0,g=g+Math.imul(E,Ne)|0,f=f+Math.imul(E,gt)|0,f=f+Math.imul(P,Ne)|0,S=S+Math.imul(P,gt)|0,g=g+Math.imul(z,De)|0,f=f+Math.imul(z,yt)|0,f=f+Math.imul(Z,De)|0,S=S+Math.imul(Z,yt)|0;var Zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,g=Math.imul(Ee,ve),f=Math.imul(Ee,lt),f=f+Math.imul(tt,ve)|0,S=Math.imul(tt,lt),g=g+Math.imul(me,Te)|0,f=f+Math.imul(me,ft)|0,f=f+Math.imul(Ue,Te)|0,S=S+Math.imul(Ue,ft)|0,g=g+Math.imul(_e,xe)|0,f=f+Math.imul(_e,dt)|0,f=f+Math.imul(Ie,xe)|0,S=S+Math.imul(Ie,dt)|0,g=g+Math.imul(oe,Pe)|0,f=f+Math.imul(oe,ht)|0,f=f+Math.imul(pe,Pe)|0,S=S+Math.imul(pe,ht)|0,g=g+Math.imul(G,Ce)|0,f=f+Math.imul(G,pt)|0,f=f+Math.imul(K,Ce)|0,S=S+Math.imul(K,pt)|0,g=g+Math.imul(q,je)|0,f=f+Math.imul(q,mt)|0,f=f+Math.imul($,je)|0,S=S+Math.imul($,mt)|0,g=g+Math.imul(L,Ne)|0,f=f+Math.imul(L,gt)|0,f=f+Math.imul(U,Ne)|0,S=S+Math.imul(U,gt)|0,g=g+Math.imul(E,De)|0,f=f+Math.imul(E,yt)|0,f=f+Math.imul(P,De)|0,S=S+Math.imul(P,yt)|0,g=g+Math.imul(z,Be)|0,f=f+Math.imul(z,_t)|0,f=f+Math.imul(Z,Be)|0,S=S+Math.imul(Z,_t)|0;var Yn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,g=Math.imul(Oe,ve),f=Math.imul(Oe,lt),f=f+Math.imul(Ve,ve)|0,S=Math.imul(Ve,lt),g=g+Math.imul(Ee,Te)|0,f=f+Math.imul(Ee,ft)|0,f=f+Math.imul(tt,Te)|0,S=S+Math.imul(tt,ft)|0,g=g+Math.imul(me,xe)|0,f=f+Math.imul(me,dt)|0,f=f+Math.imul(Ue,xe)|0,S=S+Math.imul(Ue,dt)|0,g=g+Math.imul(_e,Pe)|0,f=f+Math.imul(_e,ht)|0,f=f+Math.imul(Ie,Pe)|0,S=S+Math.imul(Ie,ht)|0,g=g+Math.imul(oe,Ce)|0,f=f+Math.imul(oe,pt)|0,f=f+Math.imul(pe,Ce)|0,S=S+Math.imul(pe,pt)|0,g=g+Math.imul(G,je)|0,f=f+Math.imul(G,mt)|0,f=f+Math.imul(K,je)|0,S=S+Math.imul(K,mt)|0,g=g+Math.imul(q,Ne)|0,f=f+Math.imul(q,gt)|0,f=f+Math.imul($,Ne)|0,S=S+Math.imul($,gt)|0,g=g+Math.imul(L,De)|0,f=f+Math.imul(L,yt)|0,f=f+Math.imul(U,De)|0,S=S+Math.imul(U,yt)|0,g=g+Math.imul(E,Be)|0,f=f+Math.imul(E,_t)|0,f=f+Math.imul(P,Be)|0,S=S+Math.imul(P,_t)|0,g=g+Math.imul(z,Re)|0,f=f+Math.imul(z,ct)|0,f=f+Math.imul(Z,Re)|0,S=S+Math.imul(Z,ct)|0;var Qn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,g=Math.imul(Oe,Te),f=Math.imul(Oe,ft),f=f+Math.imul(Ve,Te)|0,S=Math.imul(Ve,ft),g=g+Math.imul(Ee,xe)|0,f=f+Math.imul(Ee,dt)|0,f=f+Math.imul(tt,xe)|0,S=S+Math.imul(tt,dt)|0,g=g+Math.imul(me,Pe)|0,f=f+Math.imul(me,ht)|0,f=f+Math.imul(Ue,Pe)|0,S=S+Math.imul(Ue,ht)|0,g=g+Math.imul(_e,Ce)|0,f=f+Math.imul(_e,pt)|0,f=f+Math.imul(Ie,Ce)|0,S=S+Math.imul(Ie,pt)|0,g=g+Math.imul(oe,je)|0,f=f+Math.imul(oe,mt)|0,f=f+Math.imul(pe,je)|0,S=S+Math.imul(pe,mt)|0,g=g+Math.imul(G,Ne)|0,f=f+Math.imul(G,gt)|0,f=f+Math.imul(K,Ne)|0,S=S+Math.imul(K,gt)|0,g=g+Math.imul(q,De)|0,f=f+Math.imul(q,yt)|0,f=f+Math.imul($,De)|0,S=S+Math.imul($,yt)|0,g=g+Math.imul(L,Be)|0,f=f+Math.imul(L,_t)|0,f=f+Math.imul(U,Be)|0,S=S+Math.imul(U,_t)|0,g=g+Math.imul(E,Re)|0,f=f+Math.imul(E,ct)|0,f=f+Math.imul(P,Re)|0,S=S+Math.imul(P,ct)|0;var ei=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,g=Math.imul(Oe,xe),f=Math.imul(Oe,dt),f=f+Math.imul(Ve,xe)|0,S=Math.imul(Ve,dt),g=g+Math.imul(Ee,Pe)|0,f=f+Math.imul(Ee,ht)|0,f=f+Math.imul(tt,Pe)|0,S=S+Math.imul(tt,ht)|0,g=g+Math.imul(me,Ce)|0,f=f+Math.imul(me,pt)|0,f=f+Math.imul(Ue,Ce)|0,S=S+Math.imul(Ue,pt)|0,g=g+Math.imul(_e,je)|0,f=f+Math.imul(_e,mt)|0,f=f+Math.imul(Ie,je)|0,S=S+Math.imul(Ie,mt)|0,g=g+Math.imul(oe,Ne)|0,f=f+Math.imul(oe,gt)|0,f=f+Math.imul(pe,Ne)|0,S=S+Math.imul(pe,gt)|0,g=g+Math.imul(G,De)|0,f=f+Math.imul(G,yt)|0,f=f+Math.imul(K,De)|0,S=S+Math.imul(K,yt)|0,g=g+Math.imul(q,Be)|0,f=f+Math.imul(q,_t)|0,f=f+Math.imul($,Be)|0,S=S+Math.imul($,_t)|0,g=g+Math.imul(L,Re)|0,f=f+Math.imul(L,ct)|0,f=f+Math.imul(U,Re)|0,S=S+Math.imul(U,ct)|0;var ti=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,g=Math.imul(Oe,Pe),f=Math.imul(Oe,ht),f=f+Math.imul(Ve,Pe)|0,S=Math.imul(Ve,ht),g=g+Math.imul(Ee,Ce)|0,f=f+Math.imul(Ee,pt)|0,f=f+Math.imul(tt,Ce)|0,S=S+Math.imul(tt,pt)|0,g=g+Math.imul(me,je)|0,f=f+Math.imul(me,mt)|0,f=f+Math.imul(Ue,je)|0,S=S+Math.imul(Ue,mt)|0,g=g+Math.imul(_e,Ne)|0,f=f+Math.imul(_e,gt)|0,f=f+Math.imul(Ie,Ne)|0,S=S+Math.imul(Ie,gt)|0,g=g+Math.imul(oe,De)|0,f=f+Math.imul(oe,yt)|0,f=f+Math.imul(pe,De)|0,S=S+Math.imul(pe,yt)|0,g=g+Math.imul(G,Be)|0,f=f+Math.imul(G,_t)|0,f=f+Math.imul(K,Be)|0,S=S+Math.imul(K,_t)|0,g=g+Math.imul(q,Re)|0,f=f+Math.imul(q,ct)|0,f=f+Math.imul($,Re)|0,S=S+Math.imul($,ct)|0;var ri=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(Oe,Ce),f=Math.imul(Oe,pt),f=f+Math.imul(Ve,Ce)|0,S=Math.imul(Ve,pt),g=g+Math.imul(Ee,je)|0,f=f+Math.imul(Ee,mt)|0,f=f+Math.imul(tt,je)|0,S=S+Math.imul(tt,mt)|0,g=g+Math.imul(me,Ne)|0,f=f+Math.imul(me,gt)|0,f=f+Math.imul(Ue,Ne)|0,S=S+Math.imul(Ue,gt)|0,g=g+Math.imul(_e,De)|0,f=f+Math.imul(_e,yt)|0,f=f+Math.imul(Ie,De)|0,S=S+Math.imul(Ie,yt)|0,g=g+Math.imul(oe,Be)|0,f=f+Math.imul(oe,_t)|0,f=f+Math.imul(pe,Be)|0,S=S+Math.imul(pe,_t)|0,g=g+Math.imul(G,Re)|0,f=f+Math.imul(G,ct)|0,f=f+Math.imul(K,Re)|0,S=S+Math.imul(K,ct)|0;var ni=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(Oe,je),f=Math.imul(Oe,mt),f=f+Math.imul(Ve,je)|0,S=Math.imul(Ve,mt),g=g+Math.imul(Ee,Ne)|0,f=f+Math.imul(Ee,gt)|0,f=f+Math.imul(tt,Ne)|0,S=S+Math.imul(tt,gt)|0,g=g+Math.imul(me,De)|0,f=f+Math.imul(me,yt)|0,f=f+Math.imul(Ue,De)|0,S=S+Math.imul(Ue,yt)|0,g=g+Math.imul(_e,Be)|0,f=f+Math.imul(_e,_t)|0,f=f+Math.imul(Ie,Be)|0,S=S+Math.imul(Ie,_t)|0,g=g+Math.imul(oe,Re)|0,f=f+Math.imul(oe,ct)|0,f=f+Math.imul(pe,Re)|0,S=S+Math.imul(pe,ct)|0;var ii=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,g=Math.imul(Oe,Ne),f=Math.imul(Oe,gt),f=f+Math.imul(Ve,Ne)|0,S=Math.imul(Ve,gt),g=g+Math.imul(Ee,De)|0,f=f+Math.imul(Ee,yt)|0,f=f+Math.imul(tt,De)|0,S=S+Math.imul(tt,yt)|0,g=g+Math.imul(me,Be)|0,f=f+Math.imul(me,_t)|0,f=f+Math.imul(Ue,Be)|0,S=S+Math.imul(Ue,_t)|0,g=g+Math.imul(_e,Re)|0,f=f+Math.imul(_e,ct)|0,f=f+Math.imul(Ie,Re)|0,S=S+Math.imul(Ie,ct)|0;var si=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(Oe,De),f=Math.imul(Oe,yt),f=f+Math.imul(Ve,De)|0,S=Math.imul(Ve,yt),g=g+Math.imul(Ee,Be)|0,f=f+Math.imul(Ee,_t)|0,f=f+Math.imul(tt,Be)|0,S=S+Math.imul(tt,_t)|0,g=g+Math.imul(me,Re)|0,f=f+Math.imul(me,ct)|0,f=f+Math.imul(Ue,Re)|0,S=S+Math.imul(Ue,ct)|0;var oi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(Oe,Be),f=Math.imul(Oe,_t),f=f+Math.imul(Ve,Be)|0,S=Math.imul(Ve,_t),g=g+Math.imul(Ee,Re)|0,f=f+Math.imul(Ee,ct)|0,f=f+Math.imul(tt,Re)|0,S=S+Math.imul(tt,ct)|0;var ai=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(Oe,Re),f=Math.imul(Oe,ct),f=f+Math.imul(Ve,Re)|0,S=Math.imul(Ve,ct);var jo=(w+g|0)+((f&8191)<<13)|0;return w=(S+(f>>>13)|0)+(jo>>>26)|0,jo&=67108863,M[0]=zn,M[1]=Gn,M[2]=Hn,M[3]=Wn,M[4]=Kn,M[5]=Xn,M[6]=Jn,M[7]=Zn,M[8]=Yn,M[9]=Qn,M[10]=ei,M[11]=ti,M[12]=ri,M[13]=ni,M[14]=ii,M[15]=si,M[16]=oi,M[17]=ai,M[18]=jo,w!==0&&(M[19]=w,h.length++),h};Math.imul||(J=H);function ee(m,a,l){l.negative=a.negative^m.negative,l.length=m.length+a.length;for(var h=0,y=0,v=0;v<l.length-1;v++){var M=y;y=0;for(var w=h&67108863,g=Math.min(v,a.length-1),f=Math.max(0,v-m.length+1);f<=g;f++){var S=v-f,V=m.words[S]|0,z=a.words[f]|0,Z=V*z,ce=Z&67108863;M=M+(Z/67108864|0)|0,ce=ce+w|0,w=ce&67108863,M=M+(ce>>>26)|0,y+=M>>>26,M&=67108863}l.words[v]=w,h=M,M=y}return h!==0?l.words[v]=h:l.length--,l._strip()}function ae(m,a,l){return ee(m,a,l)}o.prototype.mulTo=function(a,l){var h,y=this.length+a.length;return this.length===10&&a.length===10?h=J(this,a,l):y<63?h=H(this,a,l):y<1024?h=ee(this,a,l):h=ae(this,a,l),h},o.prototype.mul=function(a){var l=new o(null);return l.words=new Array(this.length+a.length),this.mulTo(a,l)},o.prototype.mulf=function(a){var l=new o(null);return l.words=new Array(this.length+a.length),ae(this,a,l)},o.prototype.imul=function(a){return this.clone().mulTo(a,this)},o.prototype.imuln=function(a){var l=a<0;l&&(a=-a),i(typeof a=="number"),i(a<67108864);for(var h=0,y=0;y<this.length;y++){var v=(this.words[y]|0)*a,M=(v&67108863)+(h&67108863);h>>=26,h+=v/67108864|0,h+=M>>>26,this.words[y]=M&67108863}return h!==0&&(this.words[y]=h,this.length++),l?this.ineg():this},o.prototype.muln=function(a){return this.clone().imuln(a)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(a){var l=R(a);if(l.length===0)return new o(1);for(var h=this,y=0;y<l.length&&l[y]===0;y++,h=h.sqr());if(++y<l.length)for(var v=h.sqr();y<l.length;y++,v=v.sqr())l[y]!==0&&(h=h.mul(v));return h},o.prototype.iushln=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26,y=67108863>>>26-l<<26-l,v;if(l!==0){var M=0;for(v=0;v<this.length;v++){var w=this.words[v]&y,g=(this.words[v]|0)-w<<l;this.words[v]=g|M,M=w>>>26-l}M&&(this.words[v]=M,this.length++)}if(h!==0){for(v=this.length-1;v>=0;v--)this.words[v+h]=this.words[v];for(v=0;v<h;v++)this.words[v]=0;this.length+=h}return this._strip()},o.prototype.ishln=function(a){return i(this.negative===0),this.iushln(a)},o.prototype.iushrn=function(a,l,h){i(typeof a=="number"&&a>=0);var y;l?y=(l-l%26)/26:y=0;var v=a%26,M=Math.min((a-v)/26,this.length),w=67108863^67108863>>>v<<v,g=h;if(y-=M,y=Math.max(0,y),g){for(var f=0;f<M;f++)g.words[f]=this.words[f];g.length=M}if(M!==0)if(this.length>M)for(this.length-=M,f=0;f<this.length;f++)this.words[f]=this.words[f+M];else this.words[0]=0,this.length=1;var S=0;for(f=this.length-1;f>=0&&(S!==0||f>=y);f--){var V=this.words[f]|0;this.words[f]=S<<26-v|V>>>v,S=V&w}return g&&S!==0&&(g.words[g.length++]=S),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(a,l,h){return i(this.negative===0),this.iushrn(a,l,h)},o.prototype.shln=function(a){return this.clone().ishln(a)},o.prototype.ushln=function(a){return this.clone().iushln(a)},o.prototype.shrn=function(a){return this.clone().ishrn(a)},o.prototype.ushrn=function(a){return this.clone().iushrn(a)},o.prototype.testn=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26,y=1<<l;if(this.length<=h)return!1;var v=this.words[h];return!!(v&y)},o.prototype.imaskn=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(l!==0&&h++,this.length=Math.min(h,this.length),l!==0){var y=67108863^67108863>>>l<<l;this.words[this.length-1]&=y}return this._strip()},o.prototype.maskn=function(a){return this.clone().imaskn(a)},o.prototype.iaddn=function(a){return i(typeof a=="number"),i(a<67108864),a<0?this.isubn(-a):this.negative!==0?this.length===1&&(this.words[0]|0)<=a?(this.words[0]=a-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(a),this.negative=1,this):this._iaddn(a)},o.prototype._iaddn=function(a){this.words[0]+=a;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},o.prototype.isubn=function(a){if(i(typeof a=="number"),i(a<67108864),a<0)return this.iaddn(-a);if(this.negative!==0)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},o.prototype.addn=function(a){return this.clone().iaddn(a)},o.prototype.subn=function(a){return this.clone().isubn(a)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(a,l,h){var y=a.length+h,v;this._expand(y);var M,w=0;for(v=0;v<a.length;v++){M=(this.words[v+h]|0)+w;var g=(a.words[v]|0)*l;M-=g&67108863,w=(M>>26)-(g/67108864|0),this.words[v+h]=M&67108863}for(;v<this.length-h;v++)M=(this.words[v+h]|0)+w,w=M>>26,this.words[v+h]=M&67108863;if(w===0)return this._strip();for(i(w===-1),w=0,v=0;v<this.length;v++)M=-(this.words[v]|0)+w,w=M>>26,this.words[v]=M&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(a,l){var h=this.length-a.length,y=this.clone(),v=a,M=v.words[v.length-1]|0,w=this._countBits(M);h=26-w,h!==0&&(v=v.ushln(h),y.iushln(h),M=v.words[v.length-1]|0);var g=y.length-v.length,f;if(l!=="mod"){f=new o(null),f.length=g+1,f.words=new Array(f.length);for(var S=0;S<f.length;S++)f.words[S]=0}var V=y.clone()._ishlnsubmul(v,1,g);V.negative===0&&(y=V,f&&(f.words[g]=1));for(var z=g-1;z>=0;z--){var Z=(y.words[v.length+z]|0)*67108864+(y.words[v.length+z-1]|0);for(Z=Math.min(Z/M|0,67108863),y._ishlnsubmul(v,Z,z);y.negative!==0;)Z--,y.negative=0,y._ishlnsubmul(v,1,z),y.isZero()||(y.negative^=1);f&&(f.words[z]=Z)}return f&&f._strip(),y._strip(),l!=="div"&&h!==0&&y.iushrn(h),{div:f||null,mod:y}},o.prototype.divmod=function(a,l,h){if(i(!a.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var y,v,M;return this.negative!==0&&a.negative===0?(M=this.neg().divmod(a,l),l!=="mod"&&(y=M.div.neg()),l!=="div"&&(v=M.mod.neg(),h&&v.negative!==0&&v.iadd(a)),{div:y,mod:v}):this.negative===0&&a.negative!==0?(M=this.divmod(a.neg(),l),l!=="mod"&&(y=M.div.neg()),{div:y,mod:M.mod}):(this.negative&a.negative)!==0?(M=this.neg().divmod(a.neg(),l),l!=="div"&&(v=M.mod.neg(),h&&v.negative!==0&&v.isub(a)),{div:M.div,mod:v}):a.length>this.length||this.cmp(a)<0?{div:new o(0),mod:this}:a.length===1?l==="div"?{div:this.divn(a.words[0]),mod:null}:l==="mod"?{div:null,mod:new o(this.modrn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new o(this.modrn(a.words[0]))}:this._wordDiv(a,l)},o.prototype.div=function(a){return this.divmod(a,"div",!1).div},o.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},o.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},o.prototype.divRound=function(a){var l=this.divmod(a);if(l.mod.isZero())return l.div;var h=l.div.negative!==0?l.mod.isub(a):l.mod,y=a.ushrn(1),v=a.andln(1),M=h.cmp(y);return M<0||v===1&&M===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},o.prototype.modrn=function(a){var l=a<0;l&&(a=-a),i(a<=67108863);for(var h=(1<<26)%a,y=0,v=this.length-1;v>=0;v--)y=(h*y+(this.words[v]|0))%a;return l?-y:y},o.prototype.modn=function(a){return this.modrn(a)},o.prototype.idivn=function(a){var l=a<0;l&&(a=-a),i(a<=67108863);for(var h=0,y=this.length-1;y>=0;y--){var v=(this.words[y]|0)+h*67108864;this.words[y]=v/a|0,h=v%a}return this._strip(),l?this.ineg():this},o.prototype.divn=function(a){return this.clone().idivn(a)},o.prototype.egcd=function(a){i(a.negative===0),i(!a.isZero());var l=this,h=a.clone();l.negative!==0?l=l.umod(a):l=l.clone();for(var y=new o(1),v=new o(0),M=new o(0),w=new o(1),g=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++g;for(var f=h.clone(),S=l.clone();!l.isZero();){for(var V=0,z=1;(l.words[0]&z)===0&&V<26;++V,z<<=1);if(V>0)for(l.iushrn(V);V-- >0;)(y.isOdd()||v.isOdd())&&(y.iadd(f),v.isub(S)),y.iushrn(1),v.iushrn(1);for(var Z=0,ce=1;(h.words[0]&ce)===0&&Z<26;++Z,ce<<=1);if(Z>0)for(h.iushrn(Z);Z-- >0;)(M.isOdd()||w.isOdd())&&(M.iadd(f),w.isub(S)),M.iushrn(1),w.iushrn(1);l.cmp(h)>=0?(l.isub(h),y.isub(M),v.isub(w)):(h.isub(l),M.isub(y),w.isub(v))}return{a:M,b:w,gcd:h.iushln(g)}},o.prototype._invmp=function(a){i(a.negative===0),i(!a.isZero());var l=this,h=a.clone();l.negative!==0?l=l.umod(a):l=l.clone();for(var y=new o(1),v=new o(0),M=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var w=0,g=1;(l.words[0]&g)===0&&w<26;++w,g<<=1);if(w>0)for(l.iushrn(w);w-- >0;)y.isOdd()&&y.iadd(M),y.iushrn(1);for(var f=0,S=1;(h.words[0]&S)===0&&f<26;++f,S<<=1);if(f>0)for(h.iushrn(f);f-- >0;)v.isOdd()&&v.iadd(M),v.iushrn(1);l.cmp(h)>=0?(l.isub(h),y.isub(v)):(h.isub(l),v.isub(y))}var V;return l.cmpn(1)===0?V=y:V=v,V.cmpn(0)<0&&V.iadd(a),V},o.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var l=this.clone(),h=a.clone();l.negative=0,h.negative=0;for(var y=0;l.isEven()&&h.isEven();y++)l.iushrn(1),h.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;h.isEven();)h.iushrn(1);var v=l.cmp(h);if(v<0){var M=l;l=h,h=M}else if(v===0||h.cmpn(1)===0)break;l.isub(h)}while(!0);return h.iushln(y)},o.prototype.invm=function(a){return this.egcd(a).a.umod(a)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(a){return this.words[0]&a},o.prototype.bincn=function(a){i(typeof a=="number");var l=a%26,h=(a-l)/26,y=1<<l;if(this.length<=h)return this._expand(h+1),this.words[h]|=y,this;for(var v=y,M=h;v!==0&&M<this.length;M++){var w=this.words[M]|0;w+=v,v=w>>>26,w&=67108863,this.words[M]=w}return v!==0&&(this.words[M]=v,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(a){var l=a<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var h;if(this.length>1)h=1;else{l&&(a=-a),i(a<=67108863,"Number is too big");var y=this.words[0]|0;h=y===a?0:y<a?-1:1}return this.negative!==0?-h|0:h},o.prototype.cmp=function(a){if(this.negative!==0&&a.negative===0)return-1;if(this.negative===0&&a.negative!==0)return 1;var l=this.ucmp(a);return this.negative!==0?-l|0:l},o.prototype.ucmp=function(a){if(this.length>a.length)return 1;if(this.length<a.length)return-1;for(var l=0,h=this.length-1;h>=0;h--){var y=this.words[h]|0,v=a.words[h]|0;if(y!==v){y<v?l=-1:y>v&&(l=1);break}}return l},o.prototype.gtn=function(a){return this.cmpn(a)===1},o.prototype.gt=function(a){return this.cmp(a)===1},o.prototype.gten=function(a){return this.cmpn(a)>=0},o.prototype.gte=function(a){return this.cmp(a)>=0},o.prototype.ltn=function(a){return this.cmpn(a)===-1},o.prototype.lt=function(a){return this.cmp(a)===-1},o.prototype.lten=function(a){return this.cmpn(a)<=0},o.prototype.lte=function(a){return this.cmp(a)<=0},o.prototype.eqn=function(a){return this.cmpn(a)===0},o.prototype.eq=function(a){return this.cmp(a)===0},o.red=function(a){return new N(a)},o.prototype.toRed=function(a){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),a.convertTo(this)._forceRed(a)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(a){return this.red=a,this},o.prototype.forceRed=function(a){return i(!this.red,"Already a number in reduction context"),this._forceRed(a)},o.prototype.redAdd=function(a){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},o.prototype.redIAdd=function(a){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},o.prototype.redSub=function(a){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},o.prototype.redISub=function(a){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},o.prototype.redShl=function(a){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},o.prototype.redMul=function(a){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},o.prototype.redIMul=function(a){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(a){return i(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var te={k256:null,p224:null,p192:null,p25519:null};function he(m,a){this.name=m,this.p=new o(a,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}he.prototype._tmp=function(){var a=new o(null);return a.words=new Array(Math.ceil(this.n/13)),a},he.prototype.ireduce=function(a){var l=a,h;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),h=l.bitLength();while(h>this.n);var y=h<this.n?-1:l.ucmp(this.p);return y===0?(l.words[0]=0,l.length=1):y>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},he.prototype.split=function(a,l){a.iushrn(this.n,0,l)},he.prototype.imulK=function(a){return a.imul(this.k)};function A(){he.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(A,he),A.prototype.split=function(a,l){for(var h=4194303,y=Math.min(a.length,9),v=0;v<y;v++)l.words[v]=a.words[v];if(l.length=y,a.length<=9){a.words[0]=0,a.length=1;return}var M=a.words[9];for(l.words[l.length++]=M&h,v=10;v<a.length;v++){var w=a.words[v]|0;a.words[v-10]=(w&h)<<4|M>>>22,M=w}M>>>=22,a.words[v-10]=M,M===0&&a.length>10?a.length-=10:a.length-=9},A.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var l=0,h=0;h<a.length;h++){var y=a.words[h]|0;l+=y*977,a.words[h]=l&67108863,l=y*64+(l/67108864|0)}return a.words[a.length-1]===0&&(a.length--,a.words[a.length-1]===0&&a.length--),a};function I(){he.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,he);function C(){he.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(C,he);function D(){he.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(D,he),D.prototype.imulK=function(a){for(var l=0,h=0;h<a.length;h++){var y=(a.words[h]|0)*19+l,v=y&67108863;y>>>=26,a.words[h]=v,l=y}return l!==0&&(a.words[a.length++]=l),a},o._prime=function(a){if(te[a])return te[a];var l;if(a==="k256")l=new A;else if(a==="p224")l=new I;else if(a==="p192")l=new C;else if(a==="p25519")l=new D;else throw new Error("Unknown prime "+a);return te[a]=l,l};function N(m){if(typeof m=="string"){var a=o._prime(m);this.m=a.p,this.prime=a}else i(m.gtn(1),"modulus must be greater than 1"),this.m=m,this.prime=null}N.prototype._verify1=function(a){i(a.negative===0,"red works only with positives"),i(a.red,"red works only with red numbers")},N.prototype._verify2=function(a,l){i((a.negative|l.negative)===0,"red works only with positives"),i(a.red&&a.red===l.red,"red works only with red numbers")},N.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):(_(a,a.umod(this.m)._forceRed(this)),a)},N.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},N.prototype.add=function(a,l){this._verify2(a,l);var h=a.add(l);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},N.prototype.iadd=function(a,l){this._verify2(a,l);var h=a.iadd(l);return h.cmp(this.m)>=0&&h.isub(this.m),h},N.prototype.sub=function(a,l){this._verify2(a,l);var h=a.sub(l);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},N.prototype.isub=function(a,l){this._verify2(a,l);var h=a.isub(l);return h.cmpn(0)<0&&h.iadd(this.m),h},N.prototype.shl=function(a,l){return this._verify1(a),this.imod(a.ushln(l))},N.prototype.imul=function(a,l){return this._verify2(a,l),this.imod(a.imul(l))},N.prototype.mul=function(a,l){return this._verify2(a,l),this.imod(a.mul(l))},N.prototype.isqr=function(a){return this.imul(a,a.clone())},N.prototype.sqr=function(a){return this.mul(a,a)},N.prototype.sqrt=function(a){if(a.isZero())return a.clone();var l=this.m.andln(3);if(i(l%2===1),l===3){var h=this.m.add(new o(1)).iushrn(2);return this.pow(a,h)}for(var y=this.m.subn(1),v=0;!y.isZero()&&y.andln(1)===0;)v++,y.iushrn(1);i(!y.isZero());var M=new o(1).toRed(this),w=M.redNeg(),g=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new o(2*f*f).toRed(this);this.pow(f,g).cmp(w)!==0;)f.redIAdd(w);for(var S=this.pow(f,y),V=this.pow(a,y.addn(1).iushrn(1)),z=this.pow(a,y),Z=v;z.cmp(M)!==0;){for(var ce=z,E=0;ce.cmp(M)!==0;E++)ce=ce.redSqr();i(E<Z);var P=this.pow(S,new o(1).iushln(Z-E-1));V=V.redMul(P),S=P.redSqr(),z=z.redMul(S),Z=E}return V},N.prototype.invm=function(a){var l=a._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},N.prototype.pow=function(a,l){if(l.isZero())return new o(1).toRed(this);if(l.cmpn(1)===0)return a.clone();var h=4,y=new Array(1<<h);y[0]=new o(1).toRed(this),y[1]=a;for(var v=2;v<y.length;v++)y[v]=this.mul(y[v-1],a);var M=y[0],w=0,g=0,f=l.bitLength()%26;for(f===0&&(f=26),v=l.length-1;v>=0;v--){for(var S=l.words[v],V=f-1;V>=0;V--){var z=S>>V&1;if(M!==y[0]&&(M=this.sqr(M)),z===0&&w===0){g=0;continue}w<<=1,w|=z,g++,!(g!==h&&(v!==0||V!==0))&&(M=this.mul(M,y[w]),g=0,w=0)}f=26}return M},N.prototype.convertTo=function(a){var l=a.umod(this.m);return l===a?l.clone():l},N.prototype.convertFrom=function(a){var l=a.clone();return l.red=null,l},o.mont=function(a){return new k(a)};function k(m){N.call(this,m),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(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(k,N),k.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},k.prototype.convertFrom=function(a){var l=this.imod(a.mul(this.rinv));return l.red=null,l},k.prototype.imul=function(a,l){if(a.isZero()||l.isZero())return a.words[0]=0,a.length=1,a;var h=a.imul(l),y=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),v=h.isub(y).iushrn(this.shift),M=v;return v.cmp(this.m)>=0?M=v.isub(this.m):v.cmpn(0)<0&&(M=v.iadd(this.m)),M._forceRed(this)},k.prototype.mul=function(a,l){if(a.isZero()||l.isZero())return new o(0)._forceRed(this);var h=a.mul(l),y=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),v=h.isub(y).iushrn(this.shift),M=v;return v.cmp(this.m)>=0?M=v.isub(this.m):v.cmpn(0)<0&&(M=v.iadd(this.m)),M._forceRed(this)},k.prototype.invm=function(a){var l=this.imod(a._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof e>"u"||e,t)}}),rr=su(ou()),tu=su(ou()),z6=(t=>(t.InvalidType="InvalidType",t))(z6||{}),G6=(t=>(t.MissAggregatorPackage="MissAggregatorPackage",t.MissGlobalConfig="MissGlobalConfig",t.InvalidWallet="InvalidWallet",t.SimulateError="SimulateError",t))(G6||{}),H6=(t=>(t.InsufficientBalance="InsufficientBalance",t.SimulateEventError="simulateEventError",t.CannotGetDecimals="CannotGetDecimals",t.MissCoinA="MissCoinA",t.MissCoinB="MissCoinB",t.MissTurbosFeeType="MissTurbosFeeType",t.MissAftermathLpSupplyType="MissAftermathLpSupplyType",t))(H6||{}),W6=(t=>(t[t.NumberTooLarge=1e3]="NumberTooLarge",t[t.RateLimitExceeded=1001]="RateLimitExceeded",t[t.InsufficientLiquidity=1002]="InsufficientLiquidity",t[t.HoneyPot=1003]="HoneyPot",t))(W6||{});function Kf(t){switch(t){case 1e3:return"Number too large";case 1001:return"Rate limit exceeded";case 1002:return"Insufficient liquidity";case 1003:return"HoneyPot scam detected";default:return"Unknown error"}}var CF=class K6 extends Error{constructor(e,r){super(e),this.message=e,this.errorCode=r}static isAggregatorErrorCode(e,r){return e instanceof K6&&e.errorCode===r}},jF=0,X6=1,NF=2;function x6(t,e){return t===e?jF:t<e?X6:NF}function DF(t,e){let r=0,n=t.length<=e.length?t.length:e.length,i=x6(t.length,e.length);for(;r<n;){let s=x6(t.charCodeAt(r),e.charCodeAt(r));if(r+=1,s!==0)return s}return i}function BF(t,e){return DF(t,e)===X6}function ry(t,...e){let r=Array.isArray(e[e.length-1])?e.pop():[],i=[t,...e].filter(Boolean).join("::");return r&&r.length&&(i+=`<${r.join(", ")}>`),i}function RF(t){return t.split("::")[0]}function nu(t){var e;try{let r=t.replace(/\s/g,""),n=r.match(/(<.+>)$/),i=(e=n?.[0])==null?void 0:e.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(i){r=r.slice(0,r.indexOf("<"));let c=nu(r),d=Jf(Ic({},c),{type_arguments:i.map(p=>nu(p).source_address)});return d.type_arguments=d.type_arguments.map(p=>ki.isSuiCoin(p)?p:nu(p).source_address),d.source_address=ry(d.full_address,d.type_arguments),d}let s=r.split("::"),u={full_address:r,address:r===fy||r===Y6?"0x2":Zt.normalizeSuiObjectId(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return u.full_address=`${u.address}::${u.module}::${u.name}`,u.source_address=ry(u.full_address,u.type_arguments),u}catch{return{full_address:t,address:"",module:"",name:"",type_arguments:[],source_address:t}}}function ny(t){return nu(t).source_address}function J6(t){return t.toLowerCase().startsWith("0x")?Zt.normalizeSuiObjectId(t):t}function Z6(t){for(let e in t){let r=typeof t[e];if(r==="object")Z6(t[e]);else if(r==="string"){let n=t[e];t[e]=J6(n)}}}function UF(t,e,r){return`${t}::${e}::${r}`}var LF="0x2::coin::Coin",$F=/^0x2::coin::Coin<(.+)>$/,FF=1e3,qF=500,VF=100,zF=100,GF=1e3,fy="0x2::sui::SUI",Y6="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",HF="SUI",WF=450,KF="0x0000000000000000000000000000000000000005",ki=class vo{static getCoinTypeArg(e){let r=e.type.match($F);return r?r[1]:null}static isSUI(e){let r=vo.getCoinTypeArg(e);return r?vo.getCoinSymbol(r)==="SUI":!1}static getCoinSymbol(e){return e.substring(e.lastIndexOf(":")+1)}static getBalance(e){return BigInt(e.fields.balance)}static totalBalance(e,r){let n=BigInt(0);return e.forEach(i=>{r===i.coinAddress&&(n+=BigInt(i.balance))}),n}static getID(e){return e.fields.id.id}static getCoinTypeFromArg(e){return`${LF}<${e}>`}static getCoinAssets(e,r){let n=[];return r.forEach(i=>{ny(i.coinAddress)===ny(e)&&n.push(i)}),n}static isSuiCoin(e){return nu(e).full_address===fy}static selectCoinObjectIdGreaterThanOrEqual(e,r,n=[]){let i=vo.selectCoinAssetGreaterThanOrEqual(e,r,n),s=i.selectedCoins.map(c=>c.coinObjectId),o=i.remainingCoins,u=i.selectedCoins.map(c=>c.balance.toString());return{objectArray:s,remainCoins:o,amountArray:u}}static selectCoinAssetGreaterThanOrEqual(e,r,n=[]){let i=vo.sortByBalance(e.filter(d=>!n.includes(d.coinObjectId))),s=vo.calculateTotalBalance(i);if(s<r)return{selectedCoins:[],remainingCoins:i};if(s===r)return{selectedCoins:i,remainingCoins:[]};let o=BigInt(0),u=[],c=[...i];for(;o<s;){let d=r-o,p=c.findIndex(b=>b.balance>=d);if(p!==-1){u.push(c[p]),c.splice(p,1);break}let _=c.pop();_.balance>0&&(u.push(_),o+=_.balance)}return{selectedCoins:vo.sortByBalance(u),remainingCoins:vo.sortByBalance(c)}}static sortByBalance(e){return e.sort((r,n)=>r.balance<n.balance?-1:r.balance>n.balance?1:0)}static sortByBalanceDes(e){return e.sort((r,n)=>r.balance>n.balance?-1:r.balance<n.balance?0:1)}static calculateTotalBalance(e){return e.reduce((r,n)=>r+n.balance,BigInt(0))}};function Ts(t){let e=t.indexOf("::");if(e===-1)return t;let r=t.substring(0,e),n=t.substring(e);if(!r.startsWith("0x"))return t;let i=r.substring(2);return i.length>64?t:`0x${i.padStart(64,"0")}${n}`}function Q6(t,e){return t.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]})}function eI(t,e){t=Ts(t),e=Ts(e);let r=Math.min(t.length,e.length);for(let n=0;n<r;n++){if(t[n]>e[n])return!0;if(t[n]<e[n])return!1}return!0}function XF(t){let e=/,([^,>]*>)/g,r=[...t.matchAll(e)];if(r.length>0){let n=r[r.length-1][1];return n.substring(0,n.length-1).trim()}return null}function JF(t){let e=/<([^>]*)>/,r=t.match(e);if(r)return r[1]}function ZF(t,e,r,n){let i=ki.getCoinAssets(n,e);if(r===BigInt(0))return ki.isSuiCoin(n)||i.length===0&&!ki.isSuiCoin(n)?{targetCoin:Q6(t,n),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:t.object(i[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(i[0].balance.toString())};if(ki.calculateTotalBalance(i)<r)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+n,"InsufficientBalance"+n);if(ki.isSuiCoin(n))return{targetCoin:t.splitCoins(t.gas,[t.pure.u64(r.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(r.toString())};let o=ki.sortByBalance(i);o.slice(0,3).reduce((b,O)=>b+O.balance,BigInt(0))<BigInt(r)&&(o=ki.sortByBalanceDes(i));let c=ki.selectCoinObjectIdGreaterThanOrEqual(o,r),[d,...p]=c.objectArray;return p.length>0&&t.mergeCoins(d,p.map(b=>t.object(b))),{targetCoin:t.splitCoins(t.object(d),[t.pure.u64(r.toString())]),isMintZeroCoin:!1,targetCoinAmount:Number(r.toString())}}var Cc=su(ou()),da=new Cc.default(0),YF=new Cc.default(1),tI=new Cc.default(2),QF=tI.pow(new Cc.default(128)),eq=new Cc.default("18446744073709551615"),Zf="18446744073709551615",tq=1e9,rq="aggregator",nq="CETUS",iq="DEEPBOOK",sq="KRIYA",oq="FLOWX",aq="TURBOS",uq="AFTERMATH",cq="integrate",lq="cetus",fq="deepbook",dq="kriya",hq="utils",pq="pool",mq="pay",gq="flowx_amm",yq="turbos",_q="aftermath",rI="custodian_v2",nI="clob_v2",vq="flash_swap",bq="flash_swap_with_partner",wq="repay_flash_swap",Mq="repay_flash_swap_with_partner",Sq="flash_swap_a2b",kq="flash_swap_b2a",Oq="flash_swap_with_partner_a2b",Eq="flash_swap_with_partner_b2a",Aq="repay_flash_swap_a2b",Iq="repay_flash_swap_b2a",Tq="repay_flash_swap_with_partner_a2b",xq="repay_flash_swap_with_partner_b2a",Pq="swap_a2b",Cq="swap_b2a",jq="transfer_or_destroy_coin",Nq="check_coins_threshold",Dq="join_vec",Bq="transfer_account_cap",Rq="0x0000000000000000000000000000000000000000000000000000000000000006",Uq="0x1::coin::CoinInfo",Lq="0x1::coin::CoinStore",$q="0x2::coin::zero",iI="0x000000000000000000000000000000000000000000000000000000000000dee9",sI="0x000000000000000000000000000000000000000000000000000000000000dee9",Fq="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",oI="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",qq="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",Vq="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",zq="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",Gq="",Hq="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",Wq="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",Kq="",Xq="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",Jq="",Zq="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",Yq="",Qq="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",eV="",tV="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",rV="",Tc={AGGREGATOR_V3:"aggregator_v3"},nV="https://api-sui.cetus.zone/router_v3",iV="https://api-sui.cetus.zone/router_v2",sV={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},nd={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},xc={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},As={DEFAULT_PYTH_URL:"https://hermes.pyth.network",PYTH_TIMEOUT:3e3,MAX_OVERLAY_FEE_RATE:.1,FEE_RATE_MULTIPLIER:1e6,DEFAULT_OVERLAY_FEE_RECEIVER:"0x0",ERRORS:{SIGNER_REQUIRED:"Signer is required, but not provided.",INVALID_OVERLAY_FEE_RATE:"Overlay fee rate must be between 0 and 0.1",INVALID_SLIPPAGE:"Invalid slippage value. Must be between 0 and 1 (e.g., 0.01 represents 1% slippage)",NO_ROUTER_FOUND:"No router found",EMPTY_PATH:"Empty path",UNSUPPORTED_DEX:"Unsupported dex",PYTH_UNAVAILABLE:"All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",QUOTE_ID_REQUIRED:"Quote ID is required",AGGREGATOR_V3_PACKAGE_REQUIRED:"Aggregator V3 package is required",PACKAGES_REQUIRED:"Packages are required"}},At={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:Zf,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},aI=1010102;function oV(t,e){let r=new Map;return t.packages&&(t.packages instanceof Map?r=t.packages:typeof t.packages=="object"&&Object.entries(t.packages).forEach(([n,i])=>{r.set(n,i)})),{quoteID:t.request_id||"",amountIn:new tu.default(t.amount_in.toString()),amountOut:new tu.default(t.amount_out.toString()),byAmountIn:e,insufficientLiquidity:!1,packages:r,paths:t.paths.map(n=>({id:n.id,direction:n.direction,provider:n.provider,from:n.from,target:n.target,feeRate:n.fee_rate,amountIn:n.amount_in.toString(),amountOut:n.amount_out.toString(),version:n.version,publishedAt:n.published_at,extendedDetails:n.extended_details}))}}function uI(t,e,r,n,i){return Br(this,null,function*(){let s;if(r.liquidityChanges&&r.liquidityChanges.length>0?s=yield uV(t,r):s=yield aV(t,e,r),!s)return null;if(!s.ok){let c=1e3;return s.status===429&&(c=1001),{quoteID:"",amountIn:da,amountOut:da,paths:[],byAmountIn:r.byAmountIn,insufficientLiquidity:!1,deviationRatio:0,error:{code:c,msg:Kf(c)}}}let o=MF.default.parse(yield s.text()),u=o.msg==="liquidity is not enough";if(o.msg&&o.msg.indexOf("HoneyPot scam")>-1)return{quoteID:"",amountIn:da,amountOut:da,paths:[],byAmountIn:r.byAmountIn,insufficientLiquidity:u,deviationRatio:0,error:{code:1003,msg:Kf(1003)}};if(o.data!=null){let c=oV(o.data,r.byAmountIn);if(n>0&&i!=="0x0")if(r.byAmountIn){let d=c.amountOut.mul(new tu.default(n)).div(new tu.default(1e6));c.overlayFee=Number(d.toString()),c.amountOut=c.amountOut.sub(d)}else{let d=c.amountIn.mul(new tu.default(n)).div(new tu.default(1e6));c.overlayFee=Number(d.toString()),c.amountIn=c.amountIn.add(d)}return c.packages||(c.packages=new Map),c.packages.has("aggregator_v3")||c.packages.set("aggregator_v3","0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"),c}return{quoteID:"",amountIn:da,amountOut:da,paths:[],insufficientLiquidity:u,byAmountIn:r.byAmountIn,deviationRatio:0,error:{code:1002,msg:Kf(1002)}}})}function aV(t,e,r){return Br(this,null,function*(){try{let{from:n,target:i,amount:s,byAmountIn:o,depth:u,splitAlgorithm:c,splitFactor:d,splitCount:p,providers:_}=r,b=Ts(n),O=Ts(i),T=`${t}/find_routes?from=${b}&target=${O}&amount=${s.toString()}&by_amount_in=${o}`;return u&&(T+=`&depth=${u}`),c&&(T+=`&split_algorithm=${c}`),d&&(T+=`&split_factor=${d}`),p&&(T+=`&split_count=${p}`),_&&_.length>0&&(T+=`&providers=${_.join(",")}`),e.length>0&&(T+=`&apiKey=${e}`),T+=`&v=${aI}`,console.log("url",T),yield fetch(T)}catch(n){return console.error(n),null}})}function uV(t,e){return Br(this,null,function*(){let{from:r,target:n,amount:i,byAmountIn:s,depth:o,splitAlgorithm:u,splitFactor:c,splitCount:d,providers:p,liquidityChanges:_}=e,b=Ts(r),O=Ts(n),T=`${t}/find_routes`,x=p?.join(","),F={from:b,target:O,amount:Number(i.toString()),by_amount_in:s,depth:o,split_algorithm:u,split_factor:c,split_count:d,providers:x,liquidity_changes:_.map(R=>({pool:R.poolID,tick_lower:R.ticklower,tick_upper:R.tickUpper,delta_liquidity:R.deltaLiquidity})),v:aI};try{return yield fetch(T,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)})}catch(R){return console.error("Error:",R),null}})}function cV(t){return Br(this,null,function*(){let e=`${t}/deepbookv3_config`;try{return(yield fetch(e)).json()}catch(r){return console.error("Error:",r),null}})}function iy(t){let e=t.paths,r=e[0].from,n=e[e.length-1].target,i=[];for(let o of e)i.push({path:o,isLastUseOfIntermediateToken:!1});let s=new Map;for(let o=i.length-1;o>=0;o--){let{from:u}=i[o].path;s.has(u)||(s.set(u,!0),i[o].isLastUseOfIntermediateToken=!0)}return console.log("flattenedPaths",i),{quoteID:t.quoteID||"",amountIn:t.amountIn,amountOut:t.amountOut,byAmountIn:t.byAmountIn,flattenedPaths:i,fromCoinType:r,targetCoinType:n,packages:t.packages,totalDeepFee:t.totalDeepFee,error:t.error,overlayFee:t.overlayFee}}var cI=(t=>(t[t.Mainnet=0]="Mainnet",t[t.Testnet=1]="Testnet",t))(cI||{}),lV=class{constructor(t,e,r,n){this.endpoint=t,this.fullNodeUrl=e,this.signer=r,this.env=n}getAggregatorUrl(){return this.endpoint}getFullNodeUrl(){return this.fullNodeUrl}getWallet(){return this.signer}getENV(){return this.env}},fV=su(ou()),ru=9e15,So=1e9,sy="0123456789abcdef",Yf="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Qf="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",oy={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ru,maxE:ru,crypto:!1},lI,Is,at=!0,id="[DecimalError] ",Mo=id+"Invalid argument: ",fI=id+"Precision limit exceeded",dI=id+"crypto unavailable",hI="[object Decimal]",Jr=Math.floor,kr=Math.pow,dV=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,hV=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,pV=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,pI=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ei=1e7,Ye=7,mV=9007199254740991,gV=Yf.length-1,ay=Qf.length-1,fe={toStringTag:hI};fe.absoluteValue=fe.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),Ge(t)};fe.ceil=function(){return Ge(new this.constructor(this),this.e+1,2)};fe.clampedTo=fe.clamp=function(t,e){var r,n=this,i=n.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(Mo+e);return r=n.cmp(t),r<0?t:n.cmp(e)>0?e:new i(n)};fe.comparedTo=fe.cmp=function(t){var e,r,n,i,s=this,o=s.d,u=(t=new s.constructor(t)).d,c=s.s,d=t.s;if(!o||!u)return!c||!d?NaN:c!==d?c:o===u?0:!o^c<0?1:-1;if(!o[0]||!u[0])return o[0]?c:u[0]?-d:0;if(c!==d)return c;if(s.e!==t.e)return s.e>t.e^c<0?1:-1;for(n=o.length,i=u.length,e=0,r=n<i?n:i;e<r;++e)if(o[e]!==u[e])return o[e]>u[e]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};fe.cosine=fe.cos=function(){var t,e,r=this,n=r.constructor;return r.d?r.d[0]?(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Ye,n.rounding=1,r=yV(n,vI(n,r)),n.precision=t,n.rounding=e,Ge(Is==2||Is==3?r.neg():r,t,e,!0)):new n(1):new n(NaN)};fe.cubeRoot=fe.cbrt=function(){var t,e,r,n,i,s,o,u,c,d,p=this,_=p.constructor;if(!p.isFinite()||p.isZero())return new _(p);for(at=!1,s=p.s*kr(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Rr(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=kr(r,1/3),t=Jr((t+1)/3)-(t%3==(t<0?-1:2)),s==1/0?r="5e"+t:(r=s.toExponential(),r=r.slice(0,r.indexOf("e")+1)+t),n=new _(r),n.s=p.s):n=new _(s.toString()),o=(t=_.precision)+3;;)if(u=n,c=u.times(u).times(u),d=c.plus(p),n=Nt(d.plus(p).times(u),d.plus(c),o+2,1),Rr(u.d).slice(0,o)===(r=Rr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(Ge(u,t+1,0),u.times(u).times(u).eq(p))){n=u;break}o+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(Ge(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return at=!0,Ge(n,t,_.rounding,e)};fe.decimalPlaces=fe.dp=function(){var t,e=this.d,r=NaN;if(e){if(t=e.length-1,r=(t-Jr(this.e/Ye))*Ye,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};fe.dividedBy=fe.div=function(t){return Nt(this,new this.constructor(t))};fe.dividedToIntegerBy=fe.divToInt=function(t){var e=this,r=e.constructor;return Ge(Nt(e,new r(t),0,1,1),r.precision,r.rounding)};fe.equals=fe.eq=function(t){return this.cmp(t)===0};fe.floor=function(){return Ge(new this.constructor(this),this.e+1,3)};fe.greaterThan=fe.gt=function(t){return this.cmp(t)>0};fe.greaterThanOrEqualTo=fe.gte=function(t){var e=this.cmp(t);return e==1||e===0};fe.hyperbolicCosine=fe.cosh=function(){var t,e,r,n,i,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;r=o.precision,n=o.rounding,o.precision=r+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(t=Math.ceil(i/3),e=(1/od(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=iu(o,1,s.times(e),new o(1),!0);for(var c,d=t,p=new o(8);d--;)c=s.times(s),s=u.minus(c.times(p.minus(c.times(p))));return Ge(s,o.precision=r,o.rounding=n,!0)};fe.hyperbolicSine=fe.sinh=function(){var t,e,r,n,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(e=s.precision,r=s.rounding,s.precision=e+Math.max(i.e,i.sd())+4,s.rounding=1,n=i.d.length,n<3)i=iu(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/od(5,t)),i=iu(s,2,i,i,!0);for(var o,u=new s(5),c=new s(16),d=new s(20);t--;)o=i.times(i),i=i.times(u.plus(o.times(c.times(o).plus(d))))}return s.precision=e,s.rounding=r,Ge(i,e,r,!0)};fe.hyperbolicTangent=fe.tanh=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+7,n.rounding=1,Nt(r.sinh(),r.cosh(),n.precision=t,n.rounding=e)):new n(r.s)};fe.inverseCosine=fe.acos=function(){var t,e=this,r=e.constructor,n=e.abs().cmp(1),i=r.precision,s=r.rounding;return n!==-1?n===0?e.isNeg()?Oi(r,i,s):new r(0):new r(NaN):e.isZero()?Oi(r,i+4,s).times(.5):(r.precision=i+6,r.rounding=1,e=e.asin(),t=Oi(r,i+4,s).times(.5),r.precision=i,r.rounding=s,t.minus(e))};fe.inverseHyperbolicCosine=fe.acosh=function(){var t,e,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(t=n.precision,e=n.rounding,n.precision=t+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,at=!1,r=r.times(r).minus(1).sqrt().plus(r),at=!0,n.precision=t,n.rounding=e,r.ln()):new n(r)};fe.inverseHyperbolicSine=fe.asinh=function(){var t,e,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,at=!1,r=r.times(r).plus(1).sqrt().plus(r),at=!0,n.precision=t,n.rounding=e,r.ln())};fe.inverseHyperbolicTangent=fe.atanh=function(){var t,e,r,n,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=s.precision,e=s.rounding,n=i.sd(),Math.max(n,t)<2*-i.e-1?Ge(new s(i),t,e,!0):(s.precision=r=n-i.e,i=Nt(i.plus(1),new s(1).minus(i),r+t,1),s.precision=t+4,s.rounding=1,i=i.ln(),s.precision=t,s.rounding=e,i.times(.5))):new s(NaN)};fe.inverseSine=fe.asin=function(){var t,e,r,n,i=this,s=i.constructor;return i.isZero()?new s(i):(e=i.abs().cmp(1),r=s.precision,n=s.rounding,e!==-1?e===0?(t=Oi(s,r+4,n).times(.5),t.s=i.s,t):new s(NaN):(s.precision=r+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=n,i.times(2)))};fe.inverseTangent=fe.atan=function(){var t,e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding;if(d.isFinite()){if(d.isZero())return new p(d);if(d.abs().eq(1)&&_+4<=ay)return o=Oi(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=ay)return o=Oi(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/Ye+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(at=!1,e=Math.ceil(u/Ye),n=1,c=d.times(d),o=new p(d),i=d;t!==-1;)if(i=i.times(c),s=o.minus(i.div(n+=2)),i=i.times(c),o=s.plus(i.div(n+=2)),o.d[e]!==void 0)for(t=e;o.d[t]===s.d[t]&&t--;);return r&&(o=o.times(2<<r-1)),at=!0,Ge(o,p.precision=_,p.rounding=b,!0)};fe.isFinite=function(){return!!this.d};fe.isInteger=fe.isInt=function(){return!!this.d&&Jr(this.e/Ye)>this.d.length-2};fe.isNaN=function(){return!this.s};fe.isNegative=fe.isNeg=function(){return this.s<0};fe.isPositive=fe.isPos=function(){return this.s>0};fe.isZero=function(){return!!this.d&&this.d[0]===0};fe.lessThan=fe.lt=function(t){return this.cmp(t)<0};fe.lessThanOrEqualTo=fe.lte=function(t){return this.cmp(t)<1};fe.logarithm=fe.log=function(t){var e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding,O=5;if(t==null)t=new p(10),e=!0;else{if(t=new p(t),r=t.d,t.s<0||!r||!r[0]||t.eq(1))return new p(NaN);e=t.eq(10)}if(r=d.d,d.s<0||!r||!r[0]||d.eq(1))return new p(r&&!r[0]?-1/0:d.s!=1?NaN:r?0:1/0);if(e)if(r.length>1)s=!0;else{for(i=r[0];i%10===0;)i/=10;s=i!==1}if(at=!1,u=_+O,o=wo(d,u),n=e?ed(p,u+10):wo(t,u),c=Nt(o,n,u,1),Pc(c.d,i=_,b))do if(u+=10,o=wo(d,u),n=e?ed(p,u+10):wo(t,u),c=Nt(o,n,u,1),!s){+Rr(c.d).slice(i+1,i+15)+1==1e14&&(c=Ge(c,_+1,0));break}while(Pc(c.d,i+=10,b));return at=!0,Ge(c,_,b)};fe.minus=fe.sub=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.constructor;if(t=new T(t),!O.d||!t.d)return!O.s||!t.s?t=new T(NaN):O.d?t.s=-t.s:t=new T(t.d||O.s!==t.s?O:NaN),t;if(O.s!=t.s)return t.s=-t.s,O.plus(t);if(d=O.d,b=t.d,u=T.precision,c=T.rounding,!d[0]||!b[0]){if(b[0])t.s=-t.s;else if(d[0])t=new T(O);else return new T(c===3?-0:0);return at?Ge(t,u,c):t}if(r=Jr(t.e/Ye),p=Jr(O.e/Ye),d=d.slice(),s=p-r,s){for(_=s<0,_?(e=d,s=-s,o=b.length):(e=b,r=p,o=d.length),n=Math.max(Math.ceil(u/Ye),o)+2,s>n&&(s=n,e.length=1),e.reverse(),n=s;n--;)e.push(0);e.reverse()}else{for(n=d.length,o=b.length,_=n<o,_&&(o=n),n=0;n<o;n++)if(d[n]!=b[n]){_=d[n]<b[n];break}s=0}for(_&&(e=d,d=b,b=e,t.s=-t.s),o=d.length,n=b.length-o;n>0;--n)d[o++]=0;for(n=b.length;n>s;){if(d[--n]<b[n]){for(i=n;i&&d[--i]===0;)d[i]=Ei-1;--d[i],d[n]+=Ei}d[n]-=b[n]}for(;d[--o]===0;)d.pop();for(;d[0]===0;d.shift())--r;return d[0]?(t.d=d,t.e=sd(d,r),at?Ge(t,u,c):t):new T(c===3?-0:0)};fe.modulo=fe.mod=function(t){var e,r=this,n=r.constructor;return t=new n(t),!r.d||!t.s||t.d&&!t.d[0]?new n(NaN):!t.d||r.d&&!r.d[0]?Ge(new n(r),n.precision,n.rounding):(at=!1,n.modulo==9?(e=Nt(r,t.abs(),0,3,1),e.s*=t.s):e=Nt(r,t,0,n.modulo,1),e=e.times(t),at=!0,r.minus(e))};fe.naturalExponential=fe.exp=function(){return uy(this)};fe.naturalLogarithm=fe.ln=function(){return wo(this)};fe.negated=fe.neg=function(){var t=new this.constructor(this);return t.s=-t.s,Ge(t)};fe.plus=fe.add=function(t){var e,r,n,i,s,o,u,c,d,p,_=this,b=_.constructor;if(t=new b(t),!_.d||!t.d)return!_.s||!t.s?t=new b(NaN):_.d||(t=new b(t.d||_.s===t.s?_:NaN)),t;if(_.s!=t.s)return t.s=-t.s,_.minus(t);if(d=_.d,p=t.d,u=b.precision,c=b.rounding,!d[0]||!p[0])return p[0]||(t=new b(_)),at?Ge(t,u,c):t;if(s=Jr(_.e/Ye),n=Jr(t.e/Ye),d=d.slice(),i=s-n,i){for(i<0?(r=d,i=-i,o=p.length):(r=p,n=s,o=d.length),s=Math.ceil(u/Ye),o=s>o?s+1:o+1,i>o&&(i=o,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(o=d.length,i=p.length,o-i<0&&(i=o,r=p,p=d,d=r),e=0;i;)e=(d[--i]=d[i]+p[i]+e)/Ei|0,d[i]%=Ei;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=sd(d,n),at?Ge(t,u,c):t};fe.precision=fe.sd=function(t){var e,r=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Mo+t);return r.d?(e=mI(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};fe.round=function(){var t=this,e=t.constructor;return Ge(new e(t),t.e+1,e.rounding)};fe.sine=fe.sin=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Ye,n.rounding=1,r=vV(n,vI(n,r)),n.precision=t,n.rounding=e,Ge(Is>2?r.neg():r,t,e,!0)):new n(NaN)};fe.squareRoot=fe.sqrt=function(){var t,e,r,n,i,s,o=this,u=o.d,c=o.e,d=o.s,p=o.constructor;if(d!==1||!u||!u[0])return new p(!d||d<0&&(!u||u[0])?NaN:u?o:1/0);for(at=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Rr(u),(e.length+c)%2==0&&(e+="0"),d=Math.sqrt(e),c=Jr((c+1)/2)-(c<0||c%2),d==1/0?e="5e"+c:(e=d.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),n=new p(e)):n=new p(d.toString()),r=(c=p.precision)+3;;)if(s=n,n=s.plus(Nt(o,s,r+2,1)).times(.5),Rr(s.d).slice(0,r)===(e=Rr(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(Ge(s,c+1,0),s.times(s).eq(o))){n=s;break}r+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(Ge(n,c+1,1),t=!n.times(n).eq(o));break}return at=!0,Ge(n,c,p.rounding,t)};fe.tangent=fe.tan=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+10,n.rounding=1,r=r.sin(),r.s=1,r=Nt(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,Ge(Is==2||Is==4?r.neg():r,t,e,!0)):new n(NaN)};fe.times=fe.mul=function(t){var e,r,n,i,s,o,u,c,d,p=this,_=p.constructor,b=p.d,O=(t=new _(t)).d;if(t.s*=p.s,!b||!b[0]||!O||!O[0])return new _(!t.s||b&&!b[0]&&!O||O&&!O[0]&&!b?NaN:!b||!O?t.s/0:t.s*0);for(r=Jr(p.e/Ye)+Jr(t.e/Ye),c=b.length,d=O.length,c<d&&(s=b,b=O,O=s,o=c,c=d,d=o),s=[],o=c+d,n=o;n--;)s.push(0);for(n=d;--n>=0;){for(e=0,i=c+n;i>n;)u=s[i]+O[n]*b[i-n-1]+e,s[i--]=u%Ei|0,e=u/Ei|0;s[i]=(s[i]+e)%Ei|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=sd(s,r),at?Ge(t,_.precision,_.rounding):t};fe.toBinary=function(t,e){return dy(this,2,t,e)};fe.toDecimalPlaces=fe.toDP=function(t,e){var r=this,n=r.constructor;return r=new n(r),t===void 0?r:(mn(t,0,So),e===void 0?e=n.rounding:mn(e,0,8),Ge(r,t+r.e+1,e))};fe.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ts(n,!0):(mn(t,0,So),e===void 0?e=i.rounding:mn(e,0,8),n=Ge(new i(n),t+1,e),r=ts(n,!0,t+1)),n.isNeg()&&!n.isZero()?"-"+r:r};fe.toFixed=function(t,e){var r,n,i=this,s=i.constructor;return t===void 0?r=ts(i):(mn(t,0,So),e===void 0?e=s.rounding:mn(e,0,8),n=Ge(new s(i),t+i.e+1,e),r=ts(n,!1,t+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};fe.toFraction=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.d,x=O.constructor;if(!T)return new x(O);if(d=r=new x(1),n=c=new x(0),e=new x(n),s=e.e=mI(T)-O.e-1,o=s%Ye,e.d[0]=kr(10,o<0?Ye+o:o),t==null)t=s>0?e:d;else{if(u=new x(t),!u.isInt()||u.lt(d))throw Error(Mo+u);t=u.gt(e)?s>0?e:d:u}for(at=!1,u=new x(Rr(T)),p=x.precision,x.precision=s=T.length*Ye*2;_=Nt(u,e,0,1,1),i=r.plus(_.times(n)),i.cmp(t)!=1;)r=n,n=i,i=d,d=c.plus(_.times(i)),c=i,i=e,e=u.minus(_.times(i)),u=i;return i=Nt(t.minus(r),n,0,1,1),c=c.plus(i.times(d)),r=r.plus(i.times(n)),c.s=d.s=O.s,b=Nt(d,n,s,1).minus(O).abs().cmp(Nt(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,at=!0,b};fe.toHexadecimal=fe.toHex=function(t,e){return dy(this,16,t,e)};fe.toNearest=function(t,e){var r=this,n=r.constructor;if(r=new n(r),t==null){if(!r.d)return r;t=new n(1),e=n.rounding}else{if(t=new n(t),e===void 0?e=n.rounding:mn(e,0,8),!r.d)return t.s?r:t;if(!t.d)return t.s&&(t.s=r.s),t}return t.d[0]?(at=!1,r=Nt(r,t,0,e,1).times(t),at=!0,Ge(r)):(t.s=r.s,r=t),r};fe.toNumber=function(){return+this};fe.toOctal=function(t,e){return dy(this,8,t,e)};fe.toPower=fe.pow=function(t){var e,r,n,i,s,o,u=this,c=u.constructor,d=+(t=new c(t));if(!u.d||!t.d||!u.d[0]||!t.d[0])return new c(kr(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return Ge(u,n,s);if(e=Jr(t.e/Ye),e>=t.d.length-1&&(r=d<0?-d:d)<=mV)return i=gI(c,u,r,n),t.s<0?new c(1).div(i):Ge(i,n,s);if(o=u.s,o<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(o=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=o,u}return r=kr(+u,d),e=r==0||!isFinite(r)?Jr(d*(Math.log("0."+Rr(u.d))/Math.LN10+u.e+1)):new c(r+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?o/0:0):(at=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=uy(t.times(wo(u,n+r)),n),i.d&&(i=Ge(i,n+5,1),Pc(i.d,n,s)&&(e=n+10,i=Ge(uy(t.times(wo(u,e+r)),e),e+5,1),+Rr(i.d).slice(n+1,n+15)+1==1e14&&(i=Ge(i,n+1,0)))),i.s=o,at=!0,c.rounding=s,Ge(i,n,s))};fe.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ts(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(mn(t,1,So),e===void 0?e=i.rounding:mn(e,0,8),n=Ge(new i(n),t,e),r=ts(n,t<=n.e||n.e<=i.toExpNeg,t)),n.isNeg()&&!n.isZero()?"-"+r:r};fe.toSignificantDigits=fe.toSD=function(t,e){var r=this,n=r.constructor;return t===void 0?(t=n.precision,e=n.rounding):(mn(t,1,So),e===void 0?e=n.rounding:mn(e,0,8)),Ge(new n(r),t,e)};fe.toString=function(){var t=this,e=t.constructor,r=ts(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};fe.truncated=fe.trunc=function(){return Ge(new this.constructor(this),this.e+1,1)};fe.valueOf=fe.toJSON=function(){var t=this,e=t.constructor,r=ts(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Rr(t){var e,r,n,i=t.length-1,s="",o=t[0];if(i>0){for(s+=o,e=1;e<i;e++)n=t[e]+"",r=Ye-n.length,r&&(s+=bo(r)),s+=n;o=t[e],n=o+"",r=Ye-n.length,r&&(s+=bo(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function mn(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Mo+t)}function Pc(t,e,r,n){var i,s,o,u;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=Ye,i=0):(i=Math.ceil((e+1)/Ye),e%=Ye),s=kr(10,Ye-e),u=t[i]%s|0,n==null?e<3?(e==0?u=u/100|0:e==1&&(u=u/10|0),o=r<4&&u==99999||r>3&&u==49999||u==5e4||u==0):o=(r<4&&u+1==s||r>3&&u+1==s/2)&&(t[i+1]/s/100|0)==kr(10,e-2)-1||(u==s/2||u==0)&&(t[i+1]/s/100|0)==0:e<4?(e==0?u=u/1e3|0:e==1?u=u/100|0:e==2&&(u=u/10|0),o=(n||r<4)&&u==9999||!n&&r>3&&u==4999):o=((n||r<4)&&u+1==s||!n&&r>3&&u+1==s/2)&&(t[i+1]/s/1e3|0)==kr(10,e-3)-1,o}function Xf(t,e,r){for(var n,i=[0],s,o=0,u=t.length;o<u;){for(s=i.length;s--;)i[s]*=e;for(i[0]+=sy.indexOf(t.charAt(o++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function yV(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/od(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=iu(t,1,e.times(i),new t(1));for(var s=r;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return t.precision-=r,e}var Nt=(function(){function t(n,i,s){var o,u=0,c=n.length;for(n=n.slice();c--;)o=n[c]*i+u,n[c]=o%s|0,u=o/s|0;return u&&n.unshift(u),n}function e(n,i,s,o){var u,c;if(s!=o)c=s>o?1:-1;else for(u=c=0;u<s;u++)if(n[u]!=i[u]){c=n[u]>i[u]?1:-1;break}return c}function r(n,i,s,o){for(var u=0;s--;)n[s]-=u,u=n[s]<i[s]?1:0,n[s]=u*o+n[s]-i[s];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,s,o,u,c){var d,p,_,b,O,T,x,F,R,H,J,ee,ae,te,he,A,I,C,D,N,k=n.constructor,m=n.s==i.s?1:-1,a=n.d,l=i.d;if(!a||!a[0]||!l||!l[0])return new k(!n.s||!i.s||(a?l&&a[0]==l[0]:!l)?NaN:a&&a[0]==0||!l?m*0:m/0);for(c?(O=1,p=n.e-i.e):(c=Ei,O=Ye,p=Jr(n.e/O)-Jr(i.e/O)),D=l.length,I=a.length,R=new k(m),H=R.d=[],_=0;l[_]==(a[_]||0);_++);if(l[_]>(a[_]||0)&&p--,s==null?(te=s=k.precision,o=k.rounding):u?te=s+(n.e-i.e)+1:te=s,te<0)H.push(1),T=!0;else{if(te=te/O+2|0,_=0,D==1){for(b=0,l=l[0],te++;(_<I||b)&&te--;_++)he=b*c+(a[_]||0),H[_]=he/l|0,b=he%l|0;T=b||_<I}else{for(b=c/(l[0]+1)|0,b>1&&(l=t(l,b,c),a=t(a,b,c),D=l.length,I=a.length),A=D,J=a.slice(0,D),ee=J.length;ee<D;)J[ee++]=0;N=l.slice(),N.unshift(0),C=l[0],l[1]>=c/2&&++C;do b=0,d=e(l,J,D,ee),d<0?(ae=J[0],D!=ee&&(ae=ae*c+(J[1]||0)),b=ae/C|0,b>1?(b>=c&&(b=c-1),x=t(l,b,c),F=x.length,ee=J.length,d=e(x,J,F,ee),d==1&&(b--,r(x,D<F?N:l,F,c))):(b==0&&(d=b=1),x=l.slice()),F=x.length,F<ee&&x.unshift(0),r(J,x,ee,c),d==-1&&(ee=J.length,d=e(l,J,D,ee),d<1&&(b++,r(J,D<ee?N:l,ee,c))),ee=J.length):d===0&&(b++,J=[0]),H[_++]=b,d&&J[0]?J[ee++]=a[A]||0:(J=[a[A]],ee=1);while((A++<I||J[0]!==void 0)&&te--);T=J[0]!==void 0}H[0]||H.shift()}if(O==1)R.e=p,lI=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,Ge(R,u?s+R.e+1:s,o,T)}return R}})();function Ge(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor;e:if(e!=null){if(_=t.d,!_)return t;for(i=1,u=_[0];u>=10;u/=10)i++;if(s=e-i,s<0)s+=Ye,o=e,p=_[b=0],c=p/kr(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/Ye),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=Ye,o=s-Ye+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=Ye,o=s-Ye+i,c=o<0?0:p/kr(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%kr(10,i-o-1)),d=r<4?(c||n)&&(r==0||r==(t.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(s>0?o>0?p/kr(10,i-o):0:_[b-1])%10&1||r==(t.s<0?8:7)),e<1||!_[0])return _.length=0,d?(e-=t.e+1,_[0]=kr(10,(Ye-e%Ye)%Ye),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=kr(10,Ye-s),_[b]=o>0?(p/kr(10,i-o)%kr(10,o)|0)*u:0),d)for(;;)if(b==0){for(s=1,o=_[0];o>=10;o/=10)s++;for(o=_[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(t.e++,_[0]==Ei&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=Ei)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return at&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function ts(t,e,r){if(!t.isFinite())return _I(t);var n,i=t.e,s=Rr(t.d),o=s.length;return e?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+bo(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):i<0?(s="0."+bo(-i-1)+s,r&&(n=r-o)>0&&(s+=bo(n))):i>=o?(s+=bo(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+bo(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=bo(n))),s}function sd(t,e){var r=t[0];for(e*=Ye;r>=10;r/=10)e++;return e}function ed(t,e,r){if(e>gV)throw at=!0,r&&(t.precision=r),Error(fI);return Ge(new t(Yf),e,1,!0)}function Oi(t,e,r){if(e>ay)throw Error(fI);return Ge(new t(Qf),e,r,!0)}function mI(t){var e=t.length-1,r=e*Ye+1;if(e=t[e],e){for(;e%10==0;e/=10)r--;for(e=t[0];e>=10;e/=10)r++}return r}function bo(t){for(var e="";t--;)e+="0";return e}function gI(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/Ye+4);for(at=!1;;){if(r%2&&(s=s.times(e),C6(s.d,o)&&(i=!0)),r=Jr(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}e=e.times(e),C6(e.d,o)}return at=!0,s}function P6(t){return t.d[t.d.length-1]&1}function yI(t,e,r){for(var n,i=new t(e[0]),s=0;++s<e.length;)if(n=new t(e[s]),n.s)i[r](n)&&(i=n);else{i=n;break}return i}function uy(t,e){var r,n,i,s,o,u,c,d=0,p=0,_=0,b=t.constructor,O=b.rounding,T=b.precision;if(!t.d||!t.d[0]||t.e>17)return new b(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:NaN);for(e==null?(at=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(kr(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=Ge(s.times(t),c,1),r=r.times(++p),u=o.plus(Nt(s,r,c,1)),Rr(u.d).slice(0,c)===Rr(o.d).slice(0,c)){for(i=_;i--;)o=Ge(o.times(o),c,1);if(e==null)if(d<3&&Pc(o.d,c-n,O,d))b.precision=c+=10,r=s=u=new b(1),p=0,d++;else return Ge(o,b.precision=T,O,at=!0);else return b.precision=T,o}o=u}}function wo(t,e){var r,n,i,s,o,u,c,d,p,_,b,O=1,T=10,x=t,F=x.d,R=x.constructor,H=R.rounding,J=R.precision;if(x.s<0||!F||!F[0]||!x.e&&F[0]==1&&F.length==1)return new R(F&&!F[0]?-1/0:x.s!=1?NaN:F?0:x);if(e==null?(at=!1,p=J):p=e,R.precision=p+=T,r=Rr(F),n=r.charAt(0),Math.abs(s=x.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)x=x.times(t),r=Rr(x.d),n=r.charAt(0),O++;s=x.e,n>1?(x=new R("0."+r),s++):x=new R(n+"."+r.slice(1))}else return d=ed(R,p+2,J).times(s+""),x=wo(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?Ge(x,J,H,at=!0):x;for(_=x,c=o=x=Nt(x.minus(1),x.plus(1),p,1),b=Ge(x.times(x),p,1),i=3;;){if(o=Ge(o.times(b),p,1),d=c.plus(Nt(o,new R(i),p,1)),Rr(d.d).slice(0,p)===Rr(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus(ed(R,p+2,J).times(s+""))),c=Nt(c,new R(O),p,1),e==null)if(Pc(c.d,p-T,H,u))R.precision=p+=T,d=o=x=Nt(_.minus(1),_.plus(1),p,1),b=Ge(x.times(x),p,1),i=u=1;else return Ge(c,R.precision=J,H,at=!0);else return R.precision=J,c;c=d,i+=2}}function _I(t){return String(t.s*t.s/0)}function cy(t,e){var r,n,i;for((r=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(r<0&&(r=n),r+=+e.slice(n+1),e=e.substring(0,n)):r<0&&(r=e.length),n=0;e.charCodeAt(n)===48;n++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(n,i),e){if(i-=n,t.e=r=r-n-1,t.d=[],n=(r+1)%Ye,r<0&&(n+=Ye),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=Ye;n<i;)t.d.push(+e.slice(n,n+=Ye));e=e.slice(n),n=Ye-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),at&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function _V(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),pI.test(e))return cy(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(hV.test(e))r=16,e=e.toLowerCase();else if(dV.test(e))r=2;else if(pV.test(e))r=8;else throw Error(Mo+e);for(s=e.search(/p/i),s>0?(c=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),s=e.indexOf("."),o=s>=0,n=t.constructor,o&&(e=e.replace(".",""),u=e.length,s=u-s,i=gI(n,new n(r),s,s*2)),d=Xf(e,r,Ei),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=sd(d,p),t.d=d,at=!1,o&&(t=Nt(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?kr(2,c):jc.pow(2,c))),at=!0,t)}function vV(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:iu(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/od(5,r)),e=iu(t,2,e,e);for(var i,s=new t(5),o=new t(16),u=new t(20);r--;)i=e.times(e),e=e.times(s.plus(i.times(o.times(i).minus(u))));return e}function iu(t,e,r,n,i){var s,o,u,c,d=t.precision,p=Math.ceil(d/Ye);for(at=!1,c=r.times(r),u=new t(n);;){if(o=Nt(u.times(c),new t(e++*e++),d,1),u=i?n.plus(o):n.minus(o),n=Nt(o.times(c),new t(e++*e++),d,1),o=u.plus(n),o.d[p]!==void 0){for(s=p;o.d[s]===u.d[s]&&s--;);if(s==-1)break}s=u,u=n,n=o,o=s}return at=!0,o.d.length=p+1,o}function od(t,e){for(var r=t;--e;)r*=t;return r}function vI(t,e){var r,n=e.s<0,i=Oi(t,t.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return Is=n?4:1,e;if(r=e.divToInt(i),r.isZero())Is=n?3:2;else{if(e=e.minus(r.times(i)),e.lte(s))return Is=P6(r)?n?2:3:n?4:1,e;Is=P6(r)?n?1:4:n?3:2}return e.minus(i).abs()}function dy(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor,T=r!==void 0;if(T?(mn(r,1,So),n===void 0?n=O.rounding:mn(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=_I(t);else{for(p=ts(t),o=p.indexOf("."),T?(i=2,e==16?r=r*4-3:e==8&&(r=r*3-2)):i=e,o>=0&&(p=p.replace(".",""),b=new O(1),b.e=p.length-o,b.d=Xf(ts(b),10,i),b.e=b.d.length),_=Xf(p,10,i),s=c=_.length;_[--c]==0;)_.pop();if(!_[0])p=T?"0p+0":"0";else{if(o<0?s--:(t=new O(t),t.d=_,t.e=s,t=Nt(t,b,r,n,0,i),_=t.d,s=t.e,d=lI),o=_[r],u=i/2,d=d||_[r+1]!==void 0,d=n<4?(o!==void 0||d)&&(n===0||n===(t.s<0?3:2)):o>u||o===u&&(n===4||d||n===6&&_[r-1]&1||n===(t.s<0?8:7)),_.length=r,d)for(;++_[--r]>i-1;)_[r]=0,r||(++s,_.unshift(1));for(c=_.length;!_[c-1];--c);for(o=0,p="";o<c;o++)p+=sy.charAt(_[o]);if(T){if(c>1)if(e==16||e==8){for(o=e==16?4:3,--c;c%o;c++)p+="0";for(_=Xf(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=sy.charAt(_[o])}else p=p.charAt(0)+"."+p.slice(1);p=p+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)p="0"+p;p="0."+p}else if(++s>c)for(s-=c;s--;)p+="0";else s<c&&(p=p.slice(0,s)+"."+p.slice(s))}p=(e==16?"0x":e==2?"0b":e==8?"0o":"")+p}return t.s<0?"-"+p:p}function C6(t,e){if(t.length>e)return t.length=e,!0}function bV(t){return new this(t).abs()}function wV(t){return new this(t).acos()}function MV(t){return new this(t).acosh()}function SV(t,e){return new this(t).plus(e)}function kV(t){return new this(t).asin()}function OV(t){return new this(t).asinh()}function EV(t){return new this(t).atan()}function AV(t){return new this(t).atanh()}function IV(t,e){t=new this(t),e=new this(e);var r,n=this.precision,i=this.rounding,s=n+4;return!t.s||!e.s?r=new this(NaN):!t.d&&!e.d?(r=Oi(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?Oi(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=Oi(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan(Nt(t,e,s,1)),e=Oi(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(Nt(t,e,s,1)),r}function TV(t){return new this(t).cbrt()}function xV(t){return Ge(t=new this(t),t.e+1,2)}function PV(t,e,r){return new this(t).clamp(e,r)}function CV(t){if(!t||typeof t!="object")throw Error(id+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,So,"rounding",0,8,"toExpNeg",-ru,0,"toExpPos",0,ru,"maxE",0,ru,"minE",-ru,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=oy[r]),(n=t[r])!==void 0)if(Jr(n)===n&&n>=s[e+1]&&n<=s[e+2])this[r]=n;else throw Error(Mo+r+": "+n);if(r="crypto",i&&(this[r]=oy[r]),(n=t[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(dI);else this[r]=!1;else throw Error(Mo+r+": "+n);return this}function jV(t){return new this(t).cos()}function NV(t){return new this(t).cosh()}function bI(t){var e,r,n;function i(s){var o,u,c,d=this;if(!(d instanceof i))return new i(s);if(d.constructor=i,j6(s)){d.s=s.s,at?!s.d||s.e>i.maxE?(d.e=NaN,d.d=null):s.e<i.minE?(d.e=0,d.d=[0]):(d.e=s.e,d.d=s.d.slice()):(d.e=s.e,d.d=s.d?s.d.slice():s.d);return}if(c=typeof s,c==="number"){if(s===0){d.s=1/s<0?-1:1,d.e=0,d.d=[0];return}if(s<0?(s=-s,d.s=-1):d.s=1,s===~~s&&s<1e7){for(o=0,u=s;u>=10;u/=10)o++;at?o>i.maxE?(d.e=NaN,d.d=null):o<i.minE?(d.e=0,d.d=[0]):(d.e=o,d.d=[s]):(d.e=o,d.d=[s]);return}else if(s*0!==0){s||(d.s=NaN),d.e=NaN,d.d=null;return}return cy(d,s.toString())}else if(c!=="string")throw Error(Mo+s);return(u=s.charCodeAt(0))===45?(s=s.slice(1),d.s=-1):(u===43&&(s=s.slice(1)),d.s=1),pI.test(s)?cy(d,s):_V(d,s)}if(i.prototype=fe,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=CV,i.clone=bI,i.isDecimal=j6,i.abs=bV,i.acos=wV,i.acosh=MV,i.add=SV,i.asin=kV,i.asinh=OV,i.atan=EV,i.atanh=AV,i.atan2=IV,i.cbrt=TV,i.ceil=xV,i.clamp=PV,i.cos=jV,i.cosh=NV,i.div=DV,i.exp=BV,i.floor=RV,i.hypot=UV,i.ln=LV,i.log=$V,i.log10=qV,i.log2=FV,i.max=VV,i.min=zV,i.mod=GV,i.mul=HV,i.pow=WV,i.random=KV,i.round=XV,i.sign=JV,i.sin=ZV,i.sinh=YV,i.sqrt=QV,i.sub=ez,i.sum=tz,i.tan=rz,i.tanh=nz,i.trunc=iz,t===void 0&&(t={}),t&&t.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)t.hasOwnProperty(r=n[e++])||(t[r]=this[r]);return i.config(t),i}function DV(t,e){return new this(t).div(e)}function BV(t){return new this(t).exp()}function RV(t){return Ge(t=new this(t),t.e+1,3)}function UV(){var t,e,r=new this(0);for(at=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)r.d&&(r=r.plus(e.times(e)));else{if(e.s)return at=!0,new this(1/0);r=e}return at=!0,r.sqrt()}function j6(t){return t instanceof jc||t&&t.toStringTag===hI||!1}function LV(t){return new this(t).ln()}function $V(t,e){return new this(t).log(e)}function FV(t){return new this(t).log(2)}function qV(t){return new this(t).log(10)}function VV(){return yI(this,arguments,"lt")}function zV(){return yI(this,arguments,"gt")}function GV(t,e){return new this(t).mod(e)}function HV(t,e){return new this(t).mul(e)}function WV(t,e){return new this(t).pow(e)}function KV(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:mn(t,1,So),n=Math.ceil(t/Ye),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));s<n;)i=e[s],i>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);s<n;)i=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((e[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,s):(u.push(i%1e7),s+=4);s=n/4}else throw Error(dI);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=Ye,n&&t&&(i=kr(10,Ye-t),u[s]=(n/i|0)*i);u[s]===0;s--)u.pop();if(s<0)r=0,u=[0];else{for(r=-1;u[0]===0;r-=Ye)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<Ye&&(r-=Ye-n)}return o.e=r,o.d=u,o}function XV(t){return Ge(t=new this(t),t.e+1,this.rounding)}function JV(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function ZV(t){return new this(t).sin()}function YV(t){return new this(t).sinh()}function QV(t){return new this(t).sqrt()}function ez(t,e){return new this(t).sub(e)}function tz(){var t=0,e=arguments,r=new this(e[t]);for(at=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return at=!0,Ge(r,this.precision,this.rounding)}function rz(t){return new this(t).tan()}function nz(t){return new this(t).tanh()}function iz(t){return Ge(t=new this(t),t.e+1,1)}fe[Symbol.for("nodejs.util.inspect.custom")]=fe.toString;fe[Symbol.toStringTag]="Decimal";var jc=fe.constructor=bI(oy);Yf=new jc(Yf);Qf=new jc(Qf);var td=jc;function sz(t,e,r){return Number(wI(new td(t.toString()),e,r).toFixed(0))}function N6(t,e,r){let n=wI(new td(t.toString()),e,r);return new fV.default(n.toFixed(0))}function wI(t,e,r){return e?t.mul(1-r):t.mul(1+r)}var D6=class{constructor(t,e){if(t!==0)throw new Error("CetusRouter only supported on mainnet");this.globalConfig=t===0?"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f":"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",this.partner=e??(t===0?"0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b":"0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("Cetus not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.globalConfig),t.object(e.poolId),t.object(this.partner),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::cetus::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}flashSwapFixedOutput(t,e,r,n){let i=[n,t.object(this.globalConfig),t.object(e.id),t.object(this.partner),r,t.pure.bool(e.direction),t.pure.bool(!1),t.object(Zt.SUI_CLOCK_OBJECT_ID)],[s,o]=e.direction?[e.from,e.target]:[e.target,e.from],[u,c]=t.moveCall({target:`${e.publishedAt}::cetus::flash_swap_fixed_output`,typeArguments:[s,o],arguments:i});return{flashReceipt:u,repayAmount:c}}repayFlashSwapFixedOutput(t,e,r,n){let i=[r,t.object(this.globalConfig),t.object(e.id),t.object(this.partner),t.pure.bool(e.direction),n],[s,o]=e.direction?[e.from,e.target]:[e.target,e.from];t.moveCall({target:`${e.publishedAt}::cetus::repay_flash_swap_fixed_output`,typeArguments:[s,o],arguments:i})}add(t,e,r,n){let i=[e,r];return t.moveCall({target:`${n}::cetus::add`,typeArguments:[],arguments:i})}sub(t,e,r,n){let i=[e,r];return t.moveCall({target:`${n}::cetus::sub`,typeArguments:[],arguments:i})}},oz=class{constructor(t){if(t!==0)throw new Error("Kriya V3 only supported on mainnet");this.version="0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("Kriya V3 not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(this.version),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::kriya_clmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},az=class{constructor(t){if(t!==0)throw new Error("FlowX V3 only supported on mainnet");this.poolRegistry="0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc",this.versioned="0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("FlowX V3 not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,s=e.feeRate*1e6;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id,feeRate:s}}executeSwapContract(t,e,r){let n=[r,t.object(this.poolRegistry),t.object(this.versioned),t.pure.u64(e.feeRate),t.pure.u64(e.amountIn),t.pure.bool(e.direction),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::flowx_clmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},uz=class{constructor(t){if(t!==0)throw new Error("Turbos only supported on mainnet");this.versioned="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("Turbos not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;if(e.extendedDetails==null)throw new Error("Extended details not supported");if(e.extendedDetails.turbos_fee_type==null)throw new Error("Turbos fee type not supported");let s=e.extendedDetails.turbos_fee_type;return{coinAType:r,coinBType:n,feeType:s,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(this.versioned),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::turbos::swap`,typeArguments:[e.coinAType,e.coinBType,e.feeType],arguments:n})}},cz=class{constructor(t){if(t!==0)throw new Error("Bluefin only supported on mainnet");this.globalConfig="0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("Bluefin not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.globalConfig),t.object(e.poolId),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::bluefin::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},lz=class{constructor(t){if(t!==0)throw new Error("Momentum only supported on mainnet");this.version="0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Momentum not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(this.version),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::momentum::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},fz=class{constructor(t){if(t!==0)throw new Error("Magma only supported on mainnet");this.globalConfig="0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Magma not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.globalConfig),t.object(e.poolId),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::magma::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},dz=class{constructor(t){if(t!==0)throw new Error("Kriya V2 only supported on mainnet")}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Kriya V2 not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::kriya_amm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},hz=class{constructor(t){if(t!==0)throw new Error("FlowX V2 only supported on mainnet");this.container="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("FlowX V2 not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.container),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::flowx_amm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},pz=class{constructor(t){if(t!==0)throw new Error("BlueMove only supported on mainnet");this.dexInfo="0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("BlueMove not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.dexInfo),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::bluemove::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},mz=class{constructor(t){if(t!==0)throw new Error("DeepBook V3 only supported on mainnet");this.env=t,this.globalConfig="0x699d455ab8c5e02075b4345ea1f91be55bf46064ae6026cc2528e701ce3ac135"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r,n)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("DeepBook V3 not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r,n){let i=n?.deepbookv3DeepFee||t.moveCall({target:"0x2::coin::zero",typeArguments:[this.getDeepFeeType()]}),s=[r,t.object(this.globalConfig),t.object(e.poolId),t.pure.u64(e.amountIn),t.pure.bool(e.direction),i,t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::deepbookv3::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?xc.Mainnet:xc.Testnet}},gz=class{constructor(t){if(t!==0)throw new Error("Aftermath only supported on mainnet");this.poolRegistry="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",this.protocolFeeVault="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",this.treasury="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",this.insuranceFund="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",this.referralVault="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){var e,r;if(t.path.publishedAt==null)throw new Error("Aftermath not set publishedAt");let n=t.path,[i,s]=n.direction?[n.from,n.target]:[n.target,n.from],o=t.isLastUseOfIntermediateToken?"18446744073709551615":n.amountIn;return{coinAType:i,coinBType:s,feeType:((e=n.extendedDetails)==null?void 0:e.aftermath_lp_supply_type)||((r=n.extendedDetails)==null?void 0:r.aftermath_lp_supply_type)||"0x2::sui::SUI",direction:n.direction,amountIn:o,expectAmountOut:n.amountOut,publishedAt:n.publishedAt,poolId:n.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(this.poolRegistry),t.object(this.protocolFeeVault),t.object(this.treasury),t.object(this.insuranceFund),t.object(this.referralVault),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.pure.u64(e.expectAmountOut)];t.moveCall({target:`${e.publishedAt}::aftermath::swap`,typeArguments:[e.coinAType,e.coinBType,e.feeType],arguments:n})}},yz=class{constructor(t){if(t!==0)throw new Error("Steamm CPMM only supported on mainnet")}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}validateExtendedDetails(t){let e=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type"];for(let r of e)if(t[r]==null)throw new Error(`Steamm CPMM ${r} not supported`)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Steamm CPMM not set publishedAt");if(!e.extendedDetails)throw new Error("Extended details not found for Steamm CPMM");this.validateExtendedDetails(e.extendedDetails);let{direction:r,from:n,target:i}=e,[s,o]=r?[n,i]:[i,n],u=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:s,coinBType:o,direction:r,amountIn:u,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:e.extendedDetails}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(e.extendedDetails.steamm_bank_a),t.object(e.extendedDetails.steamm_bank_b),t.object(e.extendedDetails.steamm_lending_market),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::steamm_cpmm::swap`,typeArguments:[e.extendedDetails.steamm_lending_market_type,e.coinAType,e.coinBType,e.extendedDetails.steamm_btoken_a_type,e.extendedDetails.steamm_btoken_b_type,e.extendedDetails.steamm_lp_token_type],arguments:n})}},_z=class{constructor(t){if(t!==0)throw new Error("Scallop only supported on mainnet");this.version="0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",this.marketData="0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Scallop not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.from,e.target],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;if(e.extendedDetails==null)throw new Error("Extended details not supported");let s=e.extendedDetails.scallopScoinTreasury||e.extendedDetails.scallop_scoin_treasury;if(s==null)throw new Error("Scallop scoin treasury not supported");return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id,scallopScoinTreasury:s}}executeSwapContract(t,e,r){let n=[r,t.object(this.version),t.object(this.marketData),t.object(e.scallopScoinTreasury),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)],i=e.direction?"swap_a2b":"swap_b2a";t.moveCall({target:`${e.publishedAt}::scallop::${i}`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},B6=class{constructor(t){if(t!==0)throw new Error("Springsui only supported on mainnet")}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Springsui not set publishedAt");let r=e.direction?e.target:e.from,n=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{springSUICoinType:r,direction:e.direction,amountIn:n,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object("0x5"),t.pure.u64(e.amountIn),t.pure.bool(e.direction)];t.moveCall({target:`${e.publishedAt}::springsui::swap`,typeArguments:[e.springSUICoinType],arguments:n})}},vz=class{constructor(t,e){if(t!==0)throw new Error("Haedal PMM only supported on mainnet");this.pythPriceIDs=e}swap(t,e,r,n){let i=e.path;if(!i.extendedDetails)throw new Error("Extended details not found for Haedal PMM");this.validateExtendedDetails(i.extendedDetails);let s=this.prepareSwapData(e);this.executeSwapContract(t,s,r)}validateExtendedDetails(t){if(!t.haedal_pmm_base_price_seed)throw new Error("Haedal PMM base price seed not supported");if(!t.haedal_pmm_quote_price_seed)throw new Error("Haedal PMM quote price seed not supported")}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Haedal PMM not set publishedAt");let r=e.extendedDetails,[n,i]=e.direction?[e.from,e.target]:[e.target,e.from],s=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,o=r.haedal_pmm_base_price_seed,u=r.haedal_pmm_quote_price_seed,c=this.pythPriceIDs.get(o),d=this.pythPriceIDs.get(u);if(!c||!d)throw new Error("Haedal HMM requires oracle price IDs for both coins");return{coinAType:n,coinBType:i,basePriceId:c,quotePriceId:d,a2b:e.direction,amountIn:s,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(e.basePriceId),t.object(e.quotePriceId),t.pure.u64(e.amountIn),t.pure.bool(e.a2b),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::haedal_hmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},bz=class{constructor(t,e){if(t===1)throw new Error("Obric is not supported on testnet");this.pythStateObjectId="0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",this.pythPriceIDs=e}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Obric not set publishedAt");if(!e.extendedDetails)throw new Error("Extended details not supported in obric");let{direction:r,from:n,target:i}=e,[s,o]=r?[n,i]:[i,n],u=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,c,d;if(e.extendedDetails.obric_coin_a_price_seed&&e.extendedDetails.obric_coin_b_price_seed)c=this.pythPriceIDs.get(e.extendedDetails.obric_coin_a_price_seed),d=this.pythPriceIDs.get(e.extendedDetails.obric_coin_b_price_seed);else if(e.extendedDetails.obric_coin_a_price_id&&e.extendedDetails.obric_coin_b_price_id)c=e.extendedDetails.obric_coin_a_price_id,d=e.extendedDetails.obric_coin_b_price_id;else throw new Error("Base price id or quote price id not supported");return{coinAType:s,coinBType:o,coinAPriceInfoObjectId:c,coinBPriceInfoObjectId:d,direction:r,amountIn:u,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:e.extendedDetails}}executeSwapContract(t,e,r){if(!e.coinAPriceInfoObjectId||!e.coinBPriceInfoObjectId)throw new Error("Base price info object id or quote price info object id not found");let n=[r,t.object(e.poolId),t.pure.u64(e.amountIn),t.pure.bool(e.direction),t.object(this.pythStateObjectId),t.object(e.coinAPriceInfoObjectId),t.object(e.coinBPriceInfoObjectId),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::obric::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},wz=class{constructor(t,e){if(t!==0)throw new Error("Sevenk only supported on mainnet");this.oraclePublishedAt="0x8c36ea167c5e6da8c3d60b4fc897416105dcb986471bd81cfbfd38720a4487c0",this.pythPriceIDs=e}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r,n)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Sevenk not set publishedAt");if(!e.extendedDetails)throw new Error("Extended details not found for Sevenk");let{direction:r,from:n,target:i}=e,[s,o,u]=r?["swap_a2b",n,i]:["swap_b2a",i,n],c=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,d=e.extendedDetails;if(!d.sevenk_coin_a_price_seed||!d.sevenk_coin_b_price_seed||!d.sevenk_oracle_config_a||!d.sevenk_oracle_config_b||!d.sevenk_lp_cap_type)throw new Error("Required Sevenk extended details not found");let p=d.sevenk_coin_a_price_seed,_=d.sevenk_coin_b_price_seed,b=d.sevenk_oracle_config_a,O=d.sevenk_oracle_config_b,T=d.sevenk_lp_cap_type,x=this.pythPriceIDs.get(p),F=this.pythPriceIDs.get(_);if(!x||!F)throw new Error("Sevenk price info object IDs not found");return{func:s,coinAType:o,coinBType:u,coinAPriceId:x,coinBPriceId:F,coinAOracleId:b,coinBOracleId:O,lpCapType:T,direction:r,amountIn:c,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:e.extendedDetails}}executeSwapContract(t,e,r,n){let i=t.moveCall({target:`${this.oraclePublishedAt}::oracle::new_holder`,typeArguments:[],arguments:[]});t.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[t.object(e.coinAOracleId),i,t.object(e.coinAPriceId),t.object(Zt.SUI_CLOCK_OBJECT_ID)]}),t.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[t.object(e.coinBOracleId),i,t.object(e.coinBPriceId),t.object(Zt.SUI_CLOCK_OBJECT_ID)]});let s=[r,t.object(e.poolId),i,t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::sevenk::${e.func}`,typeArguments:[e.coinAType,e.coinBType,e.lpCapType],arguments:s})}},Mz=class{constructor(t,e){if(t!==0)throw new Error("Steamm OMM only supported on mainnet");this.pythPriceIDs=e,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(t,e,r,n){let i=e.path;if(!i.extendedDetails)throw new Error("Extended details not found for Steamm OMM");this.validateExtendedDetails(i.extendedDetails);let s=this.prepareSwapData(e);this.executeSwapContract(t,s,r)}validateExtendedDetails(t){let e=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steammOracleRegistryId","steammOracleIndexA","steammOracleIndexB","steammOraclePythPriceSeedA","steammOraclePythPriceSeedB"];for(let r of e)if(t[r]==null)throw new Error(`Steamm ${r} not supported`)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Steamm OMM not set publishedAt");let r=e.extendedDetails,{direction:n,from:i,target:s}=e,[o,u,c]=n?["swap_a2b_v2",i,s]:["swap_b2a_v2",s,i],d=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,p=r.steamm_oracle_pyth_price_seed_a,_=r.steamm_oracle_pyth_price_seed_b;if(!p||!_)throw new Error("Steamm oracle price seeds not found");let b=this.pythPriceIDs.get(p),O=this.pythPriceIDs.get(_);if(!b||!O)throw new Error("Base price info object id or quote price info object id not found");return{func:o,coinAType:u,coinBType:c,direction:n,amountIn:d,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:r,priceInfoObjectIdA:b,priceInfoObjectIdB:O}}executeSwapContract(t,e,r){let n=e.extendedDetails,i=t.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[t.object(n.steammOracleRegistryId),t.object(e.priceInfoObjectIdA),t.pure.u64(n.steammOracleIndexA),t.object(Zt.SUI_CLOCK_OBJECT_ID)]}),s=t.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[t.object(n.steammOracleRegistryId),t.object(e.priceInfoObjectIdB),t.pure.u64(n.steammOracleIndexB),t.object(Zt.SUI_CLOCK_OBJECT_ID)]}),o=[r,t.object(e.poolId),t.object(n.steamm_bank_a),t.object(n.steamm_bank_b),t.object(n.steamm_lending_market),i,s,t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::steamm_omm::${e.func}`,typeArguments:[n.steamm_lending_market_type,e.coinAType,e.coinBType,n.steamm_btoken_a_type,n.steamm_btoken_b_type,n.steamm_lp_token_type],arguments:o})}},Sz=class{constructor(t,e){if(t!==0)throw new Error("Steamm OMM V2 only supported on mainnet");this.pythPriceIDs=e,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(t,e,r,n){let i=e.path;if(!i.extendedDetails)throw new Error("Extended details not found for Steamm OMM V2");this.validateExtendedDetails(i.extendedDetails);let s=this.prepareSwapData(e);this.executeSwapContract(t,s,r)}validateExtendedDetails(t){let e=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steamm_oracle_registry_id","steamm_oracle_index_a","steamm_oracle_index_b","steamm_oracle_pyth_price_seed_a","steamm_oracle_pyth_price_seed_b"];for(let r of e)if(t[r]==null)throw new Error(`Steamm OMM V2 ${r} not supported`)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Steamm OMM V2 not set publishedAt");let r=e.extendedDetails,{direction:n,from:i,target:s}=e,[o,u]=n?[i,s]:[s,i],c=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,d=r.steamm_oracle_pyth_price_seed_a,p=r.steamm_oracle_pyth_price_seed_b;if(!d||!p)throw new Error("Steamm OMM V2 oracle price seeds not found");let _=this.pythPriceIDs.get(d),b=this.pythPriceIDs.get(p);if(!_||!b)throw new Error("Base price info object id or quote price info object id not found");return{coinAType:o,coinBType:u,direction:n,amountIn:c,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:r,priceInfoObjectIdA:_,priceInfoObjectIdB:b}}executeSwapContract(t,e,r){let n=e.extendedDetails,i=t.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[t.object(n.steamm_oracle_registry_id),t.object(e.priceInfoObjectIdA),t.pure.u64(n.steamm_oracle_index_a),t.object(Zt.SUI_CLOCK_OBJECT_ID)]}),s=t.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[t.object(n.steamm_oracle_registry_id),t.object(e.priceInfoObjectIdB),t.pure.u64(n.steamm_oracle_index_b),t.object(Zt.SUI_CLOCK_OBJECT_ID)]}),o=[r,t.object(e.poolId),t.object(n.steamm_bank_a),t.object(n.steamm_bank_b),t.object(n.steamm_lending_market),i,s,t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::steamm_omm_v2::swap`,typeArguments:[n.steamm_lending_market_type,e.coinAType,e.coinBType,n.steamm_btoken_a_type,n.steamm_btoken_b_type,n.steamm_lp_token_type],arguments:o})}},kz="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",Oz="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",Ez="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",Az=class{constructor(t,e){if(t!==0)throw new Error("Metastable only supported on mainnet");this.versionID="0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c",this.pythPriceIDs=e}swap(t,e,r,n){let i=this.prepareSwapData(e),s=this.createDepositCap(t,i);this.executeSwapContract(t,i,r,s)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Metastable not set publishedAt");if(!e.extendedDetails)throw new Error("Extended details not found for Metastable");let{direction:r,from:n,target:i}=e,[s,o]=r?[n,i]:[i,n],[u,c]=r?["swap_a2b","create_deposit_cap"]:["swap_b2a","create_withdraw_cap"];if(!e.extendedDetails.metastable_create_cap_pkg_id||!e.extendedDetails.metastable_create_cap_module||!e.extendedDetails.metastable_whitelisted_app_id)throw new Error("CreateCapPkgId or CreateCapModule or WhitelistedAppId not found in extended details");let d=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinType:s,metaCoinType:o,func:u,createCapFunc:c,direction:r,amountIn:d,publishedAt:e.publishedAt,poolId:e.id,extendedDetails:e.extendedDetails}}createDepositCap(t,e){let r=[e.metaCoinType];e.extendedDetails.metastable_create_cap_all_type_params&&r.push(e.coinType);let n=[t.object(e.extendedDetails.metastable_whitelisted_app_id),t.object(e.poolId)];switch(e.metaCoinType){case kz:{if(!e.extendedDetails.metastable_registry_id)throw new Error("Not found registry id for super sui");n.push(t.object(e.extendedDetails.metastable_registry_id));break}case Oz:case Ez:{if(e.extendedDetails.metastable_price_seed!=null){let i=this.pythPriceIDs.get(e.extendedDetails.metastable_price_seed);if(i==null)throw new Error("Invalid Pyth price feed: "+e.extendedDetails.metastable_price_seed);n.push(t.object(i))}if(e.extendedDetails.metastable_eth_price_seed!=null){let i=this.pythPriceIDs.get(e.extendedDetails.metastable_eth_price_seed);if(i==null)throw new Error("Invalid Pyth price feed: "+e.extendedDetails.metastable_eth_price_seed);n.push(t.object(i))}n.push(t.object(Zt.SUI_CLOCK_OBJECT_ID));break}default:throw new Error("Invalid Metacoin: "+e.metaCoinType)}return t.moveCall({target:`${e.extendedDetails.metastable_create_cap_pkg_id}::${e.extendedDetails.metastable_create_cap_module}::${e.createCapFunc}`,typeArguments:r,arguments:n})}executeSwapContract(t,e,r,n){let i=[r,t.object(e.poolId),t.object(this.versionID),n,t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::metastable::${e.func}`,typeArguments:[e.coinType,e.metaCoinType],arguments:i})}},Iz=class{constructor(t){if(t!==0)throw new Error("Alphafi only supported on mainnet");this.suiSystemState="0x0000000000000000000000000000000000000000000000000000000000000005"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("Alphafi not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(this.suiSystemState),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::alphafi::swap`,typeArguments:[e.coinBType],arguments:n})}},Tz=class{constructor(t){if(t!==0)throw new Error("Volo only supported on mainnet");this.stakePool="0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",this.metadata="0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Volo not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.stakePool),t.object(this.metadata),t.object("0x5"),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::volo::swap`,typeArguments:[],arguments:n})}},xz=class{constructor(t){if(t!==0)throw new Error("afSUI only supported on mainnet");this.stakedSuiVault="0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",this.safe="0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",this.referVault="0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",this.validator="0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){if(t.path.publishedAt==null)throw new Error("AFSUI not set publishedAt");let e=t.path,[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){if(!e.direction)throw new Error("AFSUI not support b2a swap");let n=[r,t.object(this.stakedSuiVault),t.object(this.safe),t.object("0x5"),t.object(this.referVault),t.object(this.validator),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::afsui::swap`,typeArguments:[],arguments:n})}},Pz=class{constructor(t){if(t!==0)throw new Error("Haedal only supported on mainnet")}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Haedal not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object("0x5"),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::hasui::swap`,typeArguments:[],arguments:n})}},Cz=class{constructor(t){if(t!==0)throw new Error("Hawal only supported on mainnet");this.staking="0x10b9d30c28448939ce6c4d6c6e0ffce4a7f8a4ada8248bdad09ef8b70e4a3904",this.validator="0x7b3ba6de2ae58283f60d5b8dc04bb9e90e4796b3b2e0dea75569f491275242e7"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Hawal not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.staking),t.object(e.poolId),t.object(this.validator),t.pure.bool(e.direction),t.pure.u64(e.amountIn)];t.moveCall({target:`${e.publishedAt}::hawal::swap`,typeArguments:[],arguments:n})}},jz=At.DEFAULT_PUBLISHED_AT.Mainnet;function Nc(t,e){return t&&t.has(Tc.AGGREGATOR_V3)?t.get(Tc.AGGREGATOR_V3):e||jz}function R6(t,e){let{quoteID:r,fromCoinType:n,targetCoinType:i,expectAmountOut:s,amountOutLimit:o,inputCoin:u,feeRate:c,feeRecipient:d,aggregatorPublishedAt:p,packages:_}=t,b=Nc(_,p),O=[e.pure.string(r),e.pure.u64(s.toString()),e.pure.u64(o.toString()),u,e.pure.u32(Number(c.toString())),e.pure.address(d)];return e.moveCall({target:`${b}::router::new_swap_context`,typeArguments:[n,i],arguments:O})}function U6(t,e){let{swapContext:r,targetCoinType:n,aggregatorPublishedAt:i,packages:s}=t,o=Nc(s,i);return e.moveCall({target:`${o}::router::confirm_swap`,typeArguments:[n],arguments:[r]})}function Nz(t,e){let{coinType:r,amount:n,swapCtx:i,aggregatorPublishedAt:s,packages:o}=t,u=Nc(o,s),c=[i,e.pure.u64(n.toString())];return e.moveCall({target:`${u}::router::take_balance`,typeArguments:[r],arguments:c})}function Dz(t,e){let{balance:r,coinType:n,recipient:i,aggregatorPublishedAt:s,packages:o}=t,u=Nc(o,s),c=[r,e.pure.address(i)];e.moveCall({target:`${u}::router::transfer_balance`,typeArguments:[n],arguments:c})}function Bz(t,e){let{coin:r,coinType:n,aggregatorPublishedAt:i,packages:s}=t,o=Nc(s,i);e.moveCall({target:`${o}::router::transfer_or_destroy_coin`,typeArguments:[n],arguments:[r]})}function Rz(){let e=Date.now().toString(16).padStart(12,"0"),r=e.substring(0,8),n=e.substring(8,12),i=Math.floor(Math.random()*16383).toString(16).padStart(4,"0"),s=Math.floor(Math.random()*0xffffffffffff).toString(16).padStart(12,"0"),u=(parseInt(r,16)&268435455|1610612736).toString(16).padStart(8,"0"),d=(parseInt(i,16)&16383|32768).toString(16).padStart(4,"0");return`downgrade_${[u,n,"6"+Math.floor(Math.random()*4095).toString(16).padStart(3,"0"),d,s].join("-")}`}function Uz(){let t=Date.now(),e=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${t.toString(16)}_${e}`}function MI(t){if(!t.startsWith("downgrade_"))return!1;let e=t.substring(10),r=/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,n=/^[0-9a-f]+_[0-9a-f]{6}$/i;return r.test(e)||n.test(e)}function Lz(t){if(!MI(t))return null;let e=t.substring(10);if(e.includes("_")){let n=e.split("_");if(n.length===2){let i=parseInt(n[0],16);return isNaN(i)?null:i}}let r=e.split("-");if(r.length===5)try{let n=(parseInt(r[0],16)&268435455).toString(16).padStart(8,"0"),i=r[1],s=n+i,o=parseInt(s,16);return isNaN(o)?null:o}catch{return null}return null}function SI(t){return t.endsWith("/find_routes")?t.replace("/find_routes",""):t}function $z(t,e,r){return Br(this,null,function*(){let n=yield Fz(e,r);return n!==null?{accountCap:t.object(n),isCreate:!1}:{accountCap:t.moveCall({target:`${sI}::${nI}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function Fz(t,e){return Br(this,null,function*(){let r=50,n=null;for(;;){let i=t.getOwnedObjects({owner:e,cursor:n,limit:r,filter:{MoveModule:{package:iI,module:rI}}});if(i!=null&&i.data!=null){if(i.data.length!==0)return i.data[0].data.objectId;if(i.data.length<50)break}else break}return null})}function qz(t,e){return e?.has("aggregator_v2")?e.get("aggregator_v2"):t||nd.V2.Mainnet}function Vz(t,e){return e?.has("aggregator_v2_extend")?e.get("aggregator_v2_extend"):t||nd.V2_EXTEND.Mainnet}function zz(t,e){return e?.has("aggregator_v2_extend2")?e.get("aggregator_v2_extend2"):t||nd.V2_EXTEND2.Mainnet}var kn=su(ou());function Gz(t){let e=t.effects;if(!(e.status.status==="success"))return{computationCost:"0",storageCost:"0",storageRebate:"0",nonRefundableStorageFee:"0",totalGasCost:"0",gasUsed:"0",gasPrice:"0",success:!1,error:e.status.error||"Unknown error"};let n=e.gasUsed;return{computationCost:n.computationCost||"0",storageCost:n.storageCost||"0",storageRebate:n.storageRebate||"0",nonRefundableStorageFee:n.nonRefundableStorageFee||"0",totalGasCost:Hz(n),gasUsed:n.computationCost||"0",gasPrice:"1000",success:!0}}function Hz(t){let e=new kn.default(t.computationCost||"0"),r=new kn.default(t.storageCost||"0"),n=new kn.default(t.storageRebate||"0"),i=new kn.default(t.nonRefundableStorageFee||"0");return e.add(r).sub(n).add(i).toString()}function Wz(t,e){let r=new kn.default(e);return r.isZero()?0:t.div(r).toNumber()}function Kz(t,e,r=1){let n=t.mul(new kn.default(Math.floor(r*1e6))).div(new kn.default(1e6));return n.isZero()?0:n.sub(e).mul(new kn.default(1e4)).div(n).toNumber()/100}function Xz(t,e){let r=t.filter(u=>u.gasMetrics.success),n=e.filter(u=>u.gasMetrics.success),i=L6(r),s=L6(n),o=i.isZero()?0:i.sub(s).mul(new kn.default(1e4)).div(i).toNumber()/100;return{v2:t,v3:e,summary:{v2AverageGas:i.toString(),v3AverageGas:s.toString(),gasSavingsPercent:o,v2SuccessRate:r.length/t.length*100,v3SuccessRate:n.length/e.length*100,totalTests:t.length+e.length}}}function L6(t){return t.length===0?new kn.default(0):t.reduce((r,n)=>r.add(new kn.default(n.gasMetrics.totalGasCost)),new kn.default(0)).div(new kn.default(t.length))}function Jz(t,e){if(!t.success)return`\u274C Failed: ${t.error}`;let r=Number(t.totalGasCost),n=r/1e9,i=e?" (estimated)":"";return`\u2705 Gas: ${r.toString()} MIST (${n.toString()} SUI)${i}`}function Zz(t){return JSON.stringify(t,null,2)}function Yz(t){let r=[["Version","Provider","Success","AmountIn","AmountOut","TotalGasCost","ComputationCost","GasEfficiency","PriceImpact","OriginalPaths","MergedPaths","PathReduction%","Timestamp"].join(",")];return t.v2.forEach(n=>{let i=n.originalPathCount&&n.mergedPathCount?((n.originalPathCount-n.mergedPathCount)/n.originalPathCount*100).toFixed(1):"0";r.push(["V2",n.provider,n.gasMetrics.success,n.amountIn.toString(),n.amountOut.toString(),n.gasMetrics.totalGasCost,n.gasMetrics.computationCost,n.gasEfficiency.toString(),n.priceImpact.toString(),n.originalPathCount||0,n.mergedPathCount||0,i,n.timestamp.toString()].join(","))}),t.v3.forEach(n=>{let i=n.originalPathCount&&n.mergedPathCount?((n.originalPathCount-n.mergedPathCount)/n.originalPathCount*100).toFixed(1):"0";r.push(["V3",n.provider,n.gasMetrics.success,n.amountIn.toString(),n.amountOut.toString(),n.gasMetrics.totalGasCost,n.gasMetrics.computationCost,n.gasEfficiency.toString(),n.priceImpact.toString(),n.originalPathCount||0,n.mergedPathCount||0,i,n.timestamp.toString()].join(","))}),r.join(`
15
+ `)}var $6=su(ou()),Qz=t=>{var e,r,n;return Jf(Ic({},t),{amountIn:(e=t?.amountIn)==null?void 0:e.toString(),amountOut:(r=t?.amountIn)==null?void 0:r.toString(),paths:(n=t?.paths)==null?void 0:n.map(s=>{var o,u,c,d,p,_;let b=Jf(Ic({},s),{amountIn:(o=s?.amountIn)==null?void 0:o.toString(),amountOut:(u=s?.amountOut)==null?void 0:u.toString()});return s?.initialPrice&&(b.initialPrice=(c=s?.initialPrice)==null?void 0:c.toString()),(d=s?.extendedDetails)!=null&&d.after_sqrt_price&&(b.extendedDetails={after_sqrt_price:(_=(p=s?.extendedDetails)==null?void 0:p.afterSqrtPrice)==null?void 0:_.toString()}),b})})},eG=t=>{var e;return Jf(Ic({},t),{amountIn:new $6.default(t?.amountIn),amountOut:new $6.default(t?.amountIn),paths:(e=t?.paths)==null?void 0:e.map(n=>{var i,s,o,u;let c=Ic({},n);return n?.initialPrice&&(c.initialPrice=new td((i=n?.initialPrice)==null?void 0:i.toString())),(s=n?.extendedDetails)!=null&&s.after_sqrt_price&&(c.extendedDetails={after_sqrt_price:new td((u=(o=n?.extendedDetails)==null?void 0:o.after_sqrt_price)==null?void 0:u.toString())}),c})})};function tG(t,e=!0){return Br(this,null,function*(){console.log("inputs",t.getData().inputs),t.getData().commands.forEach((r,n)=>{e&&console.log(`transaction ${n}: `,JSON.stringify(r,rG,2))})})}function rG(t,e){return typeof e=="bigint"?e.toString():e}function nG(t){return!(!t.startsWith("0x")||t.length!==66)}var iG=class{constructor(t,e){if(t!==0)throw new Error("Haedal HMM V2 only supported on mainnet");this.pythPriceIDs=e}swap(t,e,r,n){let i=e.path;if(!i.extendedDetails)throw new Error("Extended details not found for Haedal HMM V2");console.log("path.extendedDetails",i.extendedDetails),this.validateExtendedDetails(i.extendedDetails);let s=this.prepareSwapData(e);this.executeSwapContract(t,s,r)}validateExtendedDetails(t){if(!t.haedalhmmv2_base_price_seed)throw new Error("Haedal HMM V2 base price seed not supported")}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Haedal HMM V2 not set publishedAt");let r=e.extendedDetails,[n,i]=e.direction?[e.from,e.target]:[e.target,e.from],s=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn,o=r.haedalhmmv2_base_price_seed,u=this.pythPriceIDs.get(o);if(!u)throw new Error("Haedal HMM V2 requires oracle price IDs for base coin");return{coinAType:n,coinBType:i,basePriceId:u,a2b:e.direction,amountIn:s,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(e.poolId),t.object(e.basePriceId),t.pure.u64(e.amountIn),t.pure.bool(e.a2b),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},sG=class{constructor(t){if(t!==0)throw new Error("Fullsail only supported on mainnet");this.globalConfig="0xe93baa80cb570b3a494cbf0621b2ba96bc993926d34dc92508c9446f9a05d615",this.vault="0xfb971d3a2fb98bde74e1c30ba15a3d8bef60a02789e59ae0b91660aeed3e64e1",this.stats="0x6822a33d1d971e040c32f7cc74507010d1fe786f7d06ab89135083ddb07d2dc2",this.price_provider="0x854b2d2c0381bb656ec962f8b443eb082654384cf97885359d1956c7d76e33c9"}swap(t,e,r,n){let i=this.prepareSwapData(e);this.executeSwapContract(t,i,r)}prepareSwapData(t){let e=t.path;if(t.path.publishedAt==null)throw new Error("Fullsail not set publishedAt");let[r,n]=e.direction?[e.from,e.target]:[e.target,e.from],i=t.isLastUseOfIntermediateToken?At.MAX_AMOUNT_IN:e.amountIn;return{coinAType:r,coinBType:n,direction:e.direction,amountIn:i,publishedAt:e.publishedAt,poolId:e.id}}executeSwapContract(t,e,r){let n=[r,t.object(this.globalConfig),t.object(this.vault),t.object(this.stats),t.object(this.price_provider),t.object(e.poolId),t.pure.bool(e.direction),t.pure.u64(e.amountIn),t.object(Zt.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::fullsail::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},rd="CETUS",oG="DEEPBOOK",hy="KRIYA",py="FLOWX",my="FLOWXV3",gy="KRIYAV3",yy="TURBOS",_y="AFTERMATH",vy="HAEDAL",by="VOLO",wy="AFSUI",My="BLUEMOVE",Sy="DEEPBOOKV3",ky="SCALLOP",Oy="SUILEND",Ey="BLUEFIN",ad="HAEDALPMM",Ay="ALPHAFI",Iy="SPRINGSUI",Ty="STEAMM",ud="METASTABLE",cd="OBRIC",xy="HAWAL",ld="STEAMM_OMM",Py="MOMENTUM",fd="STEAMM_OMM_V2",Cy="MAGMA",dd="SEVENK",hd="HAEDALHMMV2",jy="FULLSAIL",kI="https://api-sui.cetus.zone/router_v3",pd=[rd,hy,py,my,gy,yy,_y,vy,by,wy,My,Sy,ky,Oy,Ey,ad,Ay,Iy,Ty,ud,cd,xy,Py,ld,fd,Cy,dd,hd,jy];function aG(){return pd}function uG(t){return pd.filter(e=>!t.includes(e))}function cG(t){return pd.filter(e=>t.includes(e))}function F6(t){let e=new Set;for(let r of t){if(r.provider===ad&&r.extendedDetails&&r.extendedDetails.haedal_pmm_base_price_seed&&r.extendedDetails.haedal_pmm_quote_price_seed&&(e.add(r.extendedDetails.haedal_pmm_base_price_seed),e.add(r.extendedDetails.haedal_pmm_quote_price_seed)),r.provider===ud&&(r.extendedDetails&&r.extendedDetails.metastable_price_seed&&e.add(r.extendedDetails.metastable_price_seed),r.extendedDetails&&r.extendedDetails.metastable_eth_price_seed&&e.add(r.extendedDetails.metastable_eth_price_seed)),r.provider===cd&&(r.extendedDetails&&r.extendedDetails.obric_coin_a_price_seed&&e.add(r.extendedDetails.obric_coin_a_price_seed),r.extendedDetails&&r.extendedDetails.obric_coin_b_price_seed&&e.add(r.extendedDetails.obric_coin_b_price_seed)),(r.provider===ld||r.provider===fd)&&(r.extendedDetails&&r.extendedDetails.steamm_oracle_pyth_price_seed_a&&e.add(r.extendedDetails.steamm_oracle_pyth_price_seed_a),r.extendedDetails&&r.extendedDetails.steamm_oracle_pyth_price_seed_b&&e.add(r.extendedDetails.steamm_oracle_pyth_price_seed_b)),r.provider===dd&&r.extendedDetails){let n=r.extendedDetails;n.sevenk_coin_a_price_seed&&e.add(n.sevenk_coin_a_price_seed),n.sevenk_coin_b_price_seed&&e.add(n.sevenk_coin_b_price_seed)}r.provider===hd&&r.extendedDetails&&r.extendedDetails.haedalhmmv2_base_price_seed&&e.add(r.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(e)}var OI=class EI{constructor(e){var r,n;this.endpoint=e.endpoint?SI(e.endpoint):kI,this.client=e.client||new E6.SuiClient({url:E6.getFullnodeUrl("mainnet")}),this.signer=e.signer||"",this.env=e.env||0;let i=EI.CONFIG[this.env];if(this.pythConnections=this.newPythClients((r=e.pythUrls)!=null?r:[]),this.pythClient=new A6.SuiPythClient(this.client,i.pythStateId,i.wormholeStateId),this.apiKey=e.apiKey||"",this.partner=e.partner,e.overlayFeeRate)if(e.overlayFeeRate>0&&e.overlayFeeRate<=As.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=e.overlayFeeRate*At.FEE_DENOMINATOR,this.overlayFeeRate>At.MAX_FEE_RATE)throw new Error(As.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(As.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(n=e.overlayFeeReceiver)!=null?n:As.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(e){return e.includes("https://hermes.pyth.network")||e.push("https://hermes.pyth.network"),e.map(n=>new A6.SuiPriceServiceConnection(n,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?xc.Mainnet:xc.Testnet}getOneCoinUsedToMerge(e){return Br(this,null,function*(){try{let r=yield this.client.getCoins({owner:this.signer,coinType:e,limit:1});return r.data.length===1?r.data[0].coinObjectId:null}catch{return null}})}findRouters(e){return Br(this,null,function*(){return uI(this.endpoint,this.apiKey,e,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(e,r,n,i,s,o,u,c,d){return Br(this,null,function*(){})}newDexRouterV3(e,r,n){switch(e){case rd:return new D6(this.env,n);case gy:return new oz(this.env);case my:return new az(this.env);case yy:return new uz(this.env);case Ey:return new cz(this.env);case Py:return new lz(this.env);case Cy:return new fz(this.env);case hy:return new dz(this.env);case py:return new hz(this.env);case My:return new pz(this.env);case Sy:return new mz(this.env);case _y:return new gz(this.env);case Ty:return new yz(this.env);case ky:return new _z(this.env);case Oy:return new B6(this.env);case Iy:return new B6(this.env);case ad:return new vz(this.env,r);case cd:return new bz(this.env,r);case dd:return new wz(this.env,r);case ld:return new Mz(this.env,r);case fd:return new Sz(this.env,r);case ud:return new Az(this.env,r);case Ay:return new Iz(this.env);case by:return new Tz(this.env);case wy:return new xz(this.env);case vy:return new Pz(this.env);case xy:return new Cz(this.env);case hd:return new iG(this.env,r);case jy:return new sG(this.env);default:throw new Error(`${As.ERRORS.UNSUPPORTED_DEX} ${e}`)}}expectInputSwapV3(e,r,n,i,s,o,u){if(n.quoteID==null)throw new Error(As.ERRORS.QUOTE_ID_REQUIRED);let c=iy(n),d=R6({quoteID:c.quoteID,fromCoinType:c.fromCoinType,targetCoinType:c.targetCoinType,expectAmountOut:i,amountOutLimit:s,inputCoin:r,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:c.packages},e),p=new Map;for(let b of c.flattenedPaths){let O=b.path;p.has(O.provider)||p.set(O.provider,this.newDexRouterV3(O.provider,o,u)),p.get(O.provider).swap(e,b,d,{pythPriceIDs:o})}return U6({swapContext:d,targetCoinType:c.targetCoinType,packages:c.packages},e)}expectOutputSwapV3(e,r,n,i,s,o){let u=[],c=new D6(this.env,o),d=iy(n),p=R6({quoteID:d.quoteID,fromCoinType:d.fromCoinType,targetCoinType:d.targetCoinType,expectAmountOut:i,amountOutLimit:i,inputCoin:r,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:d.packages},e),_=dG(n.paths),b=new Map,O=new Map;for(let F=n.paths.length-1;F>=0;F--){let R=n.paths[F],H=_.get(R.from),J;if(F!==H||R.target===d.targetCoinType){if(R.target!==d.targetCoinType){let ae=BigInt(R.amountOut);O.has(R.target)&&(ae=O.get(R.target)+ae),O.set(R.target,ae)}J=e.pure.u64(R.amountOut.toString())}else{if(!b.has(R.target))throw Error("no need repay record");if(O.has(R.target)){let ae=O.get(R.target),te=b.get(R.target);J=c.sub(e,te,e.pure.u64(ae),R.publishedAt)}else J=b.get(R.target)}let ee=c.flashSwapFixedOutput(e,R,J,p);if(u.unshift(ee.flashReceipt),b.has(R.from)){let ae=b.get(R.from);b.set(R.from,c.add(e,ae,ee.repayAmount,R.publishedAt))}else b.set(R.from,ee.repayAmount)}for(let F=0;F<n.paths.length;F++){let R=n.paths[F];c.repayFlashSwapFixedOutput(e,R,p,u[F])}let T=Nz({coinType:d.fromCoinType,amount:Zf,swapCtx:p,packages:d.packages},e);return Dz({balance:T,coinType:d.fromCoinType,recipient:this.signer,packages:d.packages},e),U6({swapContext:p,targetCoinType:d.targetCoinType,packages:d.packages},e)}routerSwap(e){return Br(this,null,function*(){let{router:r,inputCoin:n,slippage:i,txb:s,fixable:o,partner:u}=e;if(i>1||i<0)throw new Error(As.ERRORS.INVALID_SLIPPAGE);let c=e.router.byAmountIn,d=r.amountIn,p=r.amountOut,_=new rr.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(c?_=p.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)):_=d.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)));let b=c?p.sub(_):p,O=c?d:d.add(_),T=N6(c?b:O,c,i);if(!e.router.packages||!e.router.packages.get(Tc.AGGREGATOR_V3))throw new Error(As.ERRORS.PACKAGES_REQUIRED);let x=F6(r.paths),F=x.length>0?yield this.updatePythPriceIDs(x,s):new Map;return c?this.expectInputSwapV3(s,n,r,p.toString(),T.toString(),F,u??this.partner):this.expectOutputSwapV3(s,n,r,p.toString(),T.toString(),u??this.partner)})}fastRouterSwap(e){return Br(this,null,function*(){let{router:r,slippage:n,txb:i,partner:s,payDeepFeeAmount:o}=e,u=r.paths[0].from,c=r.paths[r.paths.length-1].target,d=r.byAmountIn,p=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(d?p=Number(r.amountOut.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)).toString()):p=Number(r.amountIn.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)).toString()));let _=d?r.amountOut.sub(new rr.default(p)):r.amountOut,b=d?r.amountIn:r.amountIn.add(new rr.default(p)),O=sz(d?_:b,d,n),T=d?b:O,x=ty.coinWithBalance({balance:BigInt(T.toString()),useGasCoin:!0,type:u}),F;o&&o>0&&(F=ty.coinWithBalance({balance:BigInt(o),type:this.deepbookv3DeepFeeType()}));let R={router:r,inputCoin:x,slippage:n,txb:i,partner:s??this.partner,deepbookv3DeepFee:F},H=yield this.routerSwap(R);if(ki.isSuiCoin(c))i.mergeCoins(i.gas,[H]);else{let J=yield this.getOneCoinUsedToMerge(c);J!=null?i.mergeCoins(i.object(J),[H]):Bz({coin:H,coinType:c,packages:r.packages},i)}})}fixableRouterSwapV3(e){return Br(this,null,function*(){let{router:r,inputCoin:n,slippage:i,txb:s,deepbookv3DeepFee:o,partner:u}=e,c=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(r.byAmountIn?c=Number(r.amountOut.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)).toString()):c=Number(r.amountIn.mul(new rr.default(this.overlayFeeRate)).div(new rr.default(1e6)).toString()));let d=r.byAmountIn?r.amountOut.sub(new rr.default(c)):r.amountOut,p=r.byAmountIn?r.amountIn:r.amountIn.add(new rr.default(c)),_=N6(r.byAmountIn?d:p,r.byAmountIn,i),b=F6(r.paths),O=b.length>0?yield this.updatePythPriceIDs(b,s):new Map;return r.byAmountIn?this.expectInputSwapV3(s,n,r,d.toString(),_.toString(),O,u??this.partner):this.expectOutputSwapV3(s,n,r,d.toString(),_.toString(),u??this.partner)})}swapInPools(e){return Br(this,null,function*(){var r,n,i,s;let{from:o,target:u,amount:c,byAmountIn:d,pools:p}=e,_=Ts(o),b=Ts(u),O=new ty.Transaction,T=eI(_,b),x=T?_:b,F=T?b:_,R=[x,F],H=this.env===0?"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d":"0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";for(let l=0;l<p.length;l++){let h=[O.object(p[l]),O.pure.bool(T),O.pure.bool(d),O.pure.u64(c.toString())];O.moveCall({target:`${H}::fetcher_script::calculate_swap_result`,arguments:h,typeArguments:R})}this.signer||(this.signer="0x0");let J=yield this.client.devInspectTransactionBlock({transactionBlock:O,sender:this.signer});if(J.error!=null)throw new Error("Simulation error: "+J.error);let ee=(r=J.events)==null?void 0:r.filter(l=>l.type.includes("CalculatedSwapResultEvent"));if(ee.length===0||ee.length!==p.length)throw new Error("Simulate event result error");let ae=d?new rr.default(0):new rr.default(Zf),te=0;for(let l=0;l<ee.length;l+=1)if(!ee[l].parsedJson.data.is_exceed)if(e.byAmountIn){let h=new rr.default(ee[l].parsedJson.data.amount_out);h.gt(ae)&&(te=l,ae=h)}else{let h=new rr.default(ee[l].parsedJson.data.amount_out);h.lt(ae)&&(te=l,ae=h)}let he=ee[te].parsedJson.data,[A,I]=yield Promise.all([this.client.getCoinMetadata({coinType:x}).then(l=>l?.decimals),this.client.getCoinMetadata({coinType:F}).then(l=>l?.decimals)]);if(A==null||I==null)throw new Error("Cannot get coin decimals");let C=Number(he.fee_rate)/1e6,D=new rr.default((n=he.amount_in)!=null?n:0),N=new rr.default((i=he.fee_amount)!=null?i:0),k=D.add(N),m={amountIn:k,amountOut:new rr.default((s=he.amount_out)!=null?s:0),paths:[{id:p[te],direction:T,provider:rd,from:_,target:b,feeRate:C,amountIn:k.toString(),amountOut:he.amount_out,publishedAt:oI,extendedDetails:{afterSqrtPrice:he.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:e.byAmountIn,quoteID:`degraded-${fG()}`,packages:new Map([[Tc.AGGREGATOR_V3,At.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:he.is_exceed,routeData:m}})}updatePythPriceIDs(e,r){return Br(this,null,function*(){let n=null,i=null;for(let u of this.pythConnections)try{n=yield u.getPriceFeedsUpdateData(e);break}catch(c){i=c,console.log("Error: ",c);continue}if(n==null)throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes. Detailed error: ${i?.message}`);let s=[];try{s=yield this.pythClient.updatePriceFeeds(r,n,e)}catch(u){throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes in the pythUrls parameter when initializing AggregatorClient, for example: new AggregatorClient({ pythUrls: ["https://your-pyth-node-url"] }). Detailed error: ${u}`)}let o=new Map;for(let u=0;u<e.length;u++)o.set(e[u],s[u]);return o})}devInspectTransactionBlock(e){return Br(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:e,sender:this.signer})})}sendTransaction(e,r){return Br(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:r})})}};OI.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var lG=OI;function fG(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function dG(t){let e=new Map;for(let r=0;r<t.length;r++)e.has(t[r].from)||e.set(t[r].from,r);return e}var hG=t=>{if(typeof t=="string"&&t.startsWith("0x"))return"object";if(typeof t=="number"||typeof t=="bigint")return"u64";if(typeof t=="boolean")return"bool";throw new AggregateError(`Unknown type for value: ${t}`,"InvalidType")};Y.AFSUI=wy;Y.AFTERMATH=_y;Y.AFTERMATH_AMM=uq;Y.AFTERMATH_MODULE=_q;Y.AGGREGATOR=rq;Y.AGGREGATOR_V3_CONFIG=At;Y.ALL_DEXES=pd;Y.ALPHAFI=Ay;Y.AggregatorClient=lG;Y.AggregatorConfig=lV;Y.AggregatorError=CF;Y.AggregatorServerErrorCode=W6;Y.BLUEFIN=Ey;Y.BLUEMOVE=My;Y.CETUS=rd;Y.CETUS_DEX=nq;Y.CETUS_MODULE=lq;Y.CETUS_PUBLISHED_AT=Fq;Y.CETUS_V3_PUBLISHED_AT=oI;Y.CHECK_COINS_THRESHOLD_FUNC=Nq;Y.CLIENT_CONFIG=As;Y.CLOCK_ADDRESS=Rq;Y.CoinInfoAddress=Uq;Y.CoinStoreAddress=Lq;Y.CoinUtils=ki;Y.ConfigErrorCode=G6;Y.DEEPBOOKV2=oG;Y.DEEPBOOKV3=Sy;Y.DEEPBOOK_CLOB_V2_MODULE=nI;Y.DEEPBOOK_CUSTODIAN_V2_MODULE=rI;Y.DEEPBOOK_DEX=iq;Y.DEEPBOOK_MODULE=fq;Y.DEEPBOOK_PACKAGE_ID=iI;Y.DEEPBOOK_PUBLISHED_AT=sI;Y.DEEPBOOK_V3_DEEP_FEE_TYPES=xc;Y.DEFAULT_AGG_V2_ENDPOINT=iV;Y.DEFAULT_AGG_V3_ENDPOINT=nV;Y.DEFAULT_ENDPOINT=kI;Y.DEFAULT_GAS_BUDGET_FOR_MERGE=qF;Y.DEFAULT_GAS_BUDGET_FOR_SPLIT=FF;Y.DEFAULT_GAS_BUDGET_FOR_STAKE=GF;Y.DEFAULT_GAS_BUDGET_FOR_TRANSFER=VF;Y.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=zF;Y.DEFAULT_NFT_TRANSFER_GAS_FEE=WF;Y.Env=cI;Y.FLOWXV2=py;Y.FLOWXV3=my;Y.FLOWX_AMM=oq;Y.FLOWX_AMM_MODULE=gq;Y.FULLSAIL=jy;Y.FlashSwapA2BFunc=Sq;Y.FlashSwapB2AFunc=kq;Y.FlashSwapFunc=vq;Y.FlashSwapWithPartnerA2BFunc=Oq;Y.FlashSwapWithPartnerB2AFunc=Eq;Y.FlashSwapWithPartnerFunc=bq;Y.GAS_SYMBOL=HF;Y.GAS_TYPE_ARG=fy;Y.GAS_TYPE_ARG_LONG=Y6;Y.HAEDAL=vy;Y.HAEDALHMMV2=hd;Y.HAEDALPMM=ad;Y.HAWAL=xy;Y.INTEGRATE=cq;Y.JOIN_FUNC=Dq;Y.KRIYA=hy;Y.KRIYAV3=gy;Y.KRIYA_DEX=sq;Y.KRIYA_MODULE=dq;Y.MAGMA=Cy;Y.MAINNET_AFTERMATH_INSURANCE_FUND_ID=Qq;Y.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=Xq;Y.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=tV;Y.MAINNET_AFTERMATH_REGISTRY_ID=Wq;Y.MAINNET_AFTERMATH_TREASURY_ID=Zq;Y.MAINNET_CETUS_GLOBAL_CONFIG_ID=qq;Y.MAINNET_FLOWX_AMM_CONTAINER_ID=zq;Y.METASTABLE=ud;Y.MOMENTUM=Py;Y.OBRIC=cd;Y.ONE=YF;Y.PACKAGE_NAMES=Tc;Y.PAY_MODULE=mq;Y.POOL_MODULT=pq;Y.PUBLISHED_ADDRESSES=nd;Y.PYTH_CONFIG=sV;Y.REPAY_FLASH_SWAP_A2B_FUNC=Aq;Y.REPAY_FLASH_SWAP_B2A_FUNC=Iq;Y.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=Tq;Y.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=xq;Y.RepayFalshSwapFunc=wq;Y.RepayFlashSwapWithPartnerFunc=Mq;Y.SCALLOP=ky;Y.SEVENK=dd;Y.SPRINGSUI=Iy;Y.STEAMM=Ty;Y.STEAMM_OMM=ld;Y.STEAMM_OMM_V2=fd;Y.SUILEND=Oy;Y.SUI_SYSTEM_STATE_OBJECT_ID=KF;Y.SWAP_A2B_FUNC=Pq;Y.SWAP_B2A_FUNC=Cq;Y.SuiZeroCoinFn=$q;Y.TEN_POW_NINE=tq;Y.TESTNET_AFTERMATH_INSURANCE_FUND_ID=eV;Y.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=Jq;Y.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=rV;Y.TESTNET_AFTERMATH_REGISTRY_ID=Kq;Y.TESTNET_AFTERMATH_TREASURY_ID=Yq;Y.TESTNET_CETUS_GLOBAL_CONFIG_ID=Vq;Y.TESTNET_FLOWX_AMM_CONTAINER_ID=Gq;Y.TRANSFER_ACCOUNT_CAP=Bq;Y.TRANSFER_OR_DESTORY_COIN_FUNC=jq;Y.TURBOS=yy;Y.TURBOS_DEX=aq;Y.TURBOS_MODULE=yq;Y.TURBOS_VERSIONED=Hq;Y.TWO=tI;Y.TransactionErrorCode=H6;Y.TypesErrorCode=z6;Y.U128=QF;Y.U64_MAX=Zf;Y.U64_MAX_BN=eq;Y.UTILS_MODULE=hq;Y.VOLO=by;Y.ZERO=da;Y.buildInputCoin=ZF;Y.calculateGasEfficiency=Wz;Y.calculatePriceImpact=Kz;Y.checkInvalidSuiAddress=nG;Y.compareCoins=eI;Y.compareGasMetrics=Xz;Y.completionCoin=Ts;Y.composeType=ry;Y.createTarget=UF;Y.dealWithFastRouterSwapParamsForMsafe=Qz;Y.exportToCSV=Yz;Y.exportToJSON=Zz;Y.extractAddressFromType=RF;Y.extractGasMetrics=Gz;Y.extractStructTagFromType=nu;Y.extractTimestampFromDowngradeUuid6=Lz;Y.fixSuiObjectId=J6;Y.formatGasMetrics=Jz;Y.generateDowngradeUuid6=Rz;Y.generateSimpleDowngradeUuid6=Uz;Y.getAggregatorServerErrorMessage=Kf;Y.getAggregatorV2Extend2PublishedAt=zz;Y.getAggregatorV2ExtendPublishedAt=Vz;Y.getAggregatorV2PublishedAt=qz;Y.getAllProviders=aG;Y.getDeepbookV3Config=cV;Y.getDefaultSuiInputType=hG;Y.getOrCreateAccountCap=$z;Y.getProvidersExcluding=uG;Y.getProvidersIncluding=cG;Y.getRouterResult=uI;Y.isSortedSymbols=BF;Y.isValidDowngradeUuid6=MI;Y.mintZeroCoin=Q6;Y.normalizeCoinType=ny;Y.parseAftermathFeeType=JF;Y.parseTurbosPoolFeeType=XF;Y.patchFixSuiObjectId=Z6;Y.printTransaction=tG;Y.processEndpoint=SI;Y.processFlattenRoutes=iy;Y.restituteMsafeFastRouterSwapParams=eG});import{SdkWrapper as iK}from"@cetusprotocol/common-sdk";import{DefaultProviders as ZT,FullRpcUrlMainnet as YT}from"@cetusprotocol/common-sdk";var g_={full_rpc_url:YT,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:ZT,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};import{SuilendClient as r3}from"@suilend/sdk/client";import{initializeSuilend as n3,initializeSuilendRewards as i3,initializeObligations as s3,formatRewards as o3,Side as dv,getFilteredRewards as a3,getStakingYieldAprPercent as u3,getDedupedPerDayRewards as c3,getDedupedAprRewards as l3,getTotalAprPercent as hv,getNetAprPercent as f3}from"@suilend/sdk";var QT=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Kd=Math.ceil,Tn=Math.floor,cn="[BigNumber Error] ",y_=cn+"Number primitive has more than 15 significant digits: ",ui=1e14,bt=14,Xd=9007199254740991,Jd=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Rs=1e7,Er=1e9;function __(t){var e,r,n,i=H.prototype={constructor:H,toString:null,valueOf:null},s=new H(1),o=20,u=4,c=-7,d=21,p=-1e7,_=1e7,b=!1,O=1,T=0,x={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},F="0123456789abcdefghijklmnopqrstuvwxyz",R=!0;function H(A,I){var C,D,N,k,m,a,l,h,y=this;if(!(y instanceof H))return new H(A,I);if(I==null){if(A&&A._isBigNumber===!0){y.s=A.s,!A.c||A.e>_?y.c=y.e=null:A.e<p?y.c=[y.e=0]:(y.e=A.e,y.c=A.c.slice());return}if((a=typeof A=="number")&&A*0==0){if(y.s=1/A<0?(A=-A,-1):1,A===~~A){for(k=0,m=A;m>=10;m/=10,k++);k>_?y.c=y.e=null:(y.e=k,y.c=[A]);return}h=String(A)}else{if(!QT.test(h=String(A)))return n(y,h,a);y.s=h.charCodeAt(0)==45?(h=h.slice(1),-1):1}(k=h.indexOf("."))>-1&&(h=h.replace(".","")),(m=h.search(/e/i))>0?(k<0&&(k=m),k+=+h.slice(m+1),h=h.substring(0,m)):k<0&&(k=h.length)}else{if(ir(I,2,F.length,"Base"),I==10&&R)return y=new H(A),te(y,o+y.e+1,u);if(h=String(A),a=typeof A=="number"){if(A*0!=0)return n(y,h,a,I);if(y.s=1/A<0?(h=h.slice(1),-1):1,H.DEBUG&&h.replace(/^0\.0*|\./,"").length>15)throw Error(y_+A)}else y.s=h.charCodeAt(0)===45?(h=h.slice(1),-1):1;for(C=F.slice(0,I),k=m=0,l=h.length;m<l;m++)if(C.indexOf(D=h.charAt(m))<0){if(D=="."){if(m>k){k=l;continue}}else if(!N&&(h==h.toUpperCase()&&(h=h.toLowerCase())||h==h.toLowerCase()&&(h=h.toUpperCase()))){N=!0,m=-1,k=0;continue}return n(y,String(A),a,I)}a=!1,h=r(h,I,10,y.s),(k=h.indexOf("."))>-1?h=h.replace(".",""):k=h.length}for(m=0;h.charCodeAt(m)===48;m++);for(l=h.length;h.charCodeAt(--l)===48;);if(h=h.slice(m,++l)){if(l-=m,a&&H.DEBUG&&l>15&&(A>Xd||A!==Tn(A)))throw Error(y_+y.s*A);if((k=k-m-1)>_)y.c=y.e=null;else if(k<p)y.c=[y.e=0];else{if(y.e=k,y.c=[],m=(k+1)%bt,k<0&&(m+=bt),m<l){for(m&&y.c.push(+h.slice(0,m)),l-=bt;m<l;)y.c.push(+h.slice(m,m+=bt));m=bt-(h=h.slice(m)).length}else m-=l;for(;m--;h+="0");y.c.push(+h)}}else y.c=[y.e=0]}H.clone=__,H.ROUND_UP=0,H.ROUND_DOWN=1,H.ROUND_CEIL=2,H.ROUND_FLOOR=3,H.ROUND_HALF_UP=4,H.ROUND_HALF_DOWN=5,H.ROUND_HALF_EVEN=6,H.ROUND_HALF_CEIL=7,H.ROUND_HALF_FLOOR=8,H.EUCLID=9,H.config=H.set=function(A){var I,C;if(A!=null)if(typeof A=="object"){if(A.hasOwnProperty(I="DECIMAL_PLACES")&&(C=A[I],ir(C,0,Er,I),o=C),A.hasOwnProperty(I="ROUNDING_MODE")&&(C=A[I],ir(C,0,8,I),u=C),A.hasOwnProperty(I="EXPONENTIAL_AT")&&(C=A[I],C&&C.pop?(ir(C[0],-Er,0,I),ir(C[1],0,Er,I),c=C[0],d=C[1]):(ir(C,-Er,Er,I),c=-(d=C<0?-C:C))),A.hasOwnProperty(I="RANGE"))if(C=A[I],C&&C.pop)ir(C[0],-Er,-1,I),ir(C[1],1,Er,I),p=C[0],_=C[1];else if(ir(C,-Er,Er,I),C)p=-(_=C<0?-C:C);else throw Error(cn+I+" cannot be zero: "+C);if(A.hasOwnProperty(I="CRYPTO"))if(C=A[I],C===!!C)if(C)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))b=C;else throw b=!C,Error(cn+"crypto unavailable");else b=C;else throw Error(cn+I+" not true or false: "+C);if(A.hasOwnProperty(I="MODULO_MODE")&&(C=A[I],ir(C,0,9,I),O=C),A.hasOwnProperty(I="POW_PRECISION")&&(C=A[I],ir(C,0,Er,I),T=C),A.hasOwnProperty(I="FORMAT"))if(C=A[I],typeof C=="object")x=C;else throw Error(cn+I+" not an object: "+C);if(A.hasOwnProperty(I="ALPHABET"))if(C=A[I],typeof C=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(C))R=C.slice(0,10)=="0123456789",F=C;else throw Error(cn+I+" invalid: "+C)}else throw Error(cn+"Object expected: "+A);return{DECIMAL_PLACES:o,ROUNDING_MODE:u,EXPONENTIAL_AT:[c,d],RANGE:[p,_],CRYPTO:b,MODULO_MODE:O,POW_PRECISION:T,FORMAT:x,ALPHABET:F}},H.isBigNumber=function(A){if(!A||A._isBigNumber!==!0)return!1;if(!H.DEBUG)return!0;var I,C,D=A.c,N=A.e,k=A.s;e:if({}.toString.call(D)=="[object Array]"){if((k===1||k===-1)&&N>=-Er&&N<=Er&&N===Tn(N)){if(D[0]===0){if(N===0&&D.length===1)return!0;break e}if(I=(N+1)%bt,I<1&&(I+=bt),String(D[0]).length==I){for(I=0;I<D.length;I++)if(C=D[I],C<0||C>=ui||C!==Tn(C))break e;if(C!==0)return!0}}}else if(D===null&&N===null&&(k===null||k===1||k===-1))return!0;throw Error(cn+"Invalid BigNumber: "+A)},H.maximum=H.max=function(){return ee(arguments,-1)},H.minimum=H.min=function(){return ee(arguments,1)},H.random=(function(){var A=9007199254740992,I=Math.random()*A&2097151?function(){return Tn(Math.random()*A)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(C){var D,N,k,m,a,l=0,h=[],y=new H(s);if(C==null?C=o:ir(C,0,Er),m=Kd(C/bt),b)if(crypto.getRandomValues){for(D=crypto.getRandomValues(new Uint32Array(m*=2));l<m;)a=D[l]*131072+(D[l+1]>>>11),a>=9e15?(N=crypto.getRandomValues(new Uint32Array(2)),D[l]=N[0],D[l+1]=N[1]):(h.push(a%1e14),l+=2);l=m/2}else if(crypto.randomBytes){for(D=crypto.randomBytes(m*=7);l<m;)a=(D[l]&31)*281474976710656+D[l+1]*1099511627776+D[l+2]*4294967296+D[l+3]*16777216+(D[l+4]<<16)+(D[l+5]<<8)+D[l+6],a>=9e15?crypto.randomBytes(7).copy(D,l):(h.push(a%1e14),l+=7);l=m/7}else throw b=!1,Error(cn+"crypto unavailable");if(!b)for(;l<m;)a=I(),a<9e15&&(h[l++]=a%1e14);for(m=h[--l],C%=bt,m&&C&&(a=Jd[bt-C],h[l]=Tn(m/a)*a);h[l]===0;h.pop(),l--);if(l<0)h=[k=0];else{for(k=-1;h[0]===0;h.splice(0,1),k-=bt);for(l=1,a=h[0];a>=10;a/=10,l++);l<bt&&(k-=bt-l)}return y.e=k,y.c=h,y}})(),H.sum=function(){for(var A=1,I=arguments,C=new H(I[0]);A<I.length;)C=C.plus(I[A++]);return C},r=(function(){var A="0123456789";function I(C,D,N,k){for(var m,a=[0],l,h=0,y=C.length;h<y;){for(l=a.length;l--;a[l]*=D);for(a[0]+=k.indexOf(C.charAt(h++)),m=0;m<a.length;m++)a[m]>N-1&&(a[m+1]==null&&(a[m+1]=0),a[m+1]+=a[m]/N|0,a[m]%=N)}return a.reverse()}return function(C,D,N,k,m){var a,l,h,y,v,M,w,g,f=C.indexOf("."),S=o,V=u;for(f>=0&&(y=T,T=0,C=C.replace(".",""),g=new H(D),M=g.pow(C.length-f),T=y,g.c=I(os(In(M.c),M.e,"0"),10,N,A),g.e=g.c.length),w=I(C,D,N,m?(a=F,A):(a=A,F)),h=y=w.length;w[--y]==0;w.pop());if(!w[0])return a.charAt(0);if(f<0?--h:(M.c=w,M.e=h,M.s=k,M=e(M,g,S,V,N),w=M.c,v=M.r,h=M.e),l=h+S+1,f=w[l],y=N/2,v=v||l<0||w[l+1]!=null,v=V<4?(f!=null||v)&&(V==0||V==(M.s<0?3:2)):f>y||f==y&&(V==4||v||V==6&&w[l-1]&1||V==(M.s<0?8:7)),l<1||!w[0])C=v?os(a.charAt(1),-S,a.charAt(0)):a.charAt(0);else{if(w.length=l,v)for(--N;++w[--l]>N;)w[l]=0,l||(++h,w=[1].concat(w));for(y=w.length;!w[--y];);for(f=0,C="";f<=y;C+=a.charAt(w[f++]));C=os(C,h,a.charAt(0))}return C}})(),e=(function(){function A(D,N,k){var m,a,l,h,y=0,v=D.length,M=N%Rs,w=N/Rs|0;for(D=D.slice();v--;)l=D[v]%Rs,h=D[v]/Rs|0,m=w*l+h*M,a=M*l+m%Rs*Rs+y,y=(a/k|0)+(m/Rs|0)+w*h,D[v]=a%k;return y&&(D=[y].concat(D)),D}function I(D,N,k,m){var a,l;if(k!=m)l=k>m?1:-1;else for(a=l=0;a<k;a++)if(D[a]!=N[a]){l=D[a]>N[a]?1:-1;break}return l}function C(D,N,k,m){for(var a=0;k--;)D[k]-=a,a=D[k]<N[k]?1:0,D[k]=a*m+D[k]-N[k];for(;!D[0]&&D.length>1;D.splice(0,1));}return function(D,N,k,m,a){var l,h,y,v,M,w,g,f,S,V,z,Z,ce,E,P,j,L,U=D.s==N.s?1:-1,W=D.c,q=N.c;if(!W||!W[0]||!q||!q[0])return new H(!D.s||!N.s||(W?q&&W[0]==q[0]:!q)?NaN:W&&W[0]==0||!q?U*0:U/0);for(f=new H(U),S=f.c=[],h=D.e-N.e,U=k+h+1,a||(a=ui,h=xn(D.e/bt)-xn(N.e/bt),U=U/bt|0),y=0;q[y]==(W[y]||0);y++);if(q[y]>(W[y]||0)&&h--,U<0)S.push(1),v=!0;else{for(E=W.length,j=q.length,y=0,U+=2,M=Tn(a/(q[0]+1)),M>1&&(q=A(q,M,a),W=A(W,M,a),j=q.length,E=W.length),ce=j,V=W.slice(0,j),z=V.length;z<j;V[z++]=0);L=q.slice(),L=[0].concat(L),P=q[0],q[1]>=a/2&&P++;do{if(M=0,l=I(q,V,j,z),l<0){if(Z=V[0],j!=z&&(Z=Z*a+(V[1]||0)),M=Tn(Z/P),M>1)for(M>=a&&(M=a-1),w=A(q,M,a),g=w.length,z=V.length;I(w,V,g,z)==1;)M--,C(w,j<g?L:q,g,a),g=w.length,l=1;else M==0&&(l=M=1),w=q.slice(),g=w.length;if(g<z&&(w=[0].concat(w)),C(V,w,z,a),z=V.length,l==-1)for(;I(q,V,j,z)<1;)M++,C(V,j<z?L:q,z,a),z=V.length}else l===0&&(M++,V=[0]);S[y++]=M,V[0]?V[z++]=W[ce]||0:(V=[W[ce]],z=1)}while((ce++<E||V[0]!=null)&&U--);v=V[0]!=null,S[0]||S.splice(0,1)}if(a==ui){for(y=1,U=S[0];U>=10;U/=10,y++);te(f,k+(f.e=y+h*bt-1)+1,m,v)}else f.e=h,f.r=+v;return f}})();function J(A,I,C,D){var N,k,m,a,l;if(C==null?C=u:ir(C,0,8),!A.c)return A.toString();if(N=A.c[0],m=A.e,I==null)l=In(A.c),l=D==1||D==2&&(m<=c||m>=d)?Wc(l,m):os(l,m,"0");else if(A=te(new H(A),I,C),k=A.e,l=In(A.c),a=l.length,D==1||D==2&&(I<=k||k<=c)){for(;a<I;l+="0",a++);l=Wc(l,k)}else if(I-=m+(D===2&&k>m),l=os(l,k,"0"),k+1>a){if(--I>0)for(l+=".";I--;l+="0");}else if(I+=k-a,I>0)for(k+1==a&&(l+=".");I--;l+="0");return A.s<0&&N?"-"+l:l}function ee(A,I){for(var C,D,N=1,k=new H(A[0]);N<A.length;N++)D=new H(A[N]),(!D.s||(C=No(k,D))===I||C===0&&k.s===I)&&(k=D);return k}function ae(A,I,C){for(var D=1,N=I.length;!I[--N];I.pop());for(N=I[0];N>=10;N/=10,D++);return(C=D+C*bt-1)>_?A.c=A.e=null:C<p?A.c=[A.e=0]:(A.e=C,A.c=I),A}n=(function(){var A=/^(-?)0([xbo])(?=\w[\w.]*$)/i,I=/^([^.]+)\.$/,C=/^\.([^.]+)$/,D=/^-?(Infinity|NaN)$/,N=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(k,m,a,l){var h,y=a?m:m.replace(N,"");if(D.test(y))k.s=isNaN(y)?null:y<0?-1:1;else{if(!a&&(y=y.replace(A,function(v,M,w){return h=(w=w.toLowerCase())=="x"?16:w=="b"?2:8,!l||l==h?M:v}),l&&(h=l,y=y.replace(I,"$1").replace(C,"0.$1")),m!=y))return new H(y,h);if(H.DEBUG)throw Error(cn+"Not a"+(l?" base "+l:"")+" number: "+m);k.s=null}k.c=k.e=null}})();function te(A,I,C,D){var N,k,m,a,l,h,y,v=A.c,M=Jd;if(v){e:{for(N=1,a=v[0];a>=10;a/=10,N++);if(k=I-N,k<0)k+=bt,m=I,l=v[h=0],y=Tn(l/M[N-m-1]%10);else if(h=Kd((k+1)/bt),h>=v.length)if(D){for(;v.length<=h;v.push(0));l=y=0,N=1,k%=bt,m=k-bt+1}else break e;else{for(l=a=v[h],N=1;a>=10;a/=10,N++);k%=bt,m=k-bt+N,y=m<0?0:Tn(l/M[N-m-1]%10)}if(D=D||I<0||v[h+1]!=null||(m<0?l:l%M[N-m-1]),D=C<4?(y||D)&&(C==0||C==(A.s<0?3:2)):y>5||y==5&&(C==4||D||C==6&&(k>0?m>0?l/M[N-m]:0:v[h-1])%10&1||C==(A.s<0?8:7)),I<1||!v[0])return v.length=0,D?(I-=A.e+1,v[0]=M[(bt-I%bt)%bt],A.e=-I||0):v[0]=A.e=0,A;if(k==0?(v.length=h,a=1,h--):(v.length=h+1,a=M[bt-k],v[h]=m>0?Tn(l/M[N-m]%M[m])*a:0),D)for(;;)if(h==0){for(k=1,m=v[0];m>=10;m/=10,k++);for(m=v[0]+=a,a=1;m>=10;m/=10,a++);k!=a&&(A.e++,v[0]==ui&&(v[0]=1));break}else{if(v[h]+=a,v[h]!=ui)break;v[h--]=0,a=1}for(k=v.length;v[--k]===0;v.pop());}A.e>_?A.c=A.e=null:A.e<p&&(A.c=[A.e=0])}return A}function he(A){var I,C=A.e;return C===null?A.toString():(I=In(A.c),I=C<=c||C>=d?Wc(I,C):os(I,C,"0"),A.s<0?"-"+I:I)}return i.absoluteValue=i.abs=function(){var A=new H(this);return A.s<0&&(A.s=1),A},i.comparedTo=function(A,I){return No(this,new H(A,I))},i.decimalPlaces=i.dp=function(A,I){var C,D,N,k=this;if(A!=null)return ir(A,0,Er),I==null?I=u:ir(I,0,8),te(new H(k),A+k.e+1,I);if(!(C=k.c))return null;if(D=((N=C.length-1)-xn(this.e/bt))*bt,N=C[N])for(;N%10==0;N/=10,D--);return D<0&&(D=0),D},i.dividedBy=i.div=function(A,I){return e(this,new H(A,I),o,u)},i.dividedToIntegerBy=i.idiv=function(A,I){return e(this,new H(A,I),0,1)},i.exponentiatedBy=i.pow=function(A,I){var C,D,N,k,m,a,l,h,y,v=this;if(A=new H(A),A.c&&!A.isInteger())throw Error(cn+"Exponent not an integer: "+he(A));if(I!=null&&(I=new H(I)),a=A.e>14,!v.c||!v.c[0]||v.c[0]==1&&!v.e&&v.c.length==1||!A.c||!A.c[0])return y=new H(Math.pow(+he(v),a?A.s*(2-Hc(A)):+he(A))),I?y.mod(I):y;if(l=A.s<0,I){if(I.c?!I.c[0]:!I.s)return new H(NaN);D=!l&&v.isInteger()&&I.isInteger(),D&&(v=v.mod(I))}else{if(A.e>9&&(v.e>0||v.e<-1||(v.e==0?v.c[0]>1||a&&v.c[1]>=24e7:v.c[0]<8e13||a&&v.c[0]<=9999975e7)))return k=v.s<0&&Hc(A)?-0:0,v.e>-1&&(k=1/k),new H(l?1/k:k);T&&(k=Kd(T/bt+2))}for(a?(C=new H(.5),l&&(A.s=1),h=Hc(A)):(N=Math.abs(+he(A)),h=N%2),y=new H(s);;){if(h){if(y=y.times(v),!y.c)break;k?y.c.length>k&&(y.c.length=k):D&&(y=y.mod(I))}if(N){if(N=Tn(N/2),N===0)break;h=N%2}else if(A=A.times(C),te(A,A.e+1,1),A.e>14)h=Hc(A);else{if(N=+he(A),N===0)break;h=N%2}v=v.times(v),k?v.c&&v.c.length>k&&(v.c.length=k):D&&(v=v.mod(I))}return D?y:(l&&(y=s.div(y)),I?y.mod(I):k?te(y,T,u,m):y)},i.integerValue=function(A){var I=new H(this);return A==null?A=u:ir(A,0,8),te(I,I.e+1,A)},i.isEqualTo=i.eq=function(A,I){return No(this,new H(A,I))===0},i.isFinite=function(){return!!this.c},i.isGreaterThan=i.gt=function(A,I){return No(this,new H(A,I))>0},i.isGreaterThanOrEqualTo=i.gte=function(A,I){return(I=No(this,new H(A,I)))===1||I===0},i.isInteger=function(){return!!this.c&&xn(this.e/bt)>this.c.length-2},i.isLessThan=i.lt=function(A,I){return No(this,new H(A,I))<0},i.isLessThanOrEqualTo=i.lte=function(A,I){return(I=No(this,new H(A,I)))===-1||I===0},i.isNaN=function(){return!this.s},i.isNegative=function(){return this.s<0},i.isPositive=function(){return this.s>0},i.isZero=function(){return!!this.c&&this.c[0]==0},i.minus=function(A,I){var C,D,N,k,m=this,a=m.s;if(A=new H(A,I),I=A.s,!a||!I)return new H(NaN);if(a!=I)return A.s=-I,m.plus(A);var l=m.e/bt,h=A.e/bt,y=m.c,v=A.c;if(!l||!h){if(!y||!v)return y?(A.s=-I,A):new H(v?m:NaN);if(!y[0]||!v[0])return v[0]?(A.s=-I,A):new H(y[0]?m:u==3?-0:0)}if(l=xn(l),h=xn(h),y=y.slice(),a=l-h){for((k=a<0)?(a=-a,N=y):(h=l,N=v),N.reverse(),I=a;I--;N.push(0));N.reverse()}else for(D=(k=(a=y.length)<(I=v.length))?a:I,a=I=0;I<D;I++)if(y[I]!=v[I]){k=y[I]<v[I];break}if(k&&(N=y,y=v,v=N,A.s=-A.s),I=(D=v.length)-(C=y.length),I>0)for(;I--;y[C++]=0);for(I=ui-1;D>a;){if(y[--D]<v[D]){for(C=D;C&&!y[--C];y[C]=I);--y[C],y[D]+=ui}y[D]-=v[D]}for(;y[0]==0;y.splice(0,1),--h);return y[0]?ae(A,y,h):(A.s=u==3?-1:1,A.c=[A.e=0],A)},i.modulo=i.mod=function(A,I){var C,D,N=this;return A=new H(A,I),!N.c||!A.s||A.c&&!A.c[0]?new H(NaN):!A.c||N.c&&!N.c[0]?new H(N):(O==9?(D=A.s,A.s=1,C=e(N,A,0,3),A.s=D,C.s*=D):C=e(N,A,0,O),A=N.minus(C.times(A)),!A.c[0]&&O==1&&(A.s=N.s),A)},i.multipliedBy=i.times=function(A,I){var C,D,N,k,m,a,l,h,y,v,M,w,g,f,S,V=this,z=V.c,Z=(A=new H(A,I)).c;if(!z||!Z||!z[0]||!Z[0])return!V.s||!A.s||z&&!z[0]&&!Z||Z&&!Z[0]&&!z?A.c=A.e=A.s=null:(A.s*=V.s,!z||!Z?A.c=A.e=null:(A.c=[0],A.e=0)),A;for(D=xn(V.e/bt)+xn(A.e/bt),A.s*=V.s,l=z.length,v=Z.length,l<v&&(g=z,z=Z,Z=g,N=l,l=v,v=N),N=l+v,g=[];N--;g.push(0));for(f=ui,S=Rs,N=v;--N>=0;){for(C=0,M=Z[N]%S,w=Z[N]/S|0,m=l,k=N+m;k>N;)h=z[--m]%S,y=z[m]/S|0,a=w*h+y*M,h=M*h+a%S*S+g[k]+C,C=(h/f|0)+(a/S|0)+w*y,g[k--]=h%f;g[k]=C}return C?++D:g.splice(0,1),ae(A,g,D)},i.negated=function(){var A=new H(this);return A.s=-A.s||null,A},i.plus=function(A,I){var C,D=this,N=D.s;if(A=new H(A,I),I=A.s,!N||!I)return new H(NaN);if(N!=I)return A.s=-I,D.minus(A);var k=D.e/bt,m=A.e/bt,a=D.c,l=A.c;if(!k||!m){if(!a||!l)return new H(N/0);if(!a[0]||!l[0])return l[0]?A:new H(a[0]?D:N*0)}if(k=xn(k),m=xn(m),a=a.slice(),N=k-m){for(N>0?(m=k,C=l):(N=-N,C=a),C.reverse();N--;C.push(0));C.reverse()}for(N=a.length,I=l.length,N-I<0&&(C=l,l=a,a=C,I=N),N=0;I;)N=(a[--I]=a[I]+l[I]+N)/ui|0,a[I]=ui===a[I]?0:a[I]%ui;return N&&(a=[N].concat(a),++m),ae(A,a,m)},i.precision=i.sd=function(A,I){var C,D,N,k=this;if(A!=null&&A!==!!A)return ir(A,1,Er),I==null?I=u:ir(I,0,8),te(new H(k),A,I);if(!(C=k.c))return null;if(N=C.length-1,D=N*bt+1,N=C[N]){for(;N%10==0;N/=10,D--);for(N=C[0];N>=10;N/=10,D++);}return A&&k.e+1>D&&(D=k.e+1),D},i.shiftedBy=function(A){return ir(A,-Xd,Xd),this.times("1e"+A)},i.squareRoot=i.sqrt=function(){var A,I,C,D,N,k=this,m=k.c,a=k.s,l=k.e,h=o+4,y=new H("0.5");if(a!==1||!m||!m[0])return new H(!a||a<0&&(!m||m[0])?NaN:m?k:1/0);if(a=Math.sqrt(+he(k)),a==0||a==1/0?(I=In(m),(I.length+l)%2==0&&(I+="0"),a=Math.sqrt(+I),l=xn((l+1)/2)-(l<0||l%2),a==1/0?I="5e"+l:(I=a.toExponential(),I=I.slice(0,I.indexOf("e")+1)+l),C=new H(I)):C=new H(a+""),C.c[0]){for(l=C.e,a=l+h,a<3&&(a=0);;)if(N=C,C=y.times(N.plus(e(k,N,h,1))),In(N.c).slice(0,a)===(I=In(C.c)).slice(0,a))if(C.e<l&&--a,I=I.slice(a-3,a+1),I=="9999"||!D&&I=="4999"){if(!D&&(te(N,N.e+o+2,0),N.times(N).eq(k))){C=N;break}h+=4,a+=4,D=1}else{(!+I||!+I.slice(1)&&I.charAt(0)=="5")&&(te(C,C.e+o+2,1),A=!C.times(C).eq(k));break}}return te(C,C.e+o+1,u,A)},i.toExponential=function(A,I){return A!=null&&(ir(A,0,Er),A++),J(this,A,I,1)},i.toFixed=function(A,I){return A!=null&&(ir(A,0,Er),A=A+this.e+1),J(this,A,I)},i.toFormat=function(A,I,C){var D,N=this;if(C==null)A!=null&&I&&typeof I=="object"?(C=I,I=null):A&&typeof A=="object"?(C=A,A=I=null):C=x;else if(typeof C!="object")throw Error(cn+"Argument not an object: "+C);if(D=N.toFixed(A,I),N.c){var k,m=D.split("."),a=+C.groupSize,l=+C.secondaryGroupSize,h=C.groupSeparator||"",y=m[0],v=m[1],M=N.s<0,w=M?y.slice(1):y,g=w.length;if(l&&(k=a,a=l,l=k,g-=k),a>0&&g>0){for(k=g%a||a,y=w.substr(0,k);k<g;k+=a)y+=h+w.substr(k,a);l>0&&(y+=h+w.slice(k)),M&&(y="-"+y)}D=v?y+(C.decimalSeparator||"")+((l=+C.fractionGroupSize)?v.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(C.fractionGroupSeparator||"")):v):y}return(C.prefix||"")+D+(C.suffix||"")},i.toFraction=function(A){var I,C,D,N,k,m,a,l,h,y,v,M,w=this,g=w.c;if(A!=null&&(a=new H(A),!a.isInteger()&&(a.c||a.s!==1)||a.lt(s)))throw Error(cn+"Argument "+(a.isInteger()?"out of range: ":"not an integer: ")+he(a));if(!g)return new H(w);for(I=new H(s),h=C=new H(s),D=l=new H(s),M=In(g),k=I.e=M.length-w.e-1,I.c[0]=Jd[(m=k%bt)<0?bt+m:m],A=!A||a.comparedTo(I)>0?k>0?I:h:a,m=_,_=1/0,a=new H(M),l.c[0]=0;y=e(a,I,0,1),N=C.plus(y.times(D)),N.comparedTo(A)!=1;)C=D,D=N,h=l.plus(y.times(N=h)),l=N,I=a.minus(y.times(N=I)),a=N;return N=e(A.minus(C),D,0,1),l=l.plus(N.times(h)),C=C.plus(N.times(D)),l.s=h.s=w.s,k=k*2,v=e(h,D,k,u).minus(w).abs().comparedTo(e(l,C,k,u).minus(w).abs())<1?[h,D]:[l,C],_=m,v},i.toNumber=function(){return+he(this)},i.toPrecision=function(A,I){return A!=null&&ir(A,1,Er),J(this,A,I,2)},i.toString=function(A){var I,C=this,D=C.s,N=C.e;return N===null?D?(I="Infinity",D<0&&(I="-"+I)):I="NaN":(A==null?I=N<=c||N>=d?Wc(In(C.c),N):os(In(C.c),N,"0"):A===10&&R?(C=te(new H(C),o+N+1,u),I=os(In(C.c),C.e,"0")):(ir(A,2,F.length,"Base"),I=r(os(In(C.c),N,"0"),10,A,D,!0)),D<0&&C.c[0]&&(I="-"+I)),I},i.valueOf=i.toJSON=function(){return he(this)},i._isBigNumber=!0,i[Symbol.toStringTag]="BigNumber",i[Symbol.for("nodejs.util.inspect.custom")]=i.valueOf,t!=null&&H.set(t),H}function xn(t){var e=t|0;return t>0||t===e?e:e-1}function In(t){for(var e,r,n=1,i=t.length,s=t[0]+"";n<i;){for(e=t[n++]+"",r=bt-e.length;r--;e="0"+e);s+=e}for(i=s.length;s.charCodeAt(--i)===48;);return s.slice(0,i+1||1)}function No(t,e){var r,n,i=t.c,s=e.c,o=t.s,u=e.s,c=t.e,d=e.e;if(!o||!u)return null;if(r=i&&!i[0],n=s&&!s[0],r||n)return r?n?0:-u:o;if(o!=u)return o;if(r=o<0,n=c==d,!i||!s)return n?0:!i^r?1:-1;if(!n)return c>d^r?1:-1;for(u=(c=i.length)<(d=s.length)?c:d,o=0;o<u;o++)if(i[o]!=s[o])return i[o]>s[o]^r?1:-1;return c==d?0:c>d^r?1:-1}function ir(t,e,r,n){if(t<e||t>r||t!==Tn(t))throw Error(cn+(n||"Argument")+(typeof t=="number"?t<e||t>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function Hc(t){var e=t.c.length-1;return xn(t.e/bt)==e&&t.c[e]%2!=0}function Wc(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function os(t,e,r){var n,i;if(e<0){for(i=r+".";++e;i+=r);t=i+t}else if(n=t.length,++e>n){for(i=r,e-=n;--e;i+=r);t+=i}else e<n&&(t=t.slice(0,e)+"."+t.slice(e));return t}var ex=__(),Ci=ex;import{linearlyInterpolate as ix,Side as Do}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as sx,NORMALIZED_jugSUI_COINTYPE as ox,NORMALIZED_LBTC_COINTYPE as ax}from"@suilend/sui-fe";import tx from"crypto";var Xc=new Uint8Array(256),Kc=Xc.length;function Zd(){return Kc>Xc.length-16&&(tx.randomFillSync(Xc),Kc=0),Xc.slice(Kc,Kc+=16)}var Pr=[];for(let t=0;t<256;++t)Pr.push((t+256).toString(16).slice(1));function v_(t,e=0){return Pr[t[e+0]]+Pr[t[e+1]]+Pr[t[e+2]]+Pr[t[e+3]]+"-"+Pr[t[e+4]]+Pr[t[e+5]]+"-"+Pr[t[e+6]]+Pr[t[e+7]]+"-"+Pr[t[e+8]]+Pr[t[e+9]]+"-"+Pr[t[e+10]]+Pr[t[e+11]]+Pr[t[e+12]]+Pr[t[e+13]]+Pr[t[e+14]]+Pr[t[e+15]]}import rx from"crypto";var Yd={randomUUID:rx.randomUUID};function nx(t,e,r){if(Yd.randomUUID&&!e&&!t)return Yd.randomUUID();t=t||{};let n=t.random||(t.rng||Zd)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){r=r||0;for(let i=0;i<16;++i)e[r+i]=n[i];return e}return v_(n)}var Jc=nx;import{getPackagerConfigs as ux}from"@cetusprotocol/common-sdk";var Qd=10n;function b_(t){return t.depositedAmount.eq(0)?new Ci(0):t.borrowedAmount.div(t.depositedAmount).times(100)}function eh(t){let e=b_(t);if(!e.gt(100))return ix(t.config.interestRate,"utilPercent","aprPercent",e)}function w_(t){let e=b_(t),r=eh(t);if(!(r===void 0||e.gt(100)))return new Ci(e.div(100)).times(r.div(100)).times(1-t.config.spreadFeeBps/1e4).times(100)}function M_(t,e,r,n){let{apiUrl:i}=ux(n.sdkOptions.suilend);t===Do.DEPOSIT&&([sx,ox].includes(e.coinType)&&r.push({stats:{id:Jc(),isActive:!0,rewardIndex:-1,reserve:e,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${i}/partners/LiqAg.png`,perDay:new Ci(.036),side:Do.DEPOSIT},obligationClaims:{}}),e.coinType===ax&&r.push({stats:{id:Jc(),isActive:!0,rewardIndex:-1,reserve:e,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${i}/partners/Lombard Lux.png`,perDay:new Ci(0),side:Do.DEPOSIT},obligationClaims:{}}))}function S_(t,e,r){return{...t,depositedAmount:e===Do.DEPOSIT?Ci.max(t.depositedAmount.plus(r),0):t.depositedAmount,borrowedAmount:e===Do.BORROW?Ci.max(t.borrowedAmount.plus(r),0):t.borrowedAmount}}function k_(t,e,r){let n=t===Do.DEPOSIT?e.depositedAmount:e.borrowedAmount,i=t===Do.DEPOSIT?r.depositedAmount:r.borrowedAmount,s=i.eq(0)?new Ci(-1):n.div(i);return{multiplier:s,isValid:!s.eq(-1)}}function O_(t,e,r,n){let i=t.map(o=>({...o,stats:{...o.stats,perDay:n?o.stats.perDay.times(r):void 0}})),s=e.map(o=>({...o,stats:{...o.stats,aprPercent:n?o.stats.aprPercent.times(r):void 0}}));return{newPerDayRewards:i,newAprRewards:s}}function E_(t,e){if(!Qd)throw new Error("oraclePriceMultiplierDecimal is required");if(t===0n)throw new Error("Invalid oracle price");if(e<0n){let r=10n**(Qd- -e);return t*r}return t/10n**(e+Qd)}import{d as Cu,getPackagerConfigs as Oa,removeHexPrefix as pv}from"@cetusprotocol/common-sdk";function cx(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function I_(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function th(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function T_(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function rh(t){if(!Array.isArray(t))throw new Error("array expected")}function x_(t,e){if(!I_(!0,e))throw new Error(`${t}: array of strings expected`)}function lx(t,e){if(!I_(!1,e))throw new Error(`${t}: array of numbers expected`)}function fx(...t){let e=s=>s,r=(s,o)=>u=>s(o(u)),n=t.map(s=>s.encode).reduceRight(r,e),i=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:i}}function dx(t){let e=typeof t=="string"?t.split(""):t,r=e.length;x_("alphabet",e);let n=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(rh(i),i.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:i=>(rh(i),i.map(s=>{th("alphabet.decode",s);let o=n.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function hx(t=""){return th("join",t),{encode:e=>(x_("join.decode",e),e.join(t)),decode:e=>(th("join.decode",e),e.split(t))}}function A_(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(rh(t),!t.length)return[];let n=0,i=[],s=Array.from(t,u=>{if(T_(u),u<0||u>=e)throw new Error(`invalid integer: ${u}`);return u}),o=s.length;for(;;){let u=0,c=!0;for(let d=n;d<o;d++){let p=s[d],_=e*u,b=_+p;if(!Number.isSafeInteger(b)||_/e!==u||b-p!==_)throw new Error("convertRadix: carry overflow");let O=b/r;u=b%r;let T=Math.floor(O);if(s[d]=T,!Number.isSafeInteger(T)||T*r+u!==b)throw new Error("convertRadix: carry overflow");if(c)T?c=!1:n=d;else continue}if(i.push(u),c)break}for(let u=0;u<t.length-1&&t[u]===0;u++)i.push(0);return i.reverse()}function px(t){T_(t);let e=2**8;return{encode:r=>{if(!cx(r))throw new Error("radix.encode input should be Uint8Array");return A_(Array.from(r),e,t)},decode:r=>(lx("radix.decode",r),Uint8Array.from(A_(r,t,e)))}}var mx=t=>fx(px(58),dx(t),hx("")),nh=mx("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var ci=t=>nh.encode(t),yn=t=>nh.decode(t);function sr(t){return Uint8Array.from(atob(t),e=>e.charCodeAt(0))}var ih=8192;function Ht(t){if(t.length<ih)return btoa(String.fromCharCode(...t));let e="";for(var r=0;r<t.length;r+=ih){let n=t.slice(r,r+ih);e+=String.fromCharCode(...n)}return btoa(e)}function Us(t){let e=t.startsWith("0x")?t.slice(2):t,r=e.length%2===0?e:`0${e}`,n=r.match(/[0-9a-fA-F]{2}/g)?.map(i=>parseInt(i,16))??[];if(n.length!==r.length/2)throw new Error(`Invalid hex string ${t}`);return Uint8Array.from(n)}function Qr(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function Ls(t,e){return Array.from({length:Math.ceil(t.length/e)},(r,n)=>t.slice(n*e,(n+1)*e))}var ba=class{constructor(e,r){if(typeof e!="function")throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: ${e}.`);this._batchLoadFn=e,this._maxBatchSize=vx(r),this._batchScheduleFn=bx(r),this._cacheKeyFn=wx(r),this._cacheMap=Mx(r),this._batch=null,this.name=Sx(r)}load(e){if(e==null)throw new TypeError(`The loader.load() function must be called with a value, but got: ${String(e)}.`);let r=yx(this),n=this._cacheMap,i;if(n){i=this._cacheKeyFn(e);let o=n.get(i);if(o){let u=r.cacheHits||(r.cacheHits=[]);return new Promise(c=>{u.push(()=>{c(o)})})}}r.keys.push(e);let s=new Promise((o,u)=>{r.callbacks.push({resolve:o,reject:u})});return n&&n.set(i,s),s}loadMany(e){if(!P_(e))throw new TypeError(`The loader.loadMany() function must be called with Array<key>, but got: ${e}.`);let r=[];for(let n=0;n<e.length;n++)r.push(this.load(e[n]).catch(i=>i));return Promise.all(r)}clear(e){let r=this._cacheMap;if(r){let n=this._cacheKeyFn(e);r.delete(n)}return this}clearAll(){let e=this._cacheMap;return e&&e.clear(),this}prime(e,r){let n=this._cacheMap;if(n){let i=this._cacheKeyFn(e);if(n.get(i)===void 0){let s;r instanceof Error?(s=Promise.reject(r),s.catch(()=>{})):s=Promise.resolve(r),n.set(i,s)}}return this}},gx=typeof process=="object"&&typeof process.nextTick=="function"?function(t){sh||(sh=Promise.resolve()),sh.then(()=>{process.nextTick(t)})}:typeof setImmediate=="function"?function(t){setImmediate(t)}:function(t){setTimeout(t)},sh;function yx(t){let e=t._batch;if(e!==null&&!e.hasDispatched&&e.keys.length<t._maxBatchSize)return e;let r={hasDispatched:!1,keys:[],callbacks:[]};return t._batch=r,t._batchScheduleFn(()=>{_x(t,r)}),r}function _x(t,e){if(e.hasDispatched=!0,e.keys.length===0){ah(e);return}let r;try{r=t._batchLoadFn(e.keys)}catch(n){return oh(t,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: ${String(n)}.`))}if(!r||typeof r.then!="function")return oh(t,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: ${String(r)}.`));Promise.resolve(r).then(n=>{if(!P_(n))throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array: ${String(n)}.`);if(n.length!==e.keys.length)throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.
16
+
17
+ Keys:
18
+ ${String(e.keys)}
19
+
20
+ Values:
21
+ ${String(n)}`);ah(e);for(let i=0;i<e.callbacks.length;i++){let s=n[i];s instanceof Error?e.callbacks[i].reject(s):e.callbacks[i].resolve(s)}}).catch(n=>{oh(t,e,n)})}function oh(t,e,r){ah(e);for(let n=0;n<e.keys.length;n++)t.clear(e.keys[n]),e.callbacks[n].reject(r)}function ah(t){if(t.cacheHits)for(let e=0;e<t.cacheHits.length;e++)t.cacheHits[e]()}function vx(t){if(!(!t||t.batch!==!1))return 1;let r=t&&t.maxBatchSize;if(r===void 0)return 1/0;if(typeof r!="number"||r<1)throw new TypeError(`maxBatchSize must be a positive number: ${r}`);return r}function bx(t){let e=t&&t.batchScheduleFn;if(e===void 0)return gx;if(typeof e!="function")throw new TypeError(`batchScheduleFn must be a function: ${e}`);return e}function wx(t){let e=t&&t.cacheKeyFn;if(e===void 0)return r=>r;if(typeof e!="function")throw new TypeError(`cacheKeyFn must be a function: ${e}`);return e}function Mx(t){if(!(!t||t.cache!==!1))return null;let r=t&&t.cacheMap;if(r===void 0)return new Map;if(r!==null){let i=["get","set","delete","clear"].filter(s=>r&&typeof r[s]!="function");if(i.length!==0)throw new TypeError("Custom cacheMap missing methods: "+i.join(", "))}return r}function Sx(t){return t&&t.name?t.name:null}function P_(t){return typeof t=="object"&&t!==null&&"length"in t&&typeof t.length=="number"&&(t.length===0||t.length>0&&Object.prototype.hasOwnProperty.call(t,t.length-1))}function Bo(t){let e=[],r=0;if(t===0)return[0];for(;t>0;)e[r]=t&127,(t>>=7)&&(e[r]|=128),r+=1;return e}function C_(t){let e=0,r=0,n=0;for(;;){let i=t[n];if(n+=1,e|=(i&127)<<r,(i&128)===0)break;r+=7}return{value:e,length:n}}var Zc=class{constructor(e){this.bytePosition=0,this.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength)}shift(e){return this.bytePosition+=e,this}read8(){let e=this.dataView.getUint8(this.bytePosition);return this.shift(1),e}read16(){let e=this.dataView.getUint16(this.bytePosition,!0);return this.shift(2),e}read32(){let e=this.dataView.getUint32(this.bytePosition,!0);return this.shift(4),e}read64(){let e=this.read32(),n=this.read32().toString(16)+e.toString(16).padStart(8,"0");return BigInt("0x"+n).toString(10)}read128(){let e=BigInt(this.read64()),n=BigInt(this.read64()).toString(16)+e.toString(16).padStart(16,"0");return BigInt("0x"+n).toString(10)}read256(){let e=BigInt(this.read128()),n=BigInt(this.read128()).toString(16)+e.toString(16).padStart(32,"0");return BigInt("0x"+n).toString(10)}readBytes(e){let r=this.bytePosition+this.dataView.byteOffset,n=new Uint8Array(this.dataView.buffer,r,e);return this.shift(e),n}readULEB(){let e=this.bytePosition+this.dataView.byteOffset,r=new Uint8Array(this.dataView.buffer,e),{value:n,length:i}=C_(r);return this.shift(i),n}readVec(e){let r=this.readULEB(),n=[];for(let i=0;i<r;i++)n.push(e(this,i,r));return n}};function uh(t,e){switch(e){case"base58":return ci(t);case"base64":return Ht(t);case"hex":return Qr(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function Iu(t,e=["<",">"]){let[r,n]=e,i=[],s="",o=0;for(let u=0;u<t.length;u++){let c=t[u];if(c===r&&o++,c===n&&o--,o===0&&c===","){i.push(s.trim()),s="";continue}s+=c}return i.push(s.trim()),i}var Yc=class{constructor({initialSize:e=1024,maxSize:r=1/0,allocateSize:n=1024}={}){this.bytePosition=0,this.size=e,this.maxSize=r,this.allocateSize=n,this.dataView=new DataView(new ArrayBuffer(e))}ensureSizeOrGrow(e){let r=this.bytePosition+e;if(r>this.size){let n=Math.min(this.maxSize,this.size+this.allocateSize);if(r>n)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${r}`);this.size=n;let i=new ArrayBuffer(this.size);new Uint8Array(i).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(i)}}shift(e){return this.bytePosition+=e,this}write8(e){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(e)),this.shift(1)}write16(e){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(e),!0),this.shift(2)}write32(e){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(e),!0),this.shift(4)}write64(e){return ch(BigInt(e),8).forEach(r=>this.write8(r)),this}write128(e){return ch(BigInt(e),16).forEach(r=>this.write8(r)),this}write256(e){return ch(BigInt(e),32).forEach(r=>this.write8(r)),this}writeULEB(e){return Bo(e).forEach(r=>this.write8(r)),this}writeVec(e,r){return this.writeULEB(e.length),Array.from(e).forEach((n,i)=>r(this,n,i,e.length)),this}*[Symbol.iterator](){for(let e=0;e<this.bytePosition;e++)yield this.dataView.getUint8(e);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(e){return uh(this.toBytes(),e)}};function ch(t,e){let r=new Uint8Array(e),n=0;for(;t>0;)r[n]=Number(t%BigInt(256)),t=t/BigInt(256),n+=1;return r}var j_=t=>{throw TypeError(t)},N_=(t,e,r)=>e.has(t)||j_("Cannot "+r),li=(t,e,r)=>(N_(t,e,"read from private field"),r?r.call(t):e.get(t)),el=(t,e,r)=>e.has(t)?j_("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),tl=(t,e,r,n)=>(N_(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),wa,Tu,Qc,$s,kx=class D_{constructor(e){el(this,wa),el(this,Tu),this.name=e.name,this.read=e.read,this.serializedSize=e.serializedSize??(()=>null),tl(this,wa,e.write),tl(this,Tu,e.serialize??((r,n)=>{let i=new Yc({initialSize:this.serializedSize(r)??void 0,...n});return li(this,wa).call(this,r,i),i.toBytes()})),this.validate=e.validate??(()=>{})}write(e,r){this.validate(e),li(this,wa).call(this,e,r)}serialize(e,r){return this.validate(e),new rl(this,li(this,Tu).call(this,e,r))}parse(e){let r=new Zc(e);return this.read(r)}fromHex(e){return this.parse(Us(e))}fromBase58(e){return this.parse(yn(e))}fromBase64(e){return this.parse(sr(e))}transform({name:e,input:r,output:n,validate:i}){return new D_({name:e??this.name,read:s=>n?n(this.read(s)):this.read(s),write:(s,o)=>li(this,wa).call(this,r?r(s):s,o),serializedSize:s=>this.serializedSize(r?r(s):s),serialize:(s,o)=>li(this,Tu).call(this,r?r(s):s,o),validate:s=>{i?.(s),this.validate(r?r(s):s)}})}};wa=new WeakMap;Tu=new WeakMap;var Pn=kx,B_=Symbol.for("@mysten/serialized-bcs");function Ma(t){return!!t&&typeof t=="object"&&t[B_]===!0}var rl=class{constructor(e,r){el(this,Qc),el(this,$s),tl(this,Qc,e),tl(this,$s,r)}get[B_](){return!0}toBytes(){return li(this,$s)}toHex(){return Qr(li(this,$s))}toBase64(){return Ht(li(this,$s))}toBase58(){return ci(li(this,$s))}parse(){return li(this,Qc).parse(li(this,$s))}};Qc=new WeakMap;$s=new WeakMap;function xu({size:t,...e}){return new Pn({...e,serializedSize:()=>t})}function nl({readMethod:t,writeMethod:e,...r}){return xu({...r,read:n=>n[t](),write:(n,i)=>i[e](n),validate:n=>{if(n<0||n>r.maxValue)throw new TypeError(`Invalid ${r.name} value: ${n}. Expected value in range 0-${r.maxValue}`);r.validate?.(n)}})}function il({readMethod:t,writeMethod:e,...r}){return xu({...r,read:n=>n[t](),write:(n,i)=>i[e](BigInt(n)),validate:n=>{let i=BigInt(n);if(i<0||i>r.maxValue)throw new TypeError(`Invalid ${r.name} value: ${i}. Expected value in range 0-${r.maxValue}`);r.validate?.(i)}})}function R_({serialize:t,...e}){let r=new Pn({...e,serialize:t,write:(n,i)=>{for(let s of r.serialize(n).toBytes())i.write8(s)}});return r}function U_({toBytes:t,fromBytes:e,...r}){return new Pn({...r,read:n=>{let i=n.readULEB(),s=n.readBytes(i);return e(s)},write:(n,i)=>{let s=t(n);i.writeULEB(s.length);for(let o=0;o<s.length;o++)i.write8(s[o])},serialize:n=>{let i=t(n),s=Bo(i.length),o=new Uint8Array(s.length+i.length);return o.set(s,0),o.set(i,s.length),o},validate:n=>{if(typeof n!="string")throw new TypeError(`Invalid ${r.name} value: ${n}. Expected string`);r.validate?.(n)}})}function L_(t){let e=null;function r(){return e||(e=t()),e}return new Pn({name:"lazy",read:n=>r().read(n),serializedSize:n=>r().serializedSize(n),write:(n,i)=>r().write(n,i),serialize:(n,i)=>r().serialize(n,i).toBytes()})}var B={u8(t){return nl({name:"u8",readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...t})},u16(t){return nl({name:"u16",readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...t})},u32(t){return nl({name:"u32",readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...t})},u64(t){return il({name:"u64",readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...t})},u128(t){return il({name:"u128",readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...t})},u256(t){return il({name:"u256",readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...t})},bool(t){return xu({name:"bool",size:1,read:e=>e.read8()===1,write:(e,r)=>r.write8(e?1:0),...t,validate:e=>{if(t?.validate?.(e),typeof e!="boolean")throw new TypeError(`Expected boolean, found ${typeof e}`)}})},uleb128(t){return R_({name:"uleb128",read:e=>e.readULEB(),serialize:e=>Uint8Array.from(Bo(e)),...t})},bytes(t,e){return xu({name:`bytes[${t}]`,size:t,read:r=>r.readBytes(t),write:(r,n)=>{let i=new Uint8Array(r);for(let s=0;s<t;s++)n.write8(i[s]??0)},...e,validate:r=>{if(e?.validate?.(r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`);if(r.length!==t)throw new TypeError(`Expected array of length ${t}, found ${r.length}`)}})},byteVector(t){return new Pn({name:"bytesVector",read:e=>{let r=e.readULEB();return e.readBytes(r)},write:(e,r)=>{let n=new Uint8Array(e);r.writeULEB(n.length);for(let i=0;i<n.length;i++)r.write8(n[i]??0)},...t,serializedSize:e=>{let r="length"in e?e.length:null;return r==null?null:Bo(r).length+r},validate:e=>{if(t?.validate?.(e),!e||typeof e!="object"||!("length"in e))throw new TypeError(`Expected array, found ${typeof e}`)}})},string(t){return U_({name:"string",toBytes:e=>new TextEncoder().encode(e),fromBytes:e=>new TextDecoder().decode(e),...t})},fixedArray(t,e,r){return new Pn({name:`${e.name}[${t}]`,read:n=>{let i=new Array(t);for(let s=0;s<t;s++)i[s]=e.read(n);return i},write:(n,i)=>{for(let s of n)e.write(s,i)},...r,validate:n=>{if(r?.validate?.(n),!n||typeof n!="object"||!("length"in n))throw new TypeError(`Expected array, found ${typeof n}`);if(n.length!==t)throw new TypeError(`Expected array of length ${t}, found ${n.length}`)}})},option(t){return B.enum(`Option<${t.name}>`,{None:null,Some:t}).transform({input:e=>e==null?{None:!0}:{Some:e},output:e=>e.$kind==="Some"?e.Some:null})},vector(t,e){return new Pn({name:`vector<${t.name}>`,read:r=>{let n=r.readULEB(),i=new Array(n);for(let s=0;s<n;s++)i[s]=t.read(r);return i},write:(r,n)=>{n.writeULEB(r.length);for(let i of r)t.write(i,n)},...e,validate:r=>{if(e?.validate?.(r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`)}})},tuple(t,e){return new Pn({name:`(${t.map(r=>r.name).join(", ")})`,serializedSize:r=>{let n=0;for(let i=0;i<t.length;i++){let s=t[i].serializedSize(r[i]);if(s==null)return null;n+=s}return n},read:r=>{let n=[];for(let i of t)n.push(i.read(r));return n},write:(r,n)=>{for(let i=0;i<t.length;i++)t[i].write(r[i],n)},...e,validate:r=>{if(e?.validate?.(r),!Array.isArray(r))throw new TypeError(`Expected array, found ${typeof r}`);if(r.length!==t.length)throw new TypeError(`Expected array of length ${t.length}, found ${r.length}`)}})},struct(t,e,r){let n=Object.entries(e);return new Pn({name:t,serializedSize:i=>{let s=0;for(let[o,u]of n){let c=u.serializedSize(i[o]);if(c==null)return null;s+=c}return s},read:i=>{let s={};for(let[o,u]of n)s[o]=u.read(i);return s},write:(i,s)=>{for(let[o,u]of n)u.write(i[o],s)},...r,validate:i=>{if(r?.validate?.(i),typeof i!="object"||i==null)throw new TypeError(`Expected object, found ${typeof i}`)}})},enum(t,e,r){let n=Object.entries(e);return new Pn({name:t,read:i=>{let s=i.readULEB(),o=n[s];if(!o)throw new TypeError(`Unknown value ${s} for enum ${t}`);let[u,c]=o;return{[u]:c?.read(i)??!0,$kind:u}},write:(i,s)=>{let[o,u]=Object.entries(i).filter(([c])=>Object.hasOwn(e,c))[0];for(let c=0;c<n.length;c++){let[d,p]=n[c];if(d===o){s.writeULEB(c),p?.write(u,s);return}}},...r,validate:i=>{if(r?.validate?.(i),typeof i!="object"||i==null)throw new TypeError(`Expected object, found ${typeof i}`);let s=Object.keys(i).filter(u=>i[u]!==void 0&&Object.hasOwn(e,u));if(s.length!==1)throw new TypeError(`Expected object with one key, but found ${s.length} for type ${t}}`);let[o]=s;if(!Object.hasOwn(e,o))throw new TypeError(`Invalid enum variant ${o}`)}})},map(t,e){return B.vector(B.tuple([t,e])).transform({name:`Map<${t.name}, ${e.name}>`,input:r=>[...r.entries()],output:r=>{let n=new Map;for(let[i,s]of r)n.set(i,s);return n}})},lazy(t){return L_(t)}};var as=Qr;var $_=/^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i,F_=/^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i;function q_(t){return t.length>235?!1:t.includes("@")?$_.test(t):F_.test(t)}function V_(t,e="at"){let r=t.toLowerCase(),n;if(r.includes("@")){if(!$_.test(r))throw new Error(`Invalid SuiNS name ${t}`);let[i,s]=r.split("@");n=[...i?i.split("."):[],s]}else{if(!F_.test(r))throw new Error(`Invalid SuiNS name ${t}`);n=r.split(".").slice(0,-1)}return e==="dot"?`${n.join(".")}.sui`:`${n.slice(0,-1).join(".")}@${n[n.length-1]}`}var Ox=/^([a-z0-9]+(?:-[a-z0-9]+)*)$/,Ex=/^\d+$/,Ax=64,z_="/",$r=t=>{let e=t.split(z_);if(e.length<2||e.length>3)return!1;let[r,n,i]=e;return i!==void 0&&!Ex.test(i)||!q_(r)?!1:Ox.test(n)&&n.length<Ax},G_=t=>{let e=t.split(/::|<|>|,/);for(let r of e)if(r.includes(z_)&&!$r(r))return!1;return!0};var Ix=32;function sl(t){try{return yn(t).length===Ix}catch{return!1}}var Ro=32;function Fr(t){return xx(t)&&Px(t)===Ro}function Fs(t){return Fr(t)}function Tx(t){return t.includes("::")?ji(t):t}function ji(t){let[e,r]=t.split("::"),n=$r(e),i=t.slice(e.length+r.length+4),s=i.includes("<")?i.slice(0,i.indexOf("<")):i,o=i.includes("<")?Iu(i.slice(i.indexOf("<")+1,i.lastIndexOf(">"))).map(u=>Tx(u.trim())):[];return{address:n?e:$e(e),module:r,name:s,typeParams:o}}function Uo(t){let{address:e,module:r,name:n,typeParams:i}=typeof t=="string"?ji(t):t,s=i?.length>0?`<${i.map(o=>typeof o=="string"?o:Uo(o)).join(",")}>`:"";return`${e}::${r}::${n}${s}`}function $e(t,e=!1){let r=t.toLowerCase();return!e&&r.startsWith("0x")&&(r=r.slice(2)),`0x${r.padStart(Ro*2,"0")}`}function Ar(t,e=!1){return $e(t,e)}function xx(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2===0}function Px(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}var Cx=BigInt(1e9),lh="0x1",ol="0x2";var jx=Ar("0x6");var fh=`${ol}::sui::SUI`,al=Ar("0x5");function Nx(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function cl(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ll(t,...e){if(!Nx(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function dh(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function H_(t,e){ll(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Pu(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function fl(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}var W_=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function K_(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}var Ni=W_?t=>t:t=>K_(t);function Dx(t){for(let e=0;e<t.length;e++)t[e]=K_(t[e]);return t}var Lo=W_?t=>t:Dx;function Bx(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Sa(t){return typeof t=="string"&&(t=Bx(t)),ll(t),t}var ul=class{};function X_(t){let e=(n,i)=>t(i).update(Sa(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var J_=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);var dl=BigInt(4294967295),Z_=BigInt(32);function Y_(t,e=!1){return e?{h:Number(t&dl),l:Number(t>>Z_&dl)}:{h:Number(t>>Z_&dl)|0,l:Number(t&dl)|0}}var hh=(t,e,r)=>t>>>r|e<<32-r,ph=(t,e,r)=>t<<32-r|e>>>r,Q_=(t,e,r)=>t<<64-r|e>>>r-32,ev=(t,e,r)=>t>>>r-32|e<<64-r,tv=(t,e)=>e,rv=(t,e)=>t;function mh(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var gh=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),yh=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;var pr=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Se=new Uint32Array(32);function qs(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Se[2*t],d=Se[2*t+1],p=Se[2*e],_=Se[2*e+1],b=Se[2*r],O=Se[2*r+1],T=Se[2*n],x=Se[2*n+1],F=gh(c,p,o);d=yh(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:tv(x,T),Dl:rv(x,T)},{h:O,l:b}=mh(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:hh(_,p,24),Bl:ph(_,p,24)},Se[2*t]=c,Se[2*t+1]=d,Se[2*e]=p,Se[2*e+1]=_,Se[2*r]=b,Se[2*r+1]=O,Se[2*n]=T,Se[2*n+1]=x}function Vs(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Se[2*t],d=Se[2*t+1],p=Se[2*e],_=Se[2*e+1],b=Se[2*r],O=Se[2*r+1],T=Se[2*n],x=Se[2*n+1],F=gh(c,p,o);d=yh(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:hh(x,T,16),Dl:ph(x,T,16)},{h:O,l:b}=mh(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Q_(_,p,63),Bl:ev(_,p,63)},Se[2*t]=c,Se[2*t+1]=d,Se[2*e]=p,Se[2*e+1]=_,Se[2*r]=b,Se[2*r+1]=O,Se[2*n]=T,Se[2*n+1]=x}function Ux(t,e={},r,n,i){if(cl(r),t<0||t>r)throw new Error("outputLen bigger than keyLen");let{key:s,salt:o,personalization:u}=e;if(s!==void 0&&(s.length<1||s.length>r))throw new Error("key length must be undefined or 1.."+r);if(o!==void 0&&o.length!==n)throw new Error("salt must be undefined or "+n);if(u!==void 0&&u.length!==i)throw new Error("personalization must be undefined or "+i)}var _h=class extends ul{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,cl(e),cl(r),this.blockLen=e,this.outputLen=r,this.buffer=new Uint8Array(e),this.buffer32=Pu(this.buffer)}update(e){dh(this),e=Sa(e),ll(e);let{blockLen:r,buffer:n,buffer32:i}=this,s=e.length,o=e.byteOffset,u=e.buffer;for(let c=0;c<s;){this.pos===r&&(Lo(i),this.compress(i,0,!1),Lo(i),this.pos=0);let d=Math.min(r-this.pos,s-c),p=o+c;if(d===r&&!(p%4)&&c+d<s){let _=new Uint32Array(u,p,Math.floor((s-c)/4));Lo(_);for(let b=0;c+r<s;b+=i.length,c+=r)this.length+=r,this.compress(_,b,!1);Lo(_);continue}n.set(e.subarray(c,c+d),this.pos),this.pos+=d,this.length+=d,c+=d}return this}digestInto(e){dh(this),H_(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,fl(this.buffer.subarray(r)),Lo(n),this.compress(n,0,!0),Lo(n);let i=Pu(e);this.get().forEach((s,o)=>i[o]=Ni(s))}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){let{buffer:r,length:n,finished:i,destroyed:s,outputLen:o,pos:u}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(r),e.destroyed=s,e.finished=i,e.length=n,e.pos=u,e.outputLen=o,e}clone(){return this._cloneInto()}},hl=class extends _h{constructor(e={}){let r=e.dkLen===void 0?64:e.dkLen;super(128,r),this.v0l=pr[0]|0,this.v0h=pr[1]|0,this.v1l=pr[2]|0,this.v1h=pr[3]|0,this.v2l=pr[4]|0,this.v2h=pr[5]|0,this.v3l=pr[6]|0,this.v3h=pr[7]|0,this.v4l=pr[8]|0,this.v4h=pr[9]|0,this.v5l=pr[10]|0,this.v5h=pr[11]|0,this.v6l=pr[12]|0,this.v6h=pr[13]|0,this.v7l=pr[14]|0,this.v7h=pr[15]|0,Ux(r,e,64,16,16);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=Sa(n),o=n.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=Sa(s);let u=Pu(s);this.v4l^=Ni(u[0]),this.v4h^=Ni(u[1]),this.v5l^=Ni(u[2]),this.v5h^=Ni(u[3])}if(i!==void 0){i=Sa(i);let u=Pu(i);this.v6l^=Ni(u[0]),this.v6h^=Ni(u[1]),this.v7l^=Ni(u[2]),this.v7h^=Ni(u[3])}if(n!==void 0){let u=new Uint8Array(this.blockLen);u.set(n),this.update(u)}}get(){let{v0l:e,v0h:r,v1l:n,v1h:i,v2l:s,v2h:o,v3l:u,v3h:c,v4l:d,v4h:p,v5l:_,v5h:b,v6l:O,v6h:T,v7l:x,v7h:F}=this;return[e,r,n,i,s,o,u,c,d,p,_,b,O,T,x,F]}set(e,r,n,i,s,o,u,c,d,p,_,b,O,T,x,F){this.v0l=e|0,this.v0h=r|0,this.v1l=n|0,this.v1h=i|0,this.v2l=s|0,this.v2h=o|0,this.v3l=u|0,this.v3h=c|0,this.v4l=d|0,this.v4h=p|0,this.v5l=_|0,this.v5h=b|0,this.v6l=O|0,this.v6h=T|0,this.v7l=x|0,this.v7h=F|0}compress(e,r,n){this.get().forEach((c,d)=>Se[d]=c),Se.set(pr,16);let{h:i,l:s}=Y_(BigInt(this.length));Se[24]=pr[8]^s,Se[25]=pr[9]^i,n&&(Se[28]=~Se[28],Se[29]=~Se[29]);let o=0,u=J_;for(let c=0;c<12;c++)qs(0,4,8,12,e,r+2*u[o++]),Vs(0,4,8,12,e,r+2*u[o++]),qs(1,5,9,13,e,r+2*u[o++]),Vs(1,5,9,13,e,r+2*u[o++]),qs(2,6,10,14,e,r+2*u[o++]),Vs(2,6,10,14,e,r+2*u[o++]),qs(3,7,11,15,e,r+2*u[o++]),Vs(3,7,11,15,e,r+2*u[o++]),qs(0,5,10,15,e,r+2*u[o++]),Vs(0,5,10,15,e,r+2*u[o++]),qs(1,6,11,12,e,r+2*u[o++]),Vs(1,6,11,12,e,r+2*u[o++]),qs(2,7,8,13,e,r+2*u[o++]),Vs(2,7,8,13,e,r+2*u[o++]),qs(3,4,9,14,e,r+2*u[o++]),Vs(3,4,9,14,e,r+2*u[o++]);this.v0l^=Se[0]^Se[16],this.v0h^=Se[1]^Se[17],this.v1l^=Se[2]^Se[18],this.v1h^=Se[3]^Se[19],this.v2l^=Se[4]^Se[20],this.v2h^=Se[5]^Se[21],this.v3l^=Se[6]^Se[22],this.v3h^=Se[7]^Se[23],this.v4l^=Se[8]^Se[24],this.v4h^=Se[9]^Se[25],this.v5l^=Se[10]^Se[26],this.v5h^=Se[11]^Se[27],this.v6l^=Se[12]^Se[28],this.v6h^=Se[13]^Se[29],this.v7l^=Se[14]^Se[30],this.v7h^=Se[15]^Se[31],fl(Se)}destroy(){this.destroyed=!0,fl(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},nv=X_(t=>new hl(t));var pl=nv;var Lx=/^vector<(.+)>$/,$x=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/,fi=class t{static parseFromStr(e,r=!1){if(e==="address")return{address:null};if(e==="bool")return{bool:null};if(e==="u8")return{u8:null};if(e==="u16")return{u16:null};if(e==="u32")return{u32:null};if(e==="u64")return{u64:null};if(e==="u128")return{u128:null};if(e==="u256")return{u256:null};if(e==="signer")return{signer:null};let n=e.match(Lx);if(n)return{vector:t.parseFromStr(n[1],r)};let i=e.match($x);if(i)return{struct:{address:r?$e(i[1]):i[1],module:i[2],name:i[3],typeParams:i[5]===void 0?[]:t.parseStructTypeArgs(i[5],r)}};throw new Error(`Encountered unexpected token when parsing type args for ${e}`)}static parseStructTypeArgs(e,r=!1){return Iu(e).map(n=>t.parseFromStr(n,r))}static tagToString(e){if("bool"in e)return"bool";if("u8"in e)return"u8";if("u16"in e)return"u16";if("u32"in e)return"u32";if("u64"in e)return"u64";if("u128"in e)return"u128";if("u256"in e)return"u256";if("address"in e)return"address";if("signer"in e)return"signer";if("vector"in e)return`vector<${t.tagToString(e.vector)}>`;if("struct"in e){let r=e.struct,n=r.typeParams.map(t.tagToString).join(", ");return`${r.address}::${r.module}::${r.name}${n?`<${n}>`:""}`}throw new Error("Invalid TypeTag")}};function Fx(t){return B.u64({name:"unsafe_u64",...t}).transform({input:e=>e,output:e=>Number(e)})}function qx(t){return B.enum("Option",{None:null,Some:t})}var Pt=B.bytes(Ro).transform({validate:t=>{let e=typeof t=="string"?t:Qr(t);if(!e||!Fr($e(e)))throw new Error(`Invalid Sui address ${e}`)},input:t=>typeof t=="string"?Us($e(t)):t,output:t=>$e(Qr(t))}),_n=B.vector(B.u8()).transform({name:"ObjectDigest",input:t=>yn(t),output:t=>ci(new Uint8Array(t)),validate:t=>{if(yn(t).length!==32)throw new Error("ObjectDigest must be 32 bytes")}}),ln=B.struct("SuiObjectRef",{objectId:Pt,version:B.u64(),digest:_n}),vh=B.struct("SharedObjectRef",{objectId:Pt,initialSharedVersion:B.u64(),mutable:B.bool()}),bh=B.enum("ObjectArg",{ImmOrOwnedObject:ln,SharedObject:vh,Receiving:ln}),us=B.enum("Owner",{AddressOwner:Pt,ObjectOwner:Pt,Shared:B.struct("Shared",{initialSharedVersion:B.u64()}),Immutable:null,ConsensusV2:B.struct("ConsensusV2",{authenticator:B.enum("Authenticator",{SingleOwner:Pt}),startVersion:B.u64()})}),wh=B.enum("CallArg",{Pure:B.struct("Pure",{bytes:B.vector(B.u8()).transform({input:t=>typeof t=="string"?sr(t):t,output:t=>Ht(new Uint8Array(t))})}),Object:bh}),Mh=B.enum("TypeTag",{bool:null,u8:null,u64:null,u128:null,address:null,signer:null,vector:B.lazy(()=>Mh),struct:B.lazy(()=>Ih),u16:null,u32:null,u256:null}),ml=Mh.transform({input:t=>typeof t=="string"?fi.parseFromStr(t,!0):t,output:t=>fi.tagToString(t)}),di=B.enum("Argument",{GasCoin:null,Input:B.u16(),Result:B.u16(),NestedResult:B.tuple([B.u16(),B.u16()])}),Sh=B.struct("ProgrammableMoveCall",{package:Pt,module:B.string(),function:B.string(),typeArguments:B.vector(ml),arguments:B.vector(di)}),kh=B.enum("Command",{MoveCall:Sh,TransferObjects:B.struct("TransferObjects",{objects:B.vector(di),address:di}),SplitCoins:B.struct("SplitCoins",{coin:di,amounts:B.vector(di)}),MergeCoins:B.struct("MergeCoins",{destination:di,sources:B.vector(di)}),Publish:B.struct("Publish",{modules:B.vector(B.vector(B.u8()).transform({input:t=>typeof t=="string"?sr(t):t,output:t=>Ht(new Uint8Array(t))})),dependencies:B.vector(Pt)}),MakeMoveVec:B.struct("MakeMoveVec",{type:qx(ml).transform({input:t=>t===null?{None:!0}:{Some:t},output:t=>t.Some??null}),elements:B.vector(di)}),Upgrade:B.struct("Upgrade",{modules:B.vector(B.vector(B.u8()).transform({input:t=>typeof t=="string"?sr(t):t,output:t=>Ht(new Uint8Array(t))})),dependencies:B.vector(Pt),package:Pt,ticket:di})}),Oh=B.struct("ProgrammableTransaction",{inputs:B.vector(wh),commands:B.vector(kh)}),Eh=B.enum("TransactionKind",{ProgrammableTransaction:Oh,ChangeEpoch:null,Genesis:null,ConsensusCommitPrologue:null}),Ah=B.enum("TransactionExpiration",{None:null,Epoch:Fx()}),Ih=B.struct("StructTag",{address:Pt,module:B.string(),name:B.string(),typeParams:B.vector(Mh)}),Th=B.struct("GasData",{payment:B.vector(ln),owner:Pt,price:B.u64(),budget:B.u64()}),xh=B.struct("TransactionDataV1",{kind:Eh,sender:Pt,gasData:Th,expiration:Ah}),Ph=B.enum("TransactionData",{V1:xh}),Ch=B.enum("IntentScope",{TransactionData:null,TransactionEffects:null,CheckpointSummary:null,PersonalMessage:null}),jh=B.enum("IntentVersion",{V0:null}),Nh=B.enum("AppId",{Sui:null}),Dh=B.struct("Intent",{scope:Ch,version:jh,appId:Nh});function Bh(t){return B.struct(`IntentMessage<${t.name}>`,{intent:Dh,value:t})}var Rh=B.enum("CompressedSignature",{ED25519:B.fixedArray(64,B.u8()),Secp256k1:B.fixedArray(64,B.u8()),Secp256r1:B.fixedArray(64,B.u8()),ZkLogin:B.vector(B.u8())}),Uh=B.enum("PublicKey",{ED25519:B.fixedArray(32,B.u8()),Secp256k1:B.fixedArray(33,B.u8()),Secp256r1:B.fixedArray(33,B.u8()),ZkLogin:B.vector(B.u8())}),Lh=B.struct("MultiSigPkMap",{pubKey:Uh,weight:B.u8()}),$h=B.struct("MultiSigPublicKey",{pk_map:B.vector(Lh),threshold:B.u16()}),iv=B.struct("MultiSig",{sigs:B.vector(Rh),bitmap:B.u16(),multisig_pk:$h}),Vx=B.vector(B.u8()).transform({input:t=>typeof t=="string"?sr(t):t,output:t=>Ht(new Uint8Array(t))}),Fh=B.struct("SenderSignedTransaction",{intentMessage:Bh(Ph),txSignatures:B.vector(Vx)}),sv=B.vector(Fh,{name:"SenderSignedData"}),ov=B.struct("PasskeyAuthenticator",{authenticatorData:B.vector(B.u8()),clientDataJson:B.string(),userSignature:B.vector(B.u8())});var zx=B.enum("PackageUpgradeError",{UnableToFetchPackage:B.struct("UnableToFetchPackage",{packageId:Pt}),NotAPackage:B.struct("NotAPackage",{objectId:Pt}),IncompatibleUpgrade:null,DigestDoesNotMatch:B.struct("DigestDoesNotMatch",{digest:B.vector(B.u8())}),UnknownUpgradePolicy:B.struct("UnknownUpgradePolicy",{policy:B.u8()}),PackageIDDoesNotMatch:B.struct("PackageIDDoesNotMatch",{packageId:Pt,ticketId:Pt})}),Gx=B.struct("ModuleId",{address:Pt,name:B.string()}),av=B.struct("MoveLocation",{module:Gx,function:B.u16(),instruction:B.u16(),functionName:B.option(B.string())}),Hx=B.enum("CommandArgumentError",{TypeMismatch:null,InvalidBCSBytes:null,InvalidUsageOfPureArg:null,InvalidArgumentToPrivateEntryFunction:null,IndexOutOfBounds:B.struct("IndexOutOfBounds",{idx:B.u16()}),SecondaryIndexOutOfBounds:B.struct("SecondaryIndexOutOfBounds",{resultIdx:B.u16(),secondaryIdx:B.u16()}),InvalidResultArity:B.struct("InvalidResultArity",{resultIdx:B.u16()}),InvalidGasCoinUsage:null,InvalidValueUsage:null,InvalidObjectByValue:null,InvalidObjectByMutRef:null,SharedObjectOperationNotAllowed:null}),Wx=B.enum("TypeArgumentError",{TypeNotFound:null,ConstraintNotSatisfied:null}),Kx=B.enum("ExecutionFailureStatus",{InsufficientGas:null,InvalidGasObject:null,InvariantViolation:null,FeatureNotYetSupported:null,MoveObjectTooBig:B.struct("MoveObjectTooBig",{objectSize:B.u64(),maxObjectSize:B.u64()}),MovePackageTooBig:B.struct("MovePackageTooBig",{objectSize:B.u64(),maxObjectSize:B.u64()}),CircularObjectOwnership:B.struct("CircularObjectOwnership",{object:Pt}),InsufficientCoinBalance:null,CoinBalanceOverflow:null,PublishErrorNonZeroAddress:null,SuiMoveVerificationError:null,MovePrimitiveRuntimeError:B.option(av),MoveAbort:B.tuple([av,B.u64()]),VMVerificationOrDeserializationError:null,VMInvariantViolation:null,FunctionNotFound:null,ArityMismatch:null,TypeArityMismatch:null,NonEntryFunctionInvoked:null,CommandArgumentError:B.struct("CommandArgumentError",{argIdx:B.u16(),kind:Hx}),TypeArgumentError:B.struct("TypeArgumentError",{argumentIdx:B.u16(),kind:Wx}),UnusedValueWithoutDrop:B.struct("UnusedValueWithoutDrop",{resultIdx:B.u16(),secondaryIdx:B.u16()}),InvalidPublicFunctionReturnType:B.struct("InvalidPublicFunctionReturnType",{idx:B.u16()}),InvalidTransferObject:null,EffectsTooLarge:B.struct("EffectsTooLarge",{currentSize:B.u64(),maxSize:B.u64()}),PublishUpgradeMissingDependency:null,PublishUpgradeDependencyDowngrade:null,PackageUpgradeError:B.struct("PackageUpgradeError",{upgradeError:zx}),WrittenObjectsTooLarge:B.struct("WrittenObjectsTooLarge",{currentSize:B.u64(),maxSize:B.u64()}),CertificateDenied:null,SuiMoveVerificationTimedout:null,SharedObjectOperationNotAllowed:null,InputObjectDeleted:null,ExecutionCancelledDueToSharedObjectCongestion:B.struct("ExecutionCancelledDueToSharedObjectCongestion",{congestedObjects:B.vector(Pt)}),AddressDeniedForCoin:B.struct("AddressDeniedForCoin",{address:Pt,coinType:B.string()}),CoinTypeGlobalPause:B.struct("CoinTypeGlobalPause",{coinType:B.string()}),ExecutionCancelledDueToRandomnessUnavailable:null}),uv=B.enum("ExecutionStatus",{Success:null,Failed:B.struct("ExecutionFailed",{error:Kx,command:B.option(B.u64())})}),cv=B.struct("GasCostSummary",{computationCost:B.u64(),storageCost:B.u64(),storageRebate:B.u64(),nonRefundableStorageFee:B.u64()}),Xx=B.struct("TransactionEffectsV1",{status:uv,executedEpoch:B.u64(),gasUsed:cv,modifiedAtVersions:B.vector(B.tuple([Pt,B.u64()])),sharedObjects:B.vector(ln),transactionDigest:_n,created:B.vector(B.tuple([ln,us])),mutated:B.vector(B.tuple([ln,us])),unwrapped:B.vector(B.tuple([ln,us])),deleted:B.vector(ln),unwrappedThenDeleted:B.vector(ln),wrapped:B.vector(ln),gasObject:B.tuple([ln,us]),eventsDigest:B.option(_n),dependencies:B.vector(_n)}),qh=B.tuple([B.u64(),_n]),Jx=B.enum("ObjectIn",{NotExist:null,Exist:B.tuple([qh,us])}),Zx=B.enum("ObjectOut",{NotExist:null,ObjectWrite:B.tuple([_n,us]),PackageWrite:qh}),Yx=B.enum("IDOperation",{None:null,Created:null,Deleted:null}),Qx=B.struct("EffectsObjectChange",{inputState:Jx,outputState:Zx,idOperation:Yx}),e3=B.enum("UnchangedSharedKind",{ReadOnlyRoot:qh,MutateDeleted:B.u64(),ReadDeleted:B.u64(),Cancelled:B.u64(),PerEpochConfig:null}),t3=B.struct("TransactionEffectsV2",{status:uv,executedEpoch:B.u64(),gasUsed:cv,transactionDigest:_n,gasObjectIndex:B.option(B.u32()),eventsDigest:B.option(_n),dependencies:B.vector(_n),lamportVersion:B.u64(),changedObjects:B.vector(B.tuple([Pt,Qx])),unchangedSharedObjects:B.vector(B.tuple([Pt,e3])),auxDataDigest:B.option(_n)}),lv=B.enum("TransactionEffects",{V1:Xx,V2:t3});function ka(t){switch(t){case"u8":return B.u8();case"u16":return B.u16();case"u32":return B.u32();case"u64":return B.u64();case"u128":return B.u128();case"u256":return B.u256();case"bool":return B.bool();case"string":return B.string();case"id":case"address":return Pt}let e=t.match(/^(vector|option)<(.+)>$/);if(e){let[r,n]=e.slice(1);return r==="vector"?B.vector(ka(n)):B.option(ka(n))}throw new Error(`Invalid Pure type name: ${t}`)}var et={...B,U8:B.u8(),U16:B.u16(),U32:B.u32(),U64:B.u64(),U128:B.u128(),U256:B.u256(),ULEB128:B.uleb128(),Bool:B.bool(),String:B.string(),Address:Pt,AppId:Nh,Argument:di,CallArg:wh,Command:kh,CompressedSignature:Rh,GasData:Th,Intent:Dh,IntentMessage:Bh,IntentScope:Ch,IntentVersion:jh,MultiSig:iv,MultiSigPkMap:Lh,MultiSigPublicKey:$h,ObjectArg:bh,ObjectDigest:_n,Owner:us,PasskeyAuthenticator:ov,ProgrammableMoveCall:Sh,ProgrammableTransaction:Oh,PublicKey:Uh,SenderSignedData:sv,SenderSignedTransaction:Fh,SharedObjectRef:vh,StructTag:Ih,SuiObjectRef:ln,TransactionData:Ph,TransactionDataV1:xh,TransactionEffects:lv,TransactionExpiration:Ah,TransactionKind:Eh,TypeTag:ml};function fv(t,e,r){let n=et.Address.serialize(t).toBytes(),i=et.TypeTag.serialize(e).toBytes(),s=et.u64().serialize(r.length).toBytes(),o=pl.create({dkLen:32});return o.update(new Uint8Array([240])),o.update(n),o.update(s),o.update(r),o.update(i),`0x${Qr(o.digest().slice(0,32))}`}var gl=class{constructor(e){this.getSuiLendCoinInfo=(e,r)=>{let{allLendingMarketData:n,lstAprPercentMap:i}=this.lendingMarketCache??{};if(!n||!i)throw new Error("lendingMarketCache is not initialized");let s=Object.values(n??{})[0],o=s.lendingMarket.reserves.find(he=>he.coinType===e);if(!o)throw new Error("reserve not found");let u=this.obligationsCache?.[s.lendingMarket.id],c="borrow",d=u.rewardMap[o.token.coinType]?.[c]??[],p=a3(d);M_(c,o,p,this.sdk);let _=u3(c,o.coinType,i),b=c===dv.DEPOSIT?o.depositAprPercent:o.borrowAprPercent,O=b,T=S_(o,c,r);O=c===dv.DEPOSIT?w_(T):eh(T);let{multiplier:x,isValid:F}=k_(c,o,T),R=c3(p),H=l3(p),{newPerDayRewards:J,newAprRewards:ee}=O_(R,H,x,F),ae=hv(c,b,p,_),te=O===void 0||ee.some(he=>he.stats.aprPercent===void 0)?void 0:hv(c,O,ee,_);return{borrowLimit:o.config.borrowLimit.toString(),borrowedAmount:o.borrowedAmount.toString(),remainingBorrowLimit:Cu(o.config.borrowLimit.toString()).sub(Cu(o.borrowedAmount.toString())).toString(),depositAprPercent:o.depositAprPercent.toString(),totalAprPercent:ae.toString(),borrowInterest:b.toString(),stakingYieldAprPercent:_?.toString(),rewardAprPercent:H[0]?.stats.aprPercent?.toString()}};this.createObligation=async e=>{let{lendingMarketId:r,lendingMarketType:n}=Oa(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(r,n)).createObligation(e)};this.refreshReservePrices=async(e,r,n)=>{let{lendingMarketId:i,lendingMarketType:s}=Oa(this.sdk.sdkOptions?.suilend),o=`${i}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let u=await this.suilendClientCache[o].pythClient.getPriceFeedObjectId(r);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",u),this.suilendClientCache[o].pythConnection.getLatestPriceFeeds,this.suilendClientCache[o].refreshReservePrices(e,u,n)};this.getLatestPriceFeeds=async e=>{let{lendingMarketId:r,lendingMarketType:n}=Oa(this.sdk.sdkOptions?.suilend),i=`${r}_${n}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let s=Array.from(new Set(e.map(c=>as(new Uint8Array(c.priceIdentifier.bytes))))),o=await this.suilendClientCache[i].pythConnection.getLatestPriceFeeds(s),u={};return o?.forEach((c,d)=>{let p=c.getPriceUnchecked(),_=e[d];if(p){let{price:b,expo:O}=p,T=Cu(b).mul(Cu(10).pow(Cu(O))).toString(),x={coin_type:_.coinType.name,price:T,oracle_price:0n,last_update_time:p.publishTime};x.oracle_price=E_(BigInt(b),BigInt(O)),u[_.coinType.name]=x,this.sdk.updateCache(`getLatestPrice_${x.coin_type}`,x)}}),u};this.getSuiLendReserveInfo=async(e,r)=>{let{lendingMarketId:n}=Oa(this.sdk.sdkOptions?.suilend),{allLendingMarketData:i}=await this.getLendingMarketData(),s=i[n].reserveMap[e],o=i[n].reserveMap[r],u=i[n].refreshedRawReserves.filter(c=>c.coinType.name==pv(e)||c.coinType.name==pv(r));return{baseReserveArrayIndex:s.arrayIndex.toString(),quoteReserveArrayIndex:o.arrayIndex.toString(),reserve:u}};this.sdk=e}async getSuilendClient(e,r){let n=`${e}_${r}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[n]||(this.suilendClientCache[n]=await r3.initialize(e,r,this.sdk.FullClient,!0)),this.suilendClientCache[n]}async getLendingMarketData(e=!1){if(!e&&this.lendingMarketCache)return this.lendingMarketCache;let r=Oa(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!r.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[n,i]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(r.map(async o=>{let u=await this.getSuilendClient(o.id,o.type),{lendingMarket:c,coinMetadataMap:d,refreshedRawReserves:p,reserveMap:_,reserveCoinTypes:b,reserveCoinMetadataMap:O,rewardCoinTypes:T,activeRewardCoinTypes:x,rewardCoinMetadataMap:F}=await n3(this.sdk.FullClient,u),{rewardPriceMap:R}=await i3(_,x);return[o.id,{suilendClient:u,lendingMarket:c,coinMetadataMap:d,refreshedRawReserves:p,reserveMap:_,reserveCoinTypes:b,reserveCoinMetadataMap:O,rewardPriceMap:R,rewardCoinTypes:T,activeRewardCoinTypes:x,rewardCoinMetadataMap:F}]}))))(),(async()=>{try{let s=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),o=await s.json();if(s?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(o).map(([u,c])=>[u,new Ci(c)]))}catch(s){return console.error(s),{}}})()]);return this.lendingMarketCache={allLendingMarketData:n,lstAprPercentMap:i},this.lendingMarketCache}catch(n){throw console.log("\u{1F680} getLendingMarketData error:",n),n}}async getInitializeObligations(e,r=!1){if(!r&&this.obligationsCache)return this.obligationsCache;e||(e=await this.getLendingMarketData());let n={};for(let i of Object.values(e.allLendingMarketData)){let{obligationOwnerCaps:s,obligations:o}=await s3(this.sdk.FullClient,i.suilendClient,i.refreshedRawReserves,i.reserveMap,this.sdk.senderAddress),u=o3(i.reserveMap,i.rewardCoinMetadataMap,i.rewardPriceMap,o);n[i.lendingMarket.id]={obligationOwnerCaps:s,obligations:o,rewardMap:u}}return this.obligationsCache=n,this.obligationsCache}async getSuiLendUserData(e,r=!1){let{lstAprPercentMap:n}=this.lendingMarketCache??{},i=this.obligationsCache??{},{lendingMarketId:s}=Oa(this.sdk.sdkOptions?.suilend),o=i[s];if(!o)throw new Error(`No user data found for lending market: ${s}`);if(e){let u=o.obligations.find(d=>d.id===e);if(!u)throw new Error(`Obligation not found: ${e}`);let c=f3(u,o.rewardMap,n??{});return{obligation:u,netAprPercent:c,deposits:u.deposits,borrowedAmount:u.borrowedAmount,depositedAmount:u.depositedAmount,netValueUsd:u.netValueUsd,rewardMap:o.rewardMap}}}priceCheck(e,r=60){let n=Math.floor(Date.now()/1e3);if(!(Math.abs(n-e.last_update_time)>r))return e}};import{getPackagerConfigs as _r,CACHE_TIME_5MIN as _b,CoinAssist as Qt,CLOCK_ADDRESS as Qs,d as Mt,removeHexPrefix as vb}from"@cetusprotocol/common-sdk";var Ea=9e15,Ws=1e9,Vh="0123456789abcdef",vl="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",bl="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",zh={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ea,maxE:Ea,crypto:!1},_v,cs,it=!0,Ml="[DecimalError] ",Hs=Ml+"Invalid argument: ",vv=Ml+"Precision limit exceeded",bv=Ml+"crypto unavailable",wv="[object Decimal]",qr=Math.floor,mr=Math.pow,d3=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,h3=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,p3=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Mv=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,hi=1e7,Je=7,m3=9007199254740991,g3=vl.length-1,Gh=bl.length-1,le={toStringTag:wv};le.absoluteValue=le.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),ze(t)};le.ceil=function(){return ze(new this.constructor(this),this.e+1,2)};le.clampedTo=le.clamp=function(t,e){var r,n=this,i=n.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(Hs+e);return r=n.cmp(t),r<0?t:n.cmp(e)>0?e:new i(n)};le.comparedTo=le.cmp=function(t){var e,r,n,i,s=this,o=s.d,u=(t=new s.constructor(t)).d,c=s.s,d=t.s;if(!o||!u)return!c||!d?NaN:c!==d?c:o===u?0:!o^c<0?1:-1;if(!o[0]||!u[0])return o[0]?c:u[0]?-d:0;if(c!==d)return c;if(s.e!==t.e)return s.e>t.e^c<0?1:-1;for(n=o.length,i=u.length,e=0,r=n<i?n:i;e<r;++e)if(o[e]!==u[e])return o[e]>u[e]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};le.cosine=le.cos=function(){var t,e,r=this,n=r.constructor;return r.d?r.d[0]?(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Je,n.rounding=1,r=y3(n,Av(n,r)),n.precision=t,n.rounding=e,ze(cs==2||cs==3?r.neg():r,t,e,!0)):new n(1):new n(NaN)};le.cubeRoot=le.cbrt=function(){var t,e,r,n,i,s,o,u,c,d,p=this,_=p.constructor;if(!p.isFinite()||p.isZero())return new _(p);for(it=!1,s=p.s*mr(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Cr(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=mr(r,1/3),t=qr((t+1)/3)-(t%3==(t<0?-1:2)),s==1/0?r="5e"+t:(r=s.toExponential(),r=r.slice(0,r.indexOf("e")+1)+t),n=new _(r),n.s=p.s):n=new _(s.toString()),o=(t=_.precision)+3;;)if(u=n,c=u.times(u).times(u),d=c.plus(p),n=Ct(d.plus(p).times(u),d.plus(c),o+2,1),Cr(u.d).slice(0,o)===(r=Cr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(ze(u,t+1,0),u.times(u).times(u).eq(p))){n=u;break}o+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(ze(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return it=!0,ze(n,t,_.rounding,e)};le.decimalPlaces=le.dp=function(){var t,e=this.d,r=NaN;if(e){if(t=e.length-1,r=(t-qr(this.e/Je))*Je,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};le.dividedBy=le.div=function(t){return Ct(this,new this.constructor(t))};le.dividedToIntegerBy=le.divToInt=function(t){var e=this,r=e.constructor;return ze(Ct(e,new r(t),0,1,1),r.precision,r.rounding)};le.equals=le.eq=function(t){return this.cmp(t)===0};le.floor=function(){return ze(new this.constructor(this),this.e+1,3)};le.greaterThan=le.gt=function(t){return this.cmp(t)>0};le.greaterThanOrEqualTo=le.gte=function(t){var e=this.cmp(t);return e==1||e===0};le.hyperbolicCosine=le.cosh=function(){var t,e,r,n,i,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;r=o.precision,n=o.rounding,o.precision=r+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(t=Math.ceil(i/3),e=(1/kl(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=Aa(o,1,s.times(e),new o(1),!0);for(var c,d=t,p=new o(8);d--;)c=s.times(s),s=u.minus(c.times(p.minus(c.times(p))));return ze(s,o.precision=r,o.rounding=n,!0)};le.hyperbolicSine=le.sinh=function(){var t,e,r,n,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(e=s.precision,r=s.rounding,s.precision=e+Math.max(i.e,i.sd())+4,s.rounding=1,n=i.d.length,n<3)i=Aa(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/kl(5,t)),i=Aa(s,2,i,i,!0);for(var o,u=new s(5),c=new s(16),d=new s(20);t--;)o=i.times(i),i=i.times(u.plus(o.times(c.times(o).plus(d))))}return s.precision=e,s.rounding=r,ze(i,e,r,!0)};le.hyperbolicTangent=le.tanh=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+7,n.rounding=1,Ct(r.sinh(),r.cosh(),n.precision=t,n.rounding=e)):new n(r.s)};le.inverseCosine=le.acos=function(){var t=this,e=t.constructor,r=t.abs().cmp(1),n=e.precision,i=e.rounding;return r!==-1?r===0?t.isNeg()?Di(e,n,i):new e(0):new e(NaN):t.isZero()?Di(e,n+4,i).times(.5):(e.precision=n+6,e.rounding=1,t=new e(1).minus(t).div(t.plus(1)).sqrt().atan(),e.precision=n,e.rounding=i,t.times(2))};le.inverseHyperbolicCosine=le.acosh=function(){var t,e,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(t=n.precision,e=n.rounding,n.precision=t+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,it=!1,r=r.times(r).minus(1).sqrt().plus(r),it=!0,n.precision=t,n.rounding=e,r.ln()):new n(r)};le.inverseHyperbolicSine=le.asinh=function(){var t,e,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,it=!1,r=r.times(r).plus(1).sqrt().plus(r),it=!0,n.precision=t,n.rounding=e,r.ln())};le.inverseHyperbolicTangent=le.atanh=function(){var t,e,r,n,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=s.precision,e=s.rounding,n=i.sd(),Math.max(n,t)<2*-i.e-1?ze(new s(i),t,e,!0):(s.precision=r=n-i.e,i=Ct(i.plus(1),new s(1).minus(i),r+t,1),s.precision=t+4,s.rounding=1,i=i.ln(),s.precision=t,s.rounding=e,i.times(.5))):new s(NaN)};le.inverseSine=le.asin=function(){var t,e,r,n,i=this,s=i.constructor;return i.isZero()?new s(i):(e=i.abs().cmp(1),r=s.precision,n=s.rounding,e!==-1?e===0?(t=Di(s,r+4,n).times(.5),t.s=i.s,t):new s(NaN):(s.precision=r+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=n,i.times(2)))};le.inverseTangent=le.atan=function(){var t,e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding;if(d.isFinite()){if(d.isZero())return new p(d);if(d.abs().eq(1)&&_+4<=Gh)return o=Di(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=Gh)return o=Di(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/Je+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(it=!1,e=Math.ceil(u/Je),n=1,c=d.times(d),o=new p(d),i=d;t!==-1;)if(i=i.times(c),s=o.minus(i.div(n+=2)),i=i.times(c),o=s.plus(i.div(n+=2)),o.d[e]!==void 0)for(t=e;o.d[t]===s.d[t]&&t--;);return r&&(o=o.times(2<<r-1)),it=!0,ze(o,p.precision=_,p.rounding=b,!0)};le.isFinite=function(){return!!this.d};le.isInteger=le.isInt=function(){return!!this.d&&qr(this.e/Je)>this.d.length-2};le.isNaN=function(){return!this.s};le.isNegative=le.isNeg=function(){return this.s<0};le.isPositive=le.isPos=function(){return this.s>0};le.isZero=function(){return!!this.d&&this.d[0]===0};le.lessThan=le.lt=function(t){return this.cmp(t)<0};le.lessThanOrEqualTo=le.lte=function(t){return this.cmp(t)<1};le.logarithm=le.log=function(t){var e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding,O=5;if(t==null)t=new p(10),e=!0;else{if(t=new p(t),r=t.d,t.s<0||!r||!r[0]||t.eq(1))return new p(NaN);e=t.eq(10)}if(r=d.d,d.s<0||!r||!r[0]||d.eq(1))return new p(r&&!r[0]?-1/0:d.s!=1?NaN:r?0:1/0);if(e)if(r.length>1)s=!0;else{for(i=r[0];i%10===0;)i/=10;s=i!==1}if(it=!1,u=_+O,o=Gs(d,u),n=e?wl(p,u+10):Gs(t,u),c=Ct(o,n,u,1),ju(c.d,i=_,b))do if(u+=10,o=Gs(d,u),n=e?wl(p,u+10):Gs(t,u),c=Ct(o,n,u,1),!s){+Cr(c.d).slice(i+1,i+15)+1==1e14&&(c=ze(c,_+1,0));break}while(ju(c.d,i+=10,b));return it=!0,ze(c,_,b)};le.minus=le.sub=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.constructor;if(t=new T(t),!O.d||!t.d)return!O.s||!t.s?t=new T(NaN):O.d?t.s=-t.s:t=new T(t.d||O.s!==t.s?O:NaN),t;if(O.s!=t.s)return t.s=-t.s,O.plus(t);if(d=O.d,b=t.d,u=T.precision,c=T.rounding,!d[0]||!b[0]){if(b[0])t.s=-t.s;else if(d[0])t=new T(O);else return new T(c===3?-0:0);return it?ze(t,u,c):t}if(r=qr(t.e/Je),p=qr(O.e/Je),d=d.slice(),s=p-r,s){for(_=s<0,_?(e=d,s=-s,o=b.length):(e=b,r=p,o=d.length),n=Math.max(Math.ceil(u/Je),o)+2,s>n&&(s=n,e.length=1),e.reverse(),n=s;n--;)e.push(0);e.reverse()}else{for(n=d.length,o=b.length,_=n<o,_&&(o=n),n=0;n<o;n++)if(d[n]!=b[n]){_=d[n]<b[n];break}s=0}for(_&&(e=d,d=b,b=e,t.s=-t.s),o=d.length,n=b.length-o;n>0;--n)d[o++]=0;for(n=b.length;n>s;){if(d[--n]<b[n]){for(i=n;i&&d[--i]===0;)d[i]=hi-1;--d[i],d[n]+=hi}d[n]-=b[n]}for(;d[--o]===0;)d.pop();for(;d[0]===0;d.shift())--r;return d[0]?(t.d=d,t.e=Sl(d,r),it?ze(t,u,c):t):new T(c===3?-0:0)};le.modulo=le.mod=function(t){var e,r=this,n=r.constructor;return t=new n(t),!r.d||!t.s||t.d&&!t.d[0]?new n(NaN):!t.d||r.d&&!r.d[0]?ze(new n(r),n.precision,n.rounding):(it=!1,n.modulo==9?(e=Ct(r,t.abs(),0,3,1),e.s*=t.s):e=Ct(r,t,0,n.modulo,1),e=e.times(t),it=!0,r.minus(e))};le.naturalExponential=le.exp=function(){return Hh(this)};le.naturalLogarithm=le.ln=function(){return Gs(this)};le.negated=le.neg=function(){var t=new this.constructor(this);return t.s=-t.s,ze(t)};le.plus=le.add=function(t){var e,r,n,i,s,o,u,c,d,p,_=this,b=_.constructor;if(t=new b(t),!_.d||!t.d)return!_.s||!t.s?t=new b(NaN):_.d||(t=new b(t.d||_.s===t.s?_:NaN)),t;if(_.s!=t.s)return t.s=-t.s,_.minus(t);if(d=_.d,p=t.d,u=b.precision,c=b.rounding,!d[0]||!p[0])return p[0]||(t=new b(_)),it?ze(t,u,c):t;if(s=qr(_.e/Je),n=qr(t.e/Je),d=d.slice(),i=s-n,i){for(i<0?(r=d,i=-i,o=p.length):(r=p,n=s,o=d.length),s=Math.ceil(u/Je),o=s>o?s+1:o+1,i>o&&(i=o,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(o=d.length,i=p.length,o-i<0&&(i=o,r=p,p=d,d=r),e=0;i;)e=(d[--i]=d[i]+p[i]+e)/hi|0,d[i]%=hi;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=Sl(d,n),it?ze(t,u,c):t};le.precision=le.sd=function(t){var e,r=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Hs+t);return r.d?(e=Sv(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};le.round=function(){var t=this,e=t.constructor;return ze(new e(t),t.e+1,e.rounding)};le.sine=le.sin=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Je,n.rounding=1,r=v3(n,Av(n,r)),n.precision=t,n.rounding=e,ze(cs>2?r.neg():r,t,e,!0)):new n(NaN)};le.squareRoot=le.sqrt=function(){var t,e,r,n,i,s,o=this,u=o.d,c=o.e,d=o.s,p=o.constructor;if(d!==1||!u||!u[0])return new p(!d||d<0&&(!u||u[0])?NaN:u?o:1/0);for(it=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Cr(u),(e.length+c)%2==0&&(e+="0"),d=Math.sqrt(e),c=qr((c+1)/2)-(c<0||c%2),d==1/0?e="5e"+c:(e=d.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),n=new p(e)):n=new p(d.toString()),r=(c=p.precision)+3;;)if(s=n,n=s.plus(Ct(o,s,r+2,1)).times(.5),Cr(s.d).slice(0,r)===(e=Cr(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(ze(s,c+1,0),s.times(s).eq(o))){n=s;break}r+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(ze(n,c+1,1),t=!n.times(n).eq(o));break}return it=!0,ze(n,c,p.rounding,t)};le.tangent=le.tan=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+10,n.rounding=1,r=r.sin(),r.s=1,r=Ct(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,ze(cs==2||cs==4?r.neg():r,t,e,!0)):new n(NaN)};le.times=le.mul=function(t){var e,r,n,i,s,o,u,c,d,p=this,_=p.constructor,b=p.d,O=(t=new _(t)).d;if(t.s*=p.s,!b||!b[0]||!O||!O[0])return new _(!t.s||b&&!b[0]&&!O||O&&!O[0]&&!b?NaN:!b||!O?t.s/0:t.s*0);for(r=qr(p.e/Je)+qr(t.e/Je),c=b.length,d=O.length,c<d&&(s=b,b=O,O=s,o=c,c=d,d=o),s=[],o=c+d,n=o;n--;)s.push(0);for(n=d;--n>=0;){for(e=0,i=c+n;i>n;)u=s[i]+O[n]*b[i-n-1]+e,s[i--]=u%hi|0,e=u/hi|0;s[i]=(s[i]+e)%hi|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=Sl(s,r),it?ze(t,_.precision,_.rounding):t};le.toBinary=function(t,e){return Wh(this,2,t,e)};le.toDecimalPlaces=le.toDP=function(t,e){var r=this,n=r.constructor;return r=new n(r),t===void 0?r:(fn(t,0,Ws),e===void 0?e=n.rounding:fn(e,0,8),ze(r,t+r.e+1,e))};le.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=Bi(n,!0):(fn(t,0,Ws),e===void 0?e=i.rounding:fn(e,0,8),n=ze(new i(n),t+1,e),r=Bi(n,!0,t+1)),n.isNeg()&&!n.isZero()?"-"+r:r};le.toFixed=function(t,e){var r,n,i=this,s=i.constructor;return t===void 0?r=Bi(i):(fn(t,0,Ws),e===void 0?e=s.rounding:fn(e,0,8),n=ze(new s(i),t+i.e+1,e),r=Bi(n,!1,t+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};le.toFraction=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.d,x=O.constructor;if(!T)return new x(O);if(d=r=new x(1),n=c=new x(0),e=new x(n),s=e.e=Sv(T)-O.e-1,o=s%Je,e.d[0]=mr(10,o<0?Je+o:o),t==null)t=s>0?e:d;else{if(u=new x(t),!u.isInt()||u.lt(d))throw Error(Hs+u);t=u.gt(e)?s>0?e:d:u}for(it=!1,u=new x(Cr(T)),p=x.precision,x.precision=s=T.length*Je*2;_=Ct(u,e,0,1,1),i=r.plus(_.times(n)),i.cmp(t)!=1;)r=n,n=i,i=d,d=c.plus(_.times(i)),c=i,i=e,e=u.minus(_.times(i)),u=i;return i=Ct(t.minus(r),n,0,1,1),c=c.plus(i.times(d)),r=r.plus(i.times(n)),c.s=d.s=O.s,b=Ct(d,n,s,1).minus(O).abs().cmp(Ct(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,it=!0,b};le.toHexadecimal=le.toHex=function(t,e){return Wh(this,16,t,e)};le.toNearest=function(t,e){var r=this,n=r.constructor;if(r=new n(r),t==null){if(!r.d)return r;t=new n(1),e=n.rounding}else{if(t=new n(t),e===void 0?e=n.rounding:fn(e,0,8),!r.d)return t.s?r:t;if(!t.d)return t.s&&(t.s=r.s),t}return t.d[0]?(it=!1,r=Ct(r,t,0,e,1).times(t),it=!0,ze(r)):(t.s=r.s,r=t),r};le.toNumber=function(){return+this};le.toOctal=function(t,e){return Wh(this,8,t,e)};le.toPower=le.pow=function(t){var e,r,n,i,s,o,u=this,c=u.constructor,d=+(t=new c(t));if(!u.d||!t.d||!u.d[0]||!t.d[0])return new c(mr(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return ze(u,n,s);if(e=qr(t.e/Je),e>=t.d.length-1&&(r=d<0?-d:d)<=m3)return i=kv(c,u,r,n),t.s<0?new c(1).div(i):ze(i,n,s);if(o=u.s,o<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(o=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=o,u}return r=mr(+u,d),e=r==0||!isFinite(r)?qr(d*(Math.log("0."+Cr(u.d))/Math.LN10+u.e+1)):new c(r+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?o/0:0):(it=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=Hh(t.times(Gs(u,n+r)),n),i.d&&(i=ze(i,n+5,1),ju(i.d,n,s)&&(e=n+10,i=ze(Hh(t.times(Gs(u,e+r)),e),e+5,1),+Cr(i.d).slice(n+1,n+15)+1==1e14&&(i=ze(i,n+1,0)))),i.s=o,it=!0,c.rounding=s,ze(i,n,s))};le.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=Bi(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(fn(t,1,Ws),e===void 0?e=i.rounding:fn(e,0,8),n=ze(new i(n),t,e),r=Bi(n,t<=n.e||n.e<=i.toExpNeg,t)),n.isNeg()&&!n.isZero()?"-"+r:r};le.toSignificantDigits=le.toSD=function(t,e){var r=this,n=r.constructor;return t===void 0?(t=n.precision,e=n.rounding):(fn(t,1,Ws),e===void 0?e=n.rounding:fn(e,0,8)),ze(new n(r),t,e)};le.toString=function(){var t=this,e=t.constructor,r=Bi(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};le.truncated=le.trunc=function(){return ze(new this.constructor(this),this.e+1,1)};le.valueOf=le.toJSON=function(){var t=this,e=t.constructor,r=Bi(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Cr(t){var e,r,n,i=t.length-1,s="",o=t[0];if(i>0){for(s+=o,e=1;e<i;e++)n=t[e]+"",r=Je-n.length,r&&(s+=zs(r)),s+=n;o=t[e],n=o+"",r=Je-n.length,r&&(s+=zs(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function fn(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Hs+t)}function ju(t,e,r,n){var i,s,o,u;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=Je,i=0):(i=Math.ceil((e+1)/Je),e%=Je),s=mr(10,Je-e),u=t[i]%s|0,n==null?e<3?(e==0?u=u/100|0:e==1&&(u=u/10|0),o=r<4&&u==99999||r>3&&u==49999||u==5e4||u==0):o=(r<4&&u+1==s||r>3&&u+1==s/2)&&(t[i+1]/s/100|0)==mr(10,e-2)-1||(u==s/2||u==0)&&(t[i+1]/s/100|0)==0:e<4?(e==0?u=u/1e3|0:e==1?u=u/100|0:e==2&&(u=u/10|0),o=(n||r<4)&&u==9999||!n&&r>3&&u==4999):o=((n||r<4)&&u+1==s||!n&&r>3&&u+1==s/2)&&(t[i+1]/s/1e3|0)==mr(10,e-3)-1,o}function yl(t,e,r){for(var n,i=[0],s,o=0,u=t.length;o<u;){for(s=i.length;s--;)i[s]*=e;for(i[0]+=Vh.indexOf(t.charAt(o++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function y3(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/kl(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=Aa(t,1,e.times(i),new t(1));for(var s=r;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return t.precision-=r,e}var Ct=(function(){function t(n,i,s){var o,u=0,c=n.length;for(n=n.slice();c--;)o=n[c]*i+u,n[c]=o%s|0,u=o/s|0;return u&&n.unshift(u),n}function e(n,i,s,o){var u,c;if(s!=o)c=s>o?1:-1;else for(u=c=0;u<s;u++)if(n[u]!=i[u]){c=n[u]>i[u]?1:-1;break}return c}function r(n,i,s,o){for(var u=0;s--;)n[s]-=u,u=n[s]<i[s]?1:0,n[s]=u*o+n[s]-i[s];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,s,o,u,c){var d,p,_,b,O,T,x,F,R,H,J,ee,ae,te,he,A,I,C,D,N,k=n.constructor,m=n.s==i.s?1:-1,a=n.d,l=i.d;if(!a||!a[0]||!l||!l[0])return new k(!n.s||!i.s||(a?l&&a[0]==l[0]:!l)?NaN:a&&a[0]==0||!l?m*0:m/0);for(c?(O=1,p=n.e-i.e):(c=hi,O=Je,p=qr(n.e/O)-qr(i.e/O)),D=l.length,I=a.length,R=new k(m),H=R.d=[],_=0;l[_]==(a[_]||0);_++);if(l[_]>(a[_]||0)&&p--,s==null?(te=s=k.precision,o=k.rounding):u?te=s+(n.e-i.e)+1:te=s,te<0)H.push(1),T=!0;else{if(te=te/O+2|0,_=0,D==1){for(b=0,l=l[0],te++;(_<I||b)&&te--;_++)he=b*c+(a[_]||0),H[_]=he/l|0,b=he%l|0;T=b||_<I}else{for(b=c/(l[0]+1)|0,b>1&&(l=t(l,b,c),a=t(a,b,c),D=l.length,I=a.length),A=D,J=a.slice(0,D),ee=J.length;ee<D;)J[ee++]=0;N=l.slice(),N.unshift(0),C=l[0],l[1]>=c/2&&++C;do b=0,d=e(l,J,D,ee),d<0?(ae=J[0],D!=ee&&(ae=ae*c+(J[1]||0)),b=ae/C|0,b>1?(b>=c&&(b=c-1),x=t(l,b,c),F=x.length,ee=J.length,d=e(x,J,F,ee),d==1&&(b--,r(x,D<F?N:l,F,c))):(b==0&&(d=b=1),x=l.slice()),F=x.length,F<ee&&x.unshift(0),r(J,x,ee,c),d==-1&&(ee=J.length,d=e(l,J,D,ee),d<1&&(b++,r(J,D<ee?N:l,ee,c))),ee=J.length):d===0&&(b++,J=[0]),H[_++]=b,d&&J[0]?J[ee++]=a[A]||0:(J=[a[A]],ee=1);while((A++<I||J[0]!==void 0)&&te--);T=J[0]!==void 0}H[0]||H.shift()}if(O==1)R.e=p,_v=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,ze(R,u?s+R.e+1:s,o,T)}return R}})();function ze(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor;e:if(e!=null){if(_=t.d,!_)return t;for(i=1,u=_[0];u>=10;u/=10)i++;if(s=e-i,s<0)s+=Je,o=e,p=_[b=0],c=p/mr(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/Je),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=Je,o=s-Je+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=Je,o=s-Je+i,c=o<0?0:p/mr(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%mr(10,i-o-1)),d=r<4?(c||n)&&(r==0||r==(t.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(s>0?o>0?p/mr(10,i-o):0:_[b-1])%10&1||r==(t.s<0?8:7)),e<1||!_[0])return _.length=0,d?(e-=t.e+1,_[0]=mr(10,(Je-e%Je)%Je),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=mr(10,Je-s),_[b]=o>0?(p/mr(10,i-o)%mr(10,o)|0)*u:0),d)for(;;)if(b==0){for(s=1,o=_[0];o>=10;o/=10)s++;for(o=_[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(t.e++,_[0]==hi&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=hi)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return it&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function Bi(t,e,r){if(!t.isFinite())return Ev(t);var n,i=t.e,s=Cr(t.d),o=s.length;return e?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+zs(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):i<0?(s="0."+zs(-i-1)+s,r&&(n=r-o)>0&&(s+=zs(n))):i>=o?(s+=zs(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+zs(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=zs(n))),s}function Sl(t,e){var r=t[0];for(e*=Je;r>=10;r/=10)e++;return e}function wl(t,e,r){if(e>g3)throw it=!0,r&&(t.precision=r),Error(vv);return ze(new t(vl),e,1,!0)}function Di(t,e,r){if(e>Gh)throw Error(vv);return ze(new t(bl),e,r,!0)}function Sv(t){var e=t.length-1,r=e*Je+1;if(e=t[e],e){for(;e%10==0;e/=10)r--;for(e=t[0];e>=10;e/=10)r++}return r}function zs(t){for(var e="";t--;)e+="0";return e}function kv(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/Je+4);for(it=!1;;){if(r%2&&(s=s.times(e),gv(s.d,o)&&(i=!0)),r=qr(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}e=e.times(e),gv(e.d,o)}return it=!0,s}function mv(t){return t.d[t.d.length-1]&1}function Ov(t,e,r){for(var n,i,s=new t(e[0]),o=0;++o<e.length;){if(i=new t(e[o]),!i.s){s=i;break}n=s.cmp(i),(n===r||n===0&&s.s===r)&&(s=i)}return s}function Hh(t,e){var r,n,i,s,o,u,c,d=0,p=0,_=0,b=t.constructor,O=b.rounding,T=b.precision;if(!t.d||!t.d[0]||t.e>17)return new b(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:NaN);for(e==null?(it=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(mr(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=ze(s.times(t),c,1),r=r.times(++p),u=o.plus(Ct(s,r,c,1)),Cr(u.d).slice(0,c)===Cr(o.d).slice(0,c)){for(i=_;i--;)o=ze(o.times(o),c,1);if(e==null)if(d<3&&ju(o.d,c-n,O,d))b.precision=c+=10,r=s=u=new b(1),p=0,d++;else return ze(o,b.precision=T,O,it=!0);else return b.precision=T,o}o=u}}function Gs(t,e){var r,n,i,s,o,u,c,d,p,_,b,O=1,T=10,x=t,F=x.d,R=x.constructor,H=R.rounding,J=R.precision;if(x.s<0||!F||!F[0]||!x.e&&F[0]==1&&F.length==1)return new R(F&&!F[0]?-1/0:x.s!=1?NaN:F?0:x);if(e==null?(it=!1,p=J):p=e,R.precision=p+=T,r=Cr(F),n=r.charAt(0),Math.abs(s=x.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)x=x.times(t),r=Cr(x.d),n=r.charAt(0),O++;s=x.e,n>1?(x=new R("0."+r),s++):x=new R(n+"."+r.slice(1))}else return d=wl(R,p+2,J).times(s+""),x=Gs(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?ze(x,J,H,it=!0):x;for(_=x,c=o=x=Ct(x.minus(1),x.plus(1),p,1),b=ze(x.times(x),p,1),i=3;;){if(o=ze(o.times(b),p,1),d=c.plus(Ct(o,new R(i),p,1)),Cr(d.d).slice(0,p)===Cr(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus(wl(R,p+2,J).times(s+""))),c=Ct(c,new R(O),p,1),e==null)if(ju(c.d,p-T,H,u))R.precision=p+=T,d=o=x=Ct(_.minus(1),_.plus(1),p,1),b=ze(x.times(x),p,1),i=u=1;else return ze(c,R.precision=J,H,it=!0);else return R.precision=J,c;c=d,i+=2}}function Ev(t){return String(t.s*t.s/0)}function _l(t,e){var r,n,i;for((r=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(r<0&&(r=n),r+=+e.slice(n+1),e=e.substring(0,n)):r<0&&(r=e.length),n=0;e.charCodeAt(n)===48;n++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(n,i),e){if(i-=n,t.e=r=r-n-1,t.d=[],n=(r+1)%Je,r<0&&(n+=Je),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=Je;n<i;)t.d.push(+e.slice(n,n+=Je));e=e.slice(n),n=Je-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),it&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function _3(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Mv.test(e))return _l(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(h3.test(e))r=16,e=e.toLowerCase();else if(d3.test(e))r=2;else if(p3.test(e))r=8;else throw Error(Hs+e);for(s=e.search(/p/i),s>0?(c=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),s=e.indexOf("."),o=s>=0,n=t.constructor,o&&(e=e.replace(".",""),u=e.length,s=u-s,i=kv(n,new n(r),s,s*2)),d=yl(e,r,hi),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=Sl(d,p),t.d=d,it=!1,o&&(t=Ct(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?mr(2,c):Nu.pow(2,c))),it=!0,t)}function v3(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:Aa(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/kl(5,r)),e=Aa(t,2,e,e);for(var i,s=new t(5),o=new t(16),u=new t(20);r--;)i=e.times(e),e=e.times(s.plus(i.times(o.times(i).minus(u))));return e}function Aa(t,e,r,n,i){var s,o,u,c,d=1,p=t.precision,_=Math.ceil(p/Je);for(it=!1,c=r.times(r),u=new t(n);;){if(o=Ct(u.times(c),new t(e++*e++),p,1),u=i?n.plus(o):n.minus(o),n=Ct(o.times(c),new t(e++*e++),p,1),o=u.plus(n),o.d[_]!==void 0){for(s=_;o.d[s]===u.d[s]&&s--;);if(s==-1)break}s=u,u=n,n=o,o=s,d++}return it=!0,o.d.length=_+1,o}function kl(t,e){for(var r=t;--e;)r*=t;return r}function Av(t,e){var r,n=e.s<0,i=Di(t,t.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return cs=n?4:1,e;if(r=e.divToInt(i),r.isZero())cs=n?3:2;else{if(e=e.minus(r.times(i)),e.lte(s))return cs=mv(r)?n?2:3:n?4:1,e;cs=mv(r)?n?1:4:n?3:2}return e.minus(i).abs()}function Wh(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor,T=r!==void 0;if(T?(fn(r,1,Ws),n===void 0?n=O.rounding:fn(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=Ev(t);else{for(p=Bi(t),o=p.indexOf("."),T?(i=2,e==16?r=r*4-3:e==8&&(r=r*3-2)):i=e,o>=0&&(p=p.replace(".",""),b=new O(1),b.e=p.length-o,b.d=yl(Bi(b),10,i),b.e=b.d.length),_=yl(p,10,i),s=c=_.length;_[--c]==0;)_.pop();if(!_[0])p=T?"0p+0":"0";else{if(o<0?s--:(t=new O(t),t.d=_,t.e=s,t=Ct(t,b,r,n,0,i),_=t.d,s=t.e,d=_v),o=_[r],u=i/2,d=d||_[r+1]!==void 0,d=n<4?(o!==void 0||d)&&(n===0||n===(t.s<0?3:2)):o>u||o===u&&(n===4||d||n===6&&_[r-1]&1||n===(t.s<0?8:7)),_.length=r,d)for(;++_[--r]>i-1;)_[r]=0,r||(++s,_.unshift(1));for(c=_.length;!_[c-1];--c);for(o=0,p="";o<c;o++)p+=Vh.charAt(_[o]);if(T){if(c>1)if(e==16||e==8){for(o=e==16?4:3,--c;c%o;c++)p+="0";for(_=yl(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=Vh.charAt(_[o])}else p=p.charAt(0)+"."+p.slice(1);p=p+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)p="0"+p;p="0."+p}else if(++s>c)for(s-=c;s--;)p+="0";else s<c&&(p=p.slice(0,s)+"."+p.slice(s))}p=(e==16?"0x":e==2?"0b":e==8?"0o":"")+p}return t.s<0?"-"+p:p}function gv(t,e){if(t.length>e)return t.length=e,!0}function b3(t){return new this(t).abs()}function w3(t){return new this(t).acos()}function M3(t){return new this(t).acosh()}function S3(t,e){return new this(t).plus(e)}function k3(t){return new this(t).asin()}function O3(t){return new this(t).asinh()}function E3(t){return new this(t).atan()}function A3(t){return new this(t).atanh()}function I3(t,e){t=new this(t),e=new this(e);var r,n=this.precision,i=this.rounding,s=n+4;return!t.s||!e.s?r=new this(NaN):!t.d&&!e.d?(r=Di(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?Di(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=Di(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan(Ct(t,e,s,1)),e=Di(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(Ct(t,e,s,1)),r}function T3(t){return new this(t).cbrt()}function x3(t){return ze(t=new this(t),t.e+1,2)}function P3(t,e,r){return new this(t).clamp(e,r)}function C3(t){if(!t||typeof t!="object")throw Error(Ml+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,Ws,"rounding",0,8,"toExpNeg",-Ea,0,"toExpPos",0,Ea,"maxE",0,Ea,"minE",-Ea,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=zh[r]),(n=t[r])!==void 0)if(qr(n)===n&&n>=s[e+1]&&n<=s[e+2])this[r]=n;else throw Error(Hs+r+": "+n);if(r="crypto",i&&(this[r]=zh[r]),(n=t[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(bv);else this[r]=!1;else throw Error(Hs+r+": "+n);return this}function j3(t){return new this(t).cos()}function N3(t){return new this(t).cosh()}function Iv(t){var e,r,n;function i(s){var o,u,c,d=this;if(!(d instanceof i))return new i(s);if(d.constructor=i,yv(s)){d.s=s.s,it?!s.d||s.e>i.maxE?(d.e=NaN,d.d=null):s.e<i.minE?(d.e=0,d.d=[0]):(d.e=s.e,d.d=s.d.slice()):(d.e=s.e,d.d=s.d?s.d.slice():s.d);return}if(c=typeof s,c==="number"){if(s===0){d.s=1/s<0?-1:1,d.e=0,d.d=[0];return}if(s<0?(s=-s,d.s=-1):d.s=1,s===~~s&&s<1e7){for(o=0,u=s;u>=10;u/=10)o++;it?o>i.maxE?(d.e=NaN,d.d=null):o<i.minE?(d.e=0,d.d=[0]):(d.e=o,d.d=[s]):(d.e=o,d.d=[s]);return}if(s*0!==0){s||(d.s=NaN),d.e=NaN,d.d=null;return}return _l(d,s.toString())}if(c==="string")return(u=s.charCodeAt(0))===45?(s=s.slice(1),d.s=-1):(u===43&&(s=s.slice(1)),d.s=1),Mv.test(s)?_l(d,s):_3(d,s);if(c==="bigint")return s<0?(s=-s,d.s=-1):d.s=1,_l(d,s.toString());throw Error(Hs+s)}if(i.prototype=le,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=C3,i.clone=Iv,i.isDecimal=yv,i.abs=b3,i.acos=w3,i.acosh=M3,i.add=S3,i.asin=k3,i.asinh=O3,i.atan=E3,i.atanh=A3,i.atan2=I3,i.cbrt=T3,i.ceil=x3,i.clamp=P3,i.cos=j3,i.cosh=N3,i.div=D3,i.exp=B3,i.floor=R3,i.hypot=U3,i.ln=L3,i.log=$3,i.log10=q3,i.log2=F3,i.max=V3,i.min=z3,i.mod=G3,i.mul=H3,i.pow=W3,i.random=K3,i.round=X3,i.sign=J3,i.sin=Z3,i.sinh=Y3,i.sqrt=Q3,i.sub=eP,i.sum=tP,i.tan=rP,i.tanh=nP,i.trunc=iP,t===void 0&&(t={}),t&&t.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)t.hasOwnProperty(r=n[e++])||(t[r]=this[r]);return i.config(t),i}function D3(t,e){return new this(t).div(e)}function B3(t){return new this(t).exp()}function R3(t){return ze(t=new this(t),t.e+1,3)}function U3(){var t,e,r=new this(0);for(it=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)r.d&&(r=r.plus(e.times(e)));else{if(e.s)return it=!0,new this(1/0);r=e}return it=!0,r.sqrt()}function yv(t){return t instanceof Nu||t&&t.toStringTag===wv||!1}function L3(t){return new this(t).ln()}function $3(t,e){return new this(t).log(e)}function F3(t){return new this(t).log(2)}function q3(t){return new this(t).log(10)}function V3(){return Ov(this,arguments,-1)}function z3(){return Ov(this,arguments,1)}function G3(t,e){return new this(t).mod(e)}function H3(t,e){return new this(t).mul(e)}function W3(t,e){return new this(t).pow(e)}function K3(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:fn(t,1,Ws),n=Math.ceil(t/Je),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));s<n;)i=e[s],i>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);s<n;)i=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((e[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,s):(u.push(i%1e7),s+=4);s=n/4}else throw Error(bv);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=Je,n&&t&&(i=mr(10,Je-t),u[s]=(n/i|0)*i);u[s]===0;s--)u.pop();if(s<0)r=0,u=[0];else{for(r=-1;u[0]===0;r-=Je)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<Je&&(r-=Je-n)}return o.e=r,o.d=u,o}function X3(t){return ze(t=new this(t),t.e+1,this.rounding)}function J3(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Z3(t){return new this(t).sin()}function Y3(t){return new this(t).sinh()}function Q3(t){return new this(t).sqrt()}function eP(t,e){return new this(t).sub(e)}function tP(){var t=0,e=arguments,r=new this(e[t]);for(it=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return it=!0,ze(r,this.precision,this.rounding)}function rP(t){return new this(t).tan()}function nP(t){return new this(t).tanh()}function iP(t){return ze(t=new this(t),t.e+1,1)}le[Symbol.for("nodejs.util.inspect.custom")]=le.toString;le[Symbol.toStringTag]="Decimal";var Nu=le.constructor=Iv(zh);vl=new Nu(vl);bl=new Nu(bl);var Ri=Nu;var bp=m_(xv());var sP="object",oP="ID",aP="ascii",uP="String",cP="string",lP="String",fP="option",dP="Option";function Pv(t){let e=typeof t.body=="object"&&"datatype"in t.body?t.body.datatype:null;return!!e&&$e(e.package)===$e("0x2")&&e.module==="tx_context"&&e.type==="TxContext"}function Ol(t){if(typeof t=="string")switch(t){case"address":return et.Address;case"bool":return et.Bool;case"u8":return et.U8;case"u16":return et.U16;case"u32":return et.U32;case"u64":return et.U64;case"u128":return et.U128;case"u256":return et.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t){if(t.vector==="u8")return et.vector(et.U8).transform({input:r=>typeof r=="string"?new TextEncoder().encode(r):r,output:r=>r});let e=Ol(t.vector);return e?et.vector(e):null}if("datatype"in t){let e=$e(t.datatype.package);if(e===$e(lh)){if(t.datatype.module===aP&&t.datatype.type===uP)return et.String;if(t.datatype.module===cP&&t.datatype.type===lP)return et.String;if(t.datatype.module===fP&&t.datatype.type===dP){let r=Ol(t.datatype.typeParameters[0]);return r?et.vector(r):null}}if(e===$e(ol)&&t.datatype.module===sP&&t.datatype.type===oP)return et.Address}return null}function Cv(t){return typeof t=="object"&&"Reference"in t?{ref:"&",body:Du(t.Reference)}:typeof t=="object"&&"MutableReference"in t?{ref:"&mut",body:Du(t.MutableReference)}:{ref:null,body:Du(t)}}function Du(t){if(typeof t=="string")switch(t){case"Address":return"address";case"Bool":return"bool";case"U8":return"u8";case"U16":return"u16";case"U32":return"u32";case"U64":return"u64";case"U128":return"u128";case"U256":return"u256";default:throw new Error(`Unexpected type ${t}`)}if("Vector"in t)return{vector:Du(t.Vector)};if("Struct"in t)return{datatype:{package:t.Struct.address,module:t.Struct.module,type:t.Struct.name,typeParameters:t.Struct.typeArguments.map(Du)}};if("TypeParameter"in t)return{typeParameter:t.TypeParameter};throw new Error(`Unexpected type ${JSON.stringify(t)}`)}function hP(t){return{$kind:"Pure",Pure:{bytes:t instanceof Uint8Array?Ht(t):t.toBase64()}}}var Cn={Pure:hP,ObjectRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{digest:e,version:r,objectId:$e(t)}}}},SharedObjectRef({objectId:t,mutable:e,initialSharedVersion:r}){return{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{mutable:e,initialSharedVersion:r,objectId:$e(t)}}}},ReceivingRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"Receiving",Receiving:{digest:e,version:r,objectId:$e(t)}}}}};var Xh;function pP(t){return{lang:t?.lang??Xh?.lang,message:t?.message,abortEarly:t?.abortEarly??Xh?.abortEarly,abortPipeEarly:t?.abortPipeEarly??Xh?.abortPipeEarly}}var mP;function gP(t){return mP?.get(t)}var yP;function _P(t){return yP?.get(t)}var vP;function bP(t,e){return vP?.get(t)?.get(e)}function Nv(t){let e=typeof t;return e==="string"?`"${t}"`:e==="number"||e==="bigint"||e==="boolean"?`${t}`:e==="object"||e==="function"?(t&&Object.getPrototypeOf(t)?.constructor?.name)??"null":e}function vn(t,e,r,n,i){let s=i&&"input"in i?i.input:r.value,o=i?.expected??t.expects??null,u=i?.received??Nv(s),c={kind:t.kind,type:t.type,input:s,expected:o,received:u,message:`Invalid ${e}: ${o?`Expected ${o} but r`:"R"}eceived ${u}`,requirement:t.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},d=t.kind==="schema",p=i?.message??t.message??bP(t.reference,c.lang)??(d?_P(c.lang):null)??n.message??gP(c.lang);p&&(c.message=typeof p=="function"?p(c):p),d&&(r.typed=!1),r.issues?r.issues.push(c):r.issues=[c]}function wP(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}var MP=class extends Error{issues;constructor(t){super(t[0].message),this.name="ValiError",this.issues=t}};function $o(t,e){return{kind:"validation",type:"check",reference:$o,async:!1,expects:null,requirement:t,message:e,_run(r,n){return r.typed&&!this.requirement(r.value)&&vn(this,"input",r,n),r}}}function Yt(t){return{kind:"validation",type:"integer",reference:Yt,async:!1,expects:null,requirement:Number.isInteger,message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&vn(this,"integer",e,r),e}}}function Bu(t){return{kind:"transformation",type:"transform",reference:Bu,async:!1,operation:t,_run(e){return e.value=this.operation(e.value),e}}}function Jh(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function Ru(t,e){return!t._run({typed:!1,value:e},{abortEarly:!0}).issues}function Xe(t,e){return{kind:"schema",type:"array",reference:Xe,expects:"Array",async:!1,item:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<i.length;s++){let o=i[s],u=this.item._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else vn(this,"type",r,n);return r}}}function El(t){return{kind:"schema",type:"bigint",reference:El,expects:"bigint",async:!1,message:t,_run(e,r){return typeof e.value=="bigint"?e.typed=!0:vn(this,"type",e,r),e}}}function Fo(t){return{kind:"schema",type:"boolean",reference:Fo,expects:"boolean",async:!1,message:t,_run(e,r){return typeof e.value=="boolean"?e.typed=!0:vn(this,"type",e,r),e}}}function qo(t){return{kind:"schema",type:"lazy",reference:qo,expects:"unknown",async:!1,getter:t,_run(e,r){return this.getter(e.value)._run(e,r)}}}function rt(t,e){return{kind:"schema",type:"literal",reference:rt,expects:Nv(t),async:!1,literal:t,message:e,_run(r,n){return r.value===this.literal?r.typed=!0:vn(this,"type",r,n),r}}}function Ot(t,...e){let r={kind:"schema",type:"nullable",reference:Ot,expects:`${t.expects} | null`,async:!1,wrapped:t,_run(n,i){return n.value===null&&("default"in this&&(n.value=Jh(this,n,i)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function ls(t,...e){let r={kind:"schema",type:"nullish",reference:ls,expects:`${t.expects} | null | undefined`,async:!1,wrapped:t,_run(n,i){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=Jh(this,n,i)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function Wt(t){return{kind:"schema",type:"number",reference:Wt,expects:"number",async:!1,message:t,_run(e,r){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:vn(this,"type",e,r),e}}}function we(t,e){return{kind:"schema",type:"object",reference:we,expects:"Object",async:!1,entries:t,message:e,_run(r,n){let i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(let s in this.entries){let o=i[s],u=this.entries[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"object",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),(u.value!==void 0||s in i)&&(r.value[s]=u.value)}}else vn(this,"type",r,n);return r}}}function lr(t,...e){let r={kind:"schema",type:"optional",reference:lr,expects:`${t.expects} | undefined`,async:!1,wrapped:t,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=Jh(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in e&&(r.default=e[0]),r}function Vo(t,e,r){return{kind:"schema",type:"record",reference:Vo,expects:"Object",async:!1,key:t,value:e,message:r,_run(n,i){let s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};for(let o in s)if(wP(s,o)){let u=s[o],c=this.key._run({typed:!1,value:o},i);if(c.issues){let p={type:"object",origin:"key",input:s,key:o,value:u};for(let _ of c.issues)_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}let d=this.value._run({typed:!1,value:u},i);if(d.issues){let p={type:"object",origin:"value",input:s,key:o,value:u};for(let _ of d.issues)_.path?_.path.unshift(p):_.path=[p],n.issues?.push(_);if(n.issues||(n.issues=d.issues),i.abortEarly){n.typed=!1;break}}(!c.typed||!d.typed)&&(n.typed=!1),c.typed&&(n.value[c.value]=d.value)}}else vn(this,"type",n,i);return n}}}function st(t){return{kind:"schema",type:"string",reference:st,expects:"string",async:!1,message:t,_run(e,r){return typeof e.value=="string"?e.typed=!0:vn(this,"type",e,r),e}}}function Uu(t,e){return{kind:"schema",type:"tuple",reference:Uu,expects:"Array",async:!1,items:t,message:e,_run(r,n){let i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let s=0;s<this.items.length;s++){let o=i[s],u=this.items[s]._run({typed:!1,value:o},n);if(u.issues){let c={type:"array",origin:"value",input:i,key:s,value:o};for(let d of u.issues)d.path?d.path.unshift(c):d.path=[c],r.issues?.push(d);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else vn(this,"type",r,n);return r}}}function jv(t){let e;if(t)for(let r of t)e?e.push(...r.issues):e=r.issues;return e}function fr(t,e){return{kind:"schema",type:"union",reference:fr,expects:[...new Set(t.map(r=>r.expects))].join(" | ")||"never",async:!1,options:t,message:e,_run(r,n){let i,s,o;for(let u of this.options){let c=u._run({typed:!1,value:r.value},n);if(c.typed)if(c.issues)s?s.push(c):s=[c];else{i=c;break}else o?o.push(c):o=[c]}if(i)return i;if(s){if(s.length===1)return s[0];vn(this,"type",r,n,{issues:jv(s)}),r.typed=!0}else{if(o?.length===1)return o[0];vn(this,"type",r,n,{issues:jv(o)})}return r}}}function Ui(){return{kind:"schema",type:"unknown",reference:Ui,expects:"unknown",async:!1,_run(t){return t.typed=!0,t}}}function jt(t,e,r){let n=t._run({typed:!1,value:e},pP(r));if(n.issues)throw new MP(n.issues);return n.value}function xt(...t){return{...t[0],pipe:t,_run(e,r){for(let n=0;n<t.length;n++){if(e.issues&&(t[n].kind==="schema"||t[n].kind==="transformation")){e.typed=!1;break}(!e.issues||!r.abortEarly&&!r.abortPipeEarly)&&(e=t[n]._run(e,r))}return e}}}function Xs(t){let e=Object.entries(t).map(([r,n])=>we({[r]:n}));return xt(fr(e),Bu(r=>({...r,$kind:Object.keys(r)[0]})))}var zo=xt(st(),Bu(t=>$e(t)),$o(Fr)),en=zo,Ks=st(),Vr=xt(fr([st(),xt(Wt(),Yt())]),$o(t=>{try{return BigInt(t),BigInt(t)>=0&&BigInt(t)<=18446744073709551615n}catch{return!1}},"Invalid u64")),pi=we({objectId:zo,version:Vr,digest:st()}),Kt=xt(fr([we({GasCoin:rt(!0)}),we({Input:xt(Wt(),Yt()),type:lr(rt("pure"))}),we({Input:xt(Wt(),Yt()),type:lr(rt("object"))}),we({Result:xt(Wt(),Yt())}),we({NestedResult:Uu([xt(Wt(),Yt()),xt(Wt(),Yt())])})]),Bu(t=>({...t,$kind:Object.keys(t)[0]}))),SP=we({budget:Ot(Vr),price:Ot(Vr),owner:Ot(zo),payment:Ot(Xe(pi))}),xJ=we({address:st(),module:st(),name:st(),typeParams:Xe(st())}),Zh=fr([rt("address"),rt("bool"),rt("u8"),rt("u16"),rt("u32"),rt("u64"),rt("u128"),rt("u256"),we({vector:qo(()=>Zh)}),we({datatype:we({package:st(),module:st(),type:st(),typeParameters:Xe(qo(()=>Zh))})}),we({typeParameter:xt(Wt(),Yt())})]),kP=we({ref:Ot(fr([rt("&"),rt("&mut")])),body:Zh}),OP=we({package:en,module:st(),function:st(),typeArguments:Xe(st()),arguments:Xe(Kt),_argumentTypes:lr(Ot(Xe(kP)))}),EP=we({name:st(),inputs:Vo(st(),fr([Kt,Xe(Kt)])),data:Vo(st(),Ui())}),AP=Xs({MoveCall:OP,TransferObjects:we({objects:Xe(Kt),address:Kt}),SplitCoins:we({coin:Kt,amounts:Xe(Kt)}),MergeCoins:we({destination:Kt,sources:Xe(Kt)}),Publish:we({modules:Xe(Ks),dependencies:Xe(en)}),MakeMoveVec:we({type:Ot(st()),elements:Xe(Kt)}),Upgrade:we({modules:Xe(Ks),dependencies:Xe(en),package:en,ticket:Kt}),$Intent:EP}),Dv=Xs({ImmOrOwnedObject:pi,SharedObject:we({objectId:en,initialSharedVersion:Vr,mutable:Fo()}),Receiving:pi}),IP=Xs({Object:Dv,Pure:we({bytes:Ks}),UnresolvedPure:we({value:Ui()}),UnresolvedObject:we({objectId:en,version:lr(Ot(Vr)),digest:lr(Ot(st())),initialSharedVersion:lr(Ot(Vr))})}),Yh=Xs({Object:Dv,Pure:we({bytes:Ks})}),Qh=Xs({None:rt(!0),Epoch:Vr}),Ia=we({version:rt(2),sender:ls(zo),expiration:ls(Qh),gasData:SP,inputs:Xe(IP),commands:Xe(AP)});var Js={MoveCall(t){let[e,r="",n=""]="target"in t?t.target.split("::"):[t.package,t.module,t.function];return{$kind:"MoveCall",MoveCall:{package:e,module:r,function:n,typeArguments:t.typeArguments??[],arguments:t.arguments??[]}}},TransferObjects(t,e){return{$kind:"TransferObjects",TransferObjects:{objects:t.map(r=>jt(Kt,r)),address:jt(Kt,e)}}},SplitCoins(t,e){return{$kind:"SplitCoins",SplitCoins:{coin:jt(Kt,t),amounts:e.map(r=>jt(Kt,r))}}},MergeCoins(t,e){return{$kind:"MergeCoins",MergeCoins:{destination:jt(Kt,t),sources:e.map(r=>jt(Kt,r))}}},Publish({modules:t,dependencies:e}){return{$kind:"Publish",Publish:{modules:t.map(r=>typeof r=="string"?r:Ht(new Uint8Array(r))),dependencies:e.map(r=>Ar(r))}}},Upgrade({modules:t,dependencies:e,package:r,ticket:n}){return{$kind:"Upgrade",Upgrade:{modules:t.map(i=>typeof i=="string"?i:Ht(new Uint8Array(i))),dependencies:e.map(i=>Ar(i)),package:r,ticket:jt(Kt,n)}}},MakeMoveVec({type:t,elements:e}){return{$kind:"MakeMoveVec",MakeMoveVec:{type:t??null,elements:e.map(r=>jt(Kt,r))}}},Intent({name:t,inputs:e={},data:r={}}){return{$kind:"$Intent",$Intent:{name:t,inputs:Object.fromEntries(Object.entries(e).map(([n,i])=>[n,Array.isArray(i)?i.map(s=>jt(Kt,s)):jt(Kt,i)])),data:r}}}};var ep=we({digest:st(),objectId:st(),version:fr([xt(Wt(),Yt()),st(),El()])}),TP=Xs({ImmOrOwned:ep,Shared:we({objectId:en,initialSharedVersion:Vr,mutable:Fo()}),Receiving:ep}),Bv=Xs({Object:TP,Pure:Xe(xt(Wt(),Yt()))}),Uv=fr([we({kind:rt("Input"),index:xt(Wt(),Yt()),value:Ui(),type:lr(rt("object"))}),we({kind:rt("Input"),index:xt(Wt(),Yt()),value:Ui(),type:rt("pure")})]),xP=fr([we({Epoch:xt(Wt(),Yt())}),we({None:Ot(rt(!0))})]),Rv=xt(fr([Wt(),st(),El()]),$o(t=>{if(!["string","number","bigint"].includes(typeof t))return!1;try{return BigInt(t),!0}catch{return!1}})),tp=fr([we({bool:Ot(rt(!0))}),we({u8:Ot(rt(!0))}),we({u64:Ot(rt(!0))}),we({u128:Ot(rt(!0))}),we({address:Ot(rt(!0))}),we({signer:Ot(rt(!0))}),we({vector:qo(()=>tp)}),we({struct:qo(()=>PP)}),we({u16:Ot(rt(!0))}),we({u32:Ot(rt(!0))}),we({u256:Ot(rt(!0))})]),PP=we({address:st(),module:st(),name:st(),typeParams:Xe(tp)}),CP=we({budget:lr(Rv),price:lr(Rv),payment:lr(Xe(ep)),owner:lr(st())}),jP=[Uv,we({kind:rt("GasCoin")}),we({kind:rt("Result"),index:xt(Wt(),Yt())}),we({kind:rt("NestedResult"),index:xt(Wt(),Yt()),resultIndex:xt(Wt(),Yt())})],hs=fr([...jP]),NP=we({kind:rt("MoveCall"),target:xt(st(),$o(t=>t.split("::").length===3)),typeArguments:Xe(st()),arguments:Xe(hs)}),DP=we({kind:rt("TransferObjects"),objects:Xe(hs),address:hs}),BP=we({kind:rt("SplitCoins"),coin:hs,amounts:Xe(hs)}),RP=we({kind:rt("MergeCoins"),destination:hs,sources:Xe(hs)}),UP=we({kind:rt("MakeMoveVec"),type:fr([we({Some:tp}),we({None:Ot(rt(!0))})]),objects:Xe(hs)}),LP=we({kind:rt("Publish"),modules:Xe(Xe(xt(Wt(),Yt()))),dependencies:Xe(st())}),$P=we({kind:rt("Upgrade"),modules:Xe(Xe(xt(Wt(),Yt()))),dependencies:Xe(st()),packageId:st(),ticket:hs}),FP=[NP,DP,BP,RP,LP,$P,UP],qP=fr([...FP]),FJ=we({version:rt(1),sender:lr(st()),expiration:ls(xP),gasConfig:CP,inputs:Xe(Uv),transactions:Xe(qP)});function rp(t){let e=t.inputs.map((r,n)=>{if(r.Object)return{kind:"Input",index:n,value:{Object:r.Object.ImmOrOwnedObject?{ImmOrOwned:r.Object.ImmOrOwnedObject}:r.Object.Receiving?{Receiving:{digest:r.Object.Receiving.digest,version:r.Object.Receiving.version,objectId:r.Object.Receiving.objectId}}:{Shared:{mutable:r.Object.SharedObject.mutable,initialSharedVersion:r.Object.SharedObject.initialSharedVersion,objectId:r.Object.SharedObject.objectId}}},type:"object"};if(r.Pure)return{kind:"Input",index:n,value:{Pure:Array.from(sr(r.Pure.bytes))},type:"pure"};if(r.UnresolvedPure)return{kind:"Input",type:"pure",index:n,value:r.UnresolvedPure.value};if(r.UnresolvedObject)return{kind:"Input",type:"object",index:n,value:r.UnresolvedObject.objectId};throw new Error("Invalid input")});return{version:1,sender:t.sender??void 0,expiration:t.expiration?.$kind==="Epoch"?{Epoch:Number(t.expiration.Epoch)}:t.expiration?{None:!0}:null,gasConfig:{owner:t.gasData.owner??void 0,budget:t.gasData.budget??void 0,price:t.gasData.price??void 0,payment:t.gasData.payment??void 0},inputs:e,transactions:t.commands.map(r=>{if(r.MakeMoveVec)return{kind:"MakeMoveVec",type:r.MakeMoveVec.type===null?{None:!0}:{Some:fi.parseFromStr(r.MakeMoveVec.type)},objects:r.MakeMoveVec.elements.map(n=>fs(n,e))};if(r.MergeCoins)return{kind:"MergeCoins",destination:fs(r.MergeCoins.destination,e),sources:r.MergeCoins.sources.map(n=>fs(n,e))};if(r.MoveCall)return{kind:"MoveCall",target:`${r.MoveCall.package}::${r.MoveCall.module}::${r.MoveCall.function}`,typeArguments:r.MoveCall.typeArguments,arguments:r.MoveCall.arguments.map(n=>fs(n,e))};if(r.Publish)return{kind:"Publish",modules:r.Publish.modules.map(n=>Array.from(sr(n))),dependencies:r.Publish.dependencies};if(r.SplitCoins)return{kind:"SplitCoins",coin:fs(r.SplitCoins.coin,e),amounts:r.SplitCoins.amounts.map(n=>fs(n,e))};if(r.TransferObjects)return{kind:"TransferObjects",objects:r.TransferObjects.objects.map(n=>fs(n,e)),address:fs(r.TransferObjects.address,e)};if(r.Upgrade)return{kind:"Upgrade",modules:r.Upgrade.modules.map(n=>Array.from(sr(n))),dependencies:r.Upgrade.dependencies,packageId:r.Upgrade.package,ticket:fs(r.Upgrade.ticket,e)};throw new Error(`Unknown transaction ${Object.keys(r)}`)})}}function fs(t,e){if(t.$kind==="GasCoin")return{kind:"GasCoin"};if(t.$kind==="Result")return{kind:"Result",index:t.Result};if(t.$kind==="NestedResult")return{kind:"NestedResult",index:t.NestedResult[0],resultIndex:t.NestedResult[1]};if(t.$kind==="Input")return e[t.Input];throw new Error(`Invalid argument ${Object.keys(t)}`)}function Lv(t){return jt(Ia,{version:2,sender:t.sender??null,expiration:t.expiration?"Epoch"in t.expiration?{Epoch:t.expiration.Epoch}:{None:!0}:null,gasData:{owner:t.gasConfig.owner??null,budget:t.gasConfig.budget?.toString()??null,price:t.gasConfig.price?.toString()??null,payment:t.gasConfig.payment?.map(e=>({digest:e.digest,objectId:e.objectId,version:e.version.toString()}))??null},inputs:t.inputs.map(e=>{if(e.kind==="Input"){if(Ru(Bv,e.value)){let r=jt(Bv,e.value);if(r.Object){if(r.Object.ImmOrOwned)return{Object:{ImmOrOwnedObject:{objectId:r.Object.ImmOrOwned.objectId,version:String(r.Object.ImmOrOwned.version),digest:r.Object.ImmOrOwned.digest}}};if(r.Object.Shared)return{Object:{SharedObject:{mutable:r.Object.Shared.mutable??null,initialSharedVersion:r.Object.Shared.initialSharedVersion,objectId:r.Object.Shared.objectId}}};if(r.Object.Receiving)return{Object:{Receiving:{digest:r.Object.Receiving.digest,version:String(r.Object.Receiving.version),objectId:r.Object.Receiving.objectId}}};throw new Error("Invalid object input")}return{Pure:{bytes:Ht(new Uint8Array(r.Pure))}}}return e.type==="object"?{UnresolvedObject:{objectId:e.value}}:{UnresolvedPure:{value:e.value}}}throw new Error("Invalid input")}),commands:t.transactions.map(e=>{switch(e.kind){case"MakeMoveVec":return{MakeMoveVec:{type:"Some"in e.type?fi.tagToString(e.type.Some):null,elements:e.objects.map(r=>ds(r))}};case"MergeCoins":return{MergeCoins:{destination:ds(e.destination),sources:e.sources.map(r=>ds(r))}};case"MoveCall":{let[r,n,i]=e.target.split("::");return{MoveCall:{package:r,module:n,function:i,typeArguments:e.typeArguments,arguments:e.arguments.map(s=>ds(s))}}}case"Publish":return{Publish:{modules:e.modules.map(r=>Ht(Uint8Array.from(r))),dependencies:e.dependencies}};case"SplitCoins":return{SplitCoins:{coin:ds(e.coin),amounts:e.amounts.map(r=>ds(r))}};case"TransferObjects":return{TransferObjects:{objects:e.objects.map(r=>ds(r)),address:ds(e.address)}};case"Upgrade":return{Upgrade:{modules:e.modules.map(r=>Ht(Uint8Array.from(r))),dependencies:e.dependencies,package:e.packageId,ticket:ds(e.ticket)}}}throw new Error(`Unknown transaction ${Object.keys(e)}`)})})}function ds(t){switch(t.kind){case"GasCoin":return{GasCoin:!0};case"Result":return{Result:t.index};case"NestedResult":return{NestedResult:[t.index,t.resultIndex]};case"Input":return{Input:t.index}}}function Lu(t){return fr(Object.entries(t).map(([e,r])=>we({[e]:r})))}var mi=Lu({GasCoin:rt(!0),Input:xt(Wt(),Yt()),Result:xt(Wt(),Yt()),NestedResult:Uu([xt(Wt(),Yt()),xt(Wt(),Yt())])}),VP=we({budget:Ot(Vr),price:Ot(Vr),owner:Ot(zo),payment:Ot(Xe(pi))}),zP=we({package:en,module:st(),function:st(),typeArguments:Xe(st()),arguments:Xe(mi)}),GP=we({name:st(),inputs:Vo(st(),fr([mi,Xe(mi)])),data:Vo(st(),Ui())}),HP=Lu({MoveCall:zP,TransferObjects:we({objects:Xe(mi),address:mi}),SplitCoins:we({coin:mi,amounts:Xe(mi)}),MergeCoins:we({destination:mi,sources:Xe(mi)}),Publish:we({modules:Xe(Ks),dependencies:Xe(en)}),MakeMoveVec:we({type:Ot(st()),elements:Xe(mi)}),Upgrade:we({modules:Xe(Ks),dependencies:Xe(en),package:en,ticket:mi}),$Intent:GP}),WP=Lu({ImmOrOwnedObject:pi,SharedObject:we({objectId:en,initialSharedVersion:Vr,mutable:Fo()}),Receiving:pi}),KP=Lu({Object:WP,Pure:we({bytes:Ks}),UnresolvedPure:we({value:Ui()}),UnresolvedObject:we({objectId:en,version:lr(Ot(Vr)),digest:lr(Ot(st())),initialSharedVersion:lr(Ot(Vr))})}),XP=Lu({None:rt(!0),Epoch:Vr}),$v=we({version:rt(2),sender:ls(zo),expiration:ls(XP),gasData:VP,inputs:Xe(KP),commands:Xe(HP),digest:lr(Ot(st()))});var Vv=t=>{throw TypeError(t)},zv=(t,e,r)=>e.has(t)||Vv("Cannot "+r),zr=(t,e,r)=>(zv(t,e,"read from private field"),r?r.call(t):e.get(t)),Fv=(t,e,r)=>e.has(t)?Vv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),qv=(t,e,r,n)=>(zv(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Go,tn,JP=class Gv{constructor({prefix:e,cache:r}={}){Fv(this,Go),Fv(this,tn),qv(this,Go,e??[]),qv(this,tn,r??new Map)}read(e,r){let n=[zr(this,Go),...e].join(":");if(zr(this,tn).has(n))return zr(this,tn).get(n);let i=r();return zr(this,tn).set(n,i),typeof i=="object"&&i!==null&&"then"in i?Promise.resolve(i).then(s=>(zr(this,tn).set(n,s),s)).catch(s=>{throw zr(this,tn).delete(n),s}):i}readSync(e,r){let n=[zr(this,Go),...e].join(":");if(zr(this,tn).has(n))return zr(this,tn).get(n);let i=r();return zr(this,tn).set(n,i),i}clear(e){let r=[...zr(this,Go),...e??[]].join(":");if(!r){zr(this,tn).clear();return}for(let n of zr(this,tn).keys())n.startsWith(r)&&zr(this,tn).delete(n)}scope(e){return new Gv({prefix:[...zr(this,Go),...Array.isArray(e)?e:[e]],cache:zr(this,tn)})}};Go=new WeakMap;tn=new WeakMap;var Al=JP;var Il="1.34.0",Hv="1.51.0";var Kv=t=>{throw TypeError(t)},ap=(t,e,r)=>e.has(t)||Kv("Cannot "+r),gr=(t,e,r)=>(ap(t,e,"read from private field"),r?r.call(t):e.get(t)),$u=(t,e,r)=>e.has(t)?Kv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Tl=(t,e,r,n)=>(ap(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),xl=(t,e,r)=>(ap(t,e,"access private method"),r),Fu,ps,qu,Zs,Li,np,ip,Xv,Jv,up,ZP="/",YP={"Mvr-Source":`@mysten/sui@${Il}`},Ta=class{constructor({cache:e,url:r,pageSize:n=50,overrides:i}){$u(this,Li),$u(this,Fu),$u(this,ps),$u(this,qu),$u(this,Zs),Tl(this,Fu,e),Tl(this,ps,r),Tl(this,qu,n),Tl(this,Zs,{packages:i?.packages,types:i?.types}),QP(gr(this,Zs))}async resolvePackage({package:e}){return{package:await gr(this,Li,np).load(e)}}async resolveType({type:e}){let r=[...sp(e)],n=await gr(this,Li,ip).loadMany(r),i={};for(let s=0;s<r.length;s++){let o=n[s];if(o instanceof Error)throw o;i[r[s]]=o}return{type:op(e,i)}}async resolve({types:e=[],packages:r=[]}){let n=new Set;for(let p of e??[])sp(p,n);let i=[...n],[s,o]=await Promise.all([i.length>0?gr(this,Li,ip).loadMany(i):[],r.length>0?gr(this,Li,np).loadMany(r):[]]),u={...gr(this,Zs)?.types};for(let[p,_]of i.entries()){let b=s[p];if(b instanceof Error)throw b;u[_]=b}let c={};for(let p of e??[]){let _=op(p,u);c[p]={type:_}}let d={};for(let[p,_]of(r??[]).entries()){let b=gr(this,Zs)?.packages?.[_]??o[p];if(b instanceof Error)throw b;d[_]={package:b}}return{types:c,packages:d}}};Fu=new WeakMap;ps=new WeakMap;qu=new WeakMap;Zs=new WeakMap;Li=new WeakSet;np=function(){return gr(this,Fu).readSync(["#mvrPackageDataLoader",gr(this,ps)??""],()=>{let t=new ba(async r=>{if(!gr(this,ps))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await xl(this,Li,Xv).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve package: ${i}`))}),e=gr(this,Zs)?.packages;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};ip=function(){return gr(this,Fu).readSync(["#mvrTypeDataLoader",gr(this,ps)??""],()=>{let t=new ba(async r=>{if(!gr(this,ps))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await xl(this,Li,Jv).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve type: ${i}`))}),e=gr(this,Zs)?.types;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};Xv=async function(t){if(t.length===0)return{};let e=Ls(t,gr(this,qu)),r={};return await Promise.all(e.map(async n=>{let i=await xl(this,Li,up).call(this,"/v1/resolution/bulk",{names:n});if(i?.resolution)for(let s of Object.keys(i?.resolution)){let o=i.resolution[s]?.package_id;o&&(r[s]=o)}})),r};Jv=async function(t){if(t.length===0)return{};let e=Ls(t,gr(this,qu)),r={};return await Promise.all(e.map(async n=>{let i=await xl(this,Li,up).call(this,"/v1/struct-definition/bulk",{types:n});if(i?.resolution)for(let s of Object.keys(i?.resolution)){let o=i.resolution[s]?.type_tag;o&&(r[s]=o)}})),r};up=async function(t,e){if(!gr(this,ps))throw new Error("MVR Api URL is not set for the current client");let r=await fetch(`${gr(this,ps)}${t}`,{method:"POST",headers:{"Content-Type":"application/json",...YP},body:JSON.stringify(e)});if(!r.ok){let n=await r.json().catch(()=>({}));throw new Error(`Failed to resolve types: ${n?.message}`)}return r.json()};function QP(t){if(t?.packages)for(let[e,r]of Object.entries(t.packages)){if(!$r(e))throw new Error(`Invalid package name: ${e}`);if(!Fr($e(r)))throw new Error(`Invalid package ID: ${r}`)}if(t?.types)for(let[e,r]of Object.entries(t.types)){if(ji(e).typeParams.length>0)throw new Error("Type overrides must be first-level only. If you want to supply generic types, just pass each type individually.");let n=ji(r);if(!Fr(n.address))throw new Error(`Invalid type: ${r}`)}}function sp(t,e=new Set){if(typeof t=="string"&&!rn(t))return e;let r=Zv(t)?t:ji(t);rn(r.address)&&e.add(`${r.address}::${r.module}::${r.name}`);for(let n of r.typeParams)sp(n,e);return e}function op(t,e){let r=Zv(t)?t:ji(t),n=`${r.address}::${r.module}::${r.name}`,i=e[n];return Uo({...r,address:i?i.split("::")[0]:r.address,typeParams:r.typeParams.map(s=>op(s,e))})}function rn(t){return t.includes(ZP)||t.includes("@")||t.includes(".sui")}function Zv(t){return typeof t=="object"&&"address"in t&&"module"in t&&"name"in t&&"typeParams"in t}function Yv(t){let e=new Set,r=new Set;for(let n of t.commands)switch(n.$kind){case"MakeMoveVec":n.MakeMoveVec.type&&Wv([n.MakeMoveVec.type]).forEach(o=>{r.add(o)});break;case"MoveCall":let i=n.MoveCall,s=i.package.split("::")[0];if(rn(s)){if(!$r(s))throw new Error(`Invalid package name: ${s}`);e.add(s)}Wv(i.typeArguments??[]).forEach(o=>{r.add(o)});break;default:break}return{packages:[...e],types:[...r]}}function Qv(t,e){for(let r of t.commands){if(r.MakeMoveVec?.type){if(!rn(r.MakeMoveVec.type))continue;if(!e.types[r.MakeMoveVec.type])throw new Error(`No resolution found for type: ${r.MakeMoveVec.type}`);r.MakeMoveVec.type=e.types[r.MakeMoveVec.type].type}let n=r.MoveCall;if(!n)continue;let i=n.package.split("::"),s=i[0];if(rn(s)&&!e.packages[s])throw new Error(`No address found for package: ${s}`);rn(s)&&(i[0]=e.packages[s].package,n.package=i.join("::"));let o=n.typeArguments;if(o){for(let u=0;u<o.length;u++)if(rn(o[u])){if(!e.types[o[u]])throw new Error(`No resolution found for type: ${o[u]}`);o[u]=e.types[o[u]].type}n.typeArguments=o}}}function Wv(t){let e=new Set;for(let r of t)if(rn(r)){if(!G_(r))throw new Error(`Invalid type with names: ${r}`);e.add(r)}return e}var cp=new WeakMap,eb=t=>{let e;if(t){let r=t.overrides??{packages:{},types:{}};cp.has(r)||cp.set(r,new Al),e=new Ta({cache:cp.get(r),url:t.url,pageSize:t.pageSize,overrides:r})}return async(r,n,i)=>{let s=Yv(r);if(s.types.length===0&&s.packages.length===0)return i();let o=await(e||eC(n).core.mvr).resolve({types:s.types,packages:s.packages});Qv(r,o),await i()}};function eC(t){if(!t.client)throw new Error("No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.");return t.client}var tC=50,rC=1000n,nC=5e10;function Pl(t){return async function(r,n,i){return await uC(r,t),await aC(r,t),n.onlyTransactionKind||(await iC(r,t),await sC(r,t),await oC(r,t)),await i()}}async function iC(t,e){t.gasConfig.price||(t.gasConfig.price=String(await e.getReferenceGasPrice()))}async function sC(t,e){if(t.gasConfig.budget)return;let r=await e.dryRunTransactionBlock({transactionBlock:t.build({overrides:{gasData:{budget:String(nC),payment:[]}}})});if(r.effects.status.status!=="success")throw new Error(`Dry run failed, could not automatically determine a budget: ${r.effects.status.error}`,{cause:r});let n=rC*BigInt(t.gasConfig.price||1n),i=BigInt(r.effects.gasUsed.computationCost)+n,s=i+BigInt(r.effects.gasUsed.storageCost)-BigInt(r.effects.gasUsed.storageRebate);t.gasConfig.budget=String(s>i?s:i)}async function oC(t,e){if(!t.gasConfig.payment){let n=(await e.getCoins({owner:t.gasConfig.owner||t.sender,coinType:fh})).data.filter(i=>!t.inputs.find(o=>o.Object?.ImmOrOwnedObject?i.coinObjectId===o.Object.ImmOrOwnedObject.objectId:!1)).map(i=>({objectId:i.coinObjectId,digest:i.digest,version:i.version}));if(!n.length)throw new Error("No valid gas coins found for the transaction.");t.gasConfig.payment=n.map(i=>jt(pi,i))}}async function aC(t,e){let r=t.inputs.filter(p=>p.UnresolvedObject&&!(p.UnresolvedObject.version||p.UnresolvedObject?.initialSharedVersion)),n=[...new Set(r.map(p=>Ar(p.UnresolvedObject.objectId)))],i=n.length?Ls(n,tC):[],s=(await Promise.all(i.map(p=>e.multiGetObjects({ids:p,options:{showOwner:!0}})))).flat(),o=new Map(n.map((p,_)=>[p,s[_]])),u=Array.from(o).filter(([p,_])=>_.error).map(([p,_])=>JSON.stringify(_.error));if(u.length)throw new Error(`The following input objects are invalid: ${u.join(", ")}`);let c=s.map(p=>{if(p.error||!p.data)throw new Error(`Failed to fetch object: ${p.error}`);let _=p.data.owner,b=_&&typeof _=="object"&&"Shared"in _?_.Shared.initial_shared_version:null;return{objectId:p.data.objectId,digest:p.data.digest,version:p.data.version,initialSharedVersion:b}}),d=new Map(n.map((p,_)=>[p,c[_]]));for(let[p,_]of t.inputs.entries()){if(!_.UnresolvedObject)continue;let b,O=$e(_.UnresolvedObject.objectId),T=d.get(O);_.UnresolvedObject.initialSharedVersion??T?.initialSharedVersion?b=Cn.SharedObjectRef({objectId:O,initialSharedVersion:_.UnresolvedObject.initialSharedVersion||T?.initialSharedVersion,mutable:cC(t,p)}):lC(t,p)&&(b=Cn.ReceivingRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})),t.inputs[t.inputs.indexOf(_)]=b??Cn.ObjectRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})}}async function uC(t,e){let{inputs:r,commands:n}=t,i=[],s=new Set;n.forEach(u=>{if(u.MoveCall){if(u.MoveCall._argumentTypes)return;if(u.MoveCall.arguments.map(p=>p.$kind==="Input"?t.inputs[p.Input]:null).some(p=>p?.UnresolvedPure||p?.UnresolvedObject)){let p=`${u.MoveCall.package}::${u.MoveCall.module}::${u.MoveCall.function}`;s.add(p),i.push(u.MoveCall)}}});let o=new Map;s.size>0&&await Promise.all([...s].map(async u=>{let[c,d,p]=u.split("::"),_=await e.getNormalizedMoveFunction({package:c,module:d,function:p});o.set(u,_.parameters.map(b=>Cv(b)))})),i.length&&await Promise.all(i.map(async u=>{let c=o.get(`${u.package}::${u.module}::${u.function}`);if(!c)return;let p=c.length>0&&Pv(c.at(-1))?c.slice(0,c.length-1):c;u._argumentTypes=p})),n.forEach(u=>{if(!u.MoveCall)return;let c=u.MoveCall,d=`${c.package}::${c.module}::${c.function}`,p=c._argumentTypes;if(p){if(p.length!==u.MoveCall.arguments.length)throw new Error(`Incorrect number of arguments for ${d}`);p.forEach((_,b)=>{let O=c.arguments[b];if(O.$kind!=="Input")return;let T=r[O.Input];if(!T.UnresolvedPure&&!T.UnresolvedObject)return;let x=T.UnresolvedPure?.value??T.UnresolvedObject?.objectId,F=Ol(_.body);if(F){O.type="pure",r[r.indexOf(T)]=Cn.Pure(F.serialize(x));return}if(typeof x!="string")throw new Error(`Expect the argument to be an object id string, got ${JSON.stringify(x,null,2)}`);O.type="object";let R=T.UnresolvedPure?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:x}}:T;r[O.Input]=R})}})}function cC(t,e){let r=!1;return t.getInputUses(e,(n,i)=>{if(i.MoveCall&&i.MoveCall._argumentTypes){let s=i.MoveCall.arguments.indexOf(n);r=i.MoveCall._argumentTypes[s].ref!=="&"||r}(i.$kind==="MakeMoveVec"||i.$kind==="MergeCoins"||i.$kind==="SplitCoins")&&(r=!0)}),r}function lC(t,e){let r=!1;return t.getInputUses(e,(n,i)=>{if(i.MoveCall&&i.MoveCall._argumentTypes){let s=i.MoveCall.arguments.indexOf(n);r=fC(i.MoveCall._argumentTypes[s])||r}}),r}function fC(t){return typeof t.body!="object"||!("datatype"in t.body)?!1:t.body.datatype.package==="0x2"&&t.body.datatype.module==="transfer"&&t.body.datatype.type==="Receiving"}function lp(t,e){return!!(t.inputs.some(r=>r.UnresolvedObject||r.UnresolvedPure)||!e.onlyTransactionKind&&(!t.gasConfig.price||!t.gasConfig.budget||!t.gasConfig.payment))}async function nb(t,e,r){if(hC(t),!lp(t,e))return await tb(t),r();let n=dC(e),i=n.core?.resolveTransactionPlugin()??Pl(n);return eb()(t,e,async()=>{await i(t,e,async()=>{await tb(t),await r()})})}function tb(t){t.inputs.forEach((e,r)=>{if(e.$kind!=="Object"&&e.$kind!=="Pure")throw new Error(`Input at index ${r} has not been resolved. Expected a Pure or Object input, but found ${JSON.stringify(e)}`)})}function dC(t){if(!t.client)throw new Error("No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.");return t.client}function hC(t){for(let e of t.commands)switch(e.$kind){case"SplitCoins":e.SplitCoins.amounts.forEach(r=>{rb(r,et.U64,t)});break;case"TransferObjects":rb(e.TransferObjects.address,et.Address,t);break}}function rb(t,e,r){if(t.$kind!=="Input")return;let n=r.inputs[t.Input];n.$kind==="UnresolvedPure"&&(r.inputs[t.Input]=Cn.Pure(e.serialize(n.UnresolvedPure.value)))}function ib(t){function e(r){return t(r)}return e.system=()=>e("0x5"),e.clock=()=>e("0x6"),e.random=()=>e("0x8"),e.denyList=()=>e("0x403"),e.option=({type:r,value:n})=>i=>i.moveCall({typeArguments:[r],target:`0x1::option::${n===null?"none":"some"}`,arguments:n===null?[]:[i.object(n)]}),e}function sb(t){function e(r,n){if(typeof r=="string")return t(ka(r).serialize(n));if(r instanceof Uint8Array||Ma(r))return t(r);throw new Error("tx.pure must be called either a bcs type name, or a serialized bcs value")}return e.u8=r=>t(et.U8.serialize(r)),e.u16=r=>t(et.U16.serialize(r)),e.u32=r=>t(et.U32.serialize(r)),e.u64=r=>t(et.U64.serialize(r)),e.u128=r=>t(et.U128.serialize(r)),e.u256=r=>t(et.U256.serialize(r)),e.bool=r=>t(et.Bool.serialize(r)),e.string=r=>t(et.String.serialize(r)),e.address=r=>t(et.Address.serialize(r)),e.id=e.address,e.vector=(r,n)=>t(et.vector(ka(r)).serialize(n)),e.option=(r,n)=>t(et.option(ka(r)).serialize(n)),e}function ob(t,e){let r=Array.from(`${t}::`).map(i=>i.charCodeAt(0)),n=new Uint8Array(r.length+e.length);return n.set(r),n.set(e,r.length),pl(n,{dkLen:32})}function ab(t){return $e(t).replace("0x","")}var jn=class t{constructor(e){this.version=2,this.sender=e?.sender??null,this.expiration=e?.expiration??null,this.inputs=e?.inputs??[],this.commands=e?.commands??[],this.gasData=e?.gasData??{budget:null,price:null,owner:null,payment:null}}static fromKindBytes(e){let n=et.TransactionKind.parse(e).ProgrammableTransaction;if(!n)throw new Error("Unable to deserialize from bytes.");return t.restore({version:2,sender:null,expiration:null,gasData:{budget:null,owner:null,payment:null,price:null},inputs:n.inputs,commands:n.commands})}static fromBytes(e){let n=et.TransactionData.parse(e)?.V1,i=n.kind.ProgrammableTransaction;if(!n||!i)throw new Error("Unable to deserialize from bytes.");return t.restore({version:2,sender:n.sender,expiration:n.expiration,gasData:n.gasData,inputs:i.inputs,commands:i.commands})}static restore(e){return e.version===2?new t(jt(Ia,e)):new t(jt(Ia,Lv(e)))}static getDigestFromBytes(e){let r=ob("TransactionData",e);return ci(r)}get gasConfig(){return this.gasData}set gasConfig(e){this.gasData=e}build({maxSizeBytes:e=1/0,overrides:r,onlyTransactionKind:n}={}){let i=this.inputs,s=this.commands,o={ProgrammableTransaction:{inputs:i,commands:s}};if(n)return et.TransactionKind.serialize(o,{maxSize:e}).toBytes();let u=r?.expiration??this.expiration,c=r?.sender??this.sender,d={...this.gasData,...r?.gasConfig,...r?.gasData};if(!c)throw new Error("Missing transaction sender");if(!d.budget)throw new Error("Missing gas budget");if(!d.payment)throw new Error("Missing gas payment");if(!d.price)throw new Error("Missing gas price");let p={sender:ab(c),expiration:u||{None:!0},gasData:{payment:d.payment,owner:ab(this.gasData.owner??c),price:BigInt(d.price),budget:BigInt(d.budget)},kind:{ProgrammableTransaction:{inputs:i,commands:s}}};return et.TransactionData.serialize({V1:p},{maxSize:e}).toBytes()}addInput(e,r){let n=this.inputs.length;return this.inputs.push(r),{Input:n,type:e,$kind:"Input"}}getInputUses(e,r){this.mapArguments((n,i)=>(n.$kind==="Input"&&n.Input===e&&r(n,i),n))}mapCommandArguments(e,r){let n=this.commands[e];switch(n.$kind){case"MoveCall":n.MoveCall.arguments=n.MoveCall.arguments.map(s=>r(s,n,e));break;case"TransferObjects":n.TransferObjects.objects=n.TransferObjects.objects.map(s=>r(s,n,e)),n.TransferObjects.address=r(n.TransferObjects.address,n,e);break;case"SplitCoins":n.SplitCoins.coin=r(n.SplitCoins.coin,n,e),n.SplitCoins.amounts=n.SplitCoins.amounts.map(s=>r(s,n,e));break;case"MergeCoins":n.MergeCoins.destination=r(n.MergeCoins.destination,n,e),n.MergeCoins.sources=n.MergeCoins.sources.map(s=>r(s,n,e));break;case"MakeMoveVec":n.MakeMoveVec.elements=n.MakeMoveVec.elements.map(s=>r(s,n,e));break;case"Upgrade":n.Upgrade.ticket=r(n.Upgrade.ticket,n,e);break;case"$Intent":let i=n.$Intent.inputs;n.$Intent.inputs={};for(let[s,o]of Object.entries(i))n.$Intent.inputs[s]=Array.isArray(o)?o.map(u=>r(u,n,e)):r(o,n,e);break;case"Publish":break;default:throw new Error(`Unexpected transaction kind: ${n.$kind}`)}}mapArguments(e){for(let r of this.commands.keys())this.mapCommandArguments(r,e)}replaceCommand(e,r,n=e){if(!Array.isArray(r)){this.commands[e]=r;return}let i=r.length-1;this.commands.splice(e,1,...r),i!==0&&this.mapArguments((s,o,u)=>{if(u<e+r.length)return s;switch(s.$kind){case"Result":s.Result===e&&(s.Result=n),s.Result>e&&(s.Result+=i);break;case"NestedResult":s.NestedResult[0]===e&&(s.NestedResult[0]=n),s.NestedResult[0]>e&&(s.NestedResult[0]+=i);break}return s})}getDigest(){let e=this.build({onlyTransactionKind:!1});return t.getDigestFromBytes(e)}snapshot(){return jt(Ia,this)}shallowClone(){return new t({version:this.version,sender:this.sender,expiration:this.expiration,gasData:{...this.gasData},inputs:[...this.inputs],commands:[...this.commands]})}};function fp(t){if(typeof t=="string")return $e(t);if(t.Object)return t.Object.ImmOrOwnedObject?$e(t.Object.ImmOrOwnedObject.objectId):t.Object.Receiving?$e(t.Object.Receiving.objectId):$e(t.Object.SharedObject.objectId);if(t.UnresolvedObject)return $e(t.UnresolvedObject.objectId)}var cb=t=>{throw TypeError(t)},gp=(t,e,r)=>e.has(t)||cb("Cannot "+r),ge=(t,e,r)=>(gp(t,e,"read from private field"),r?r.call(t):e.get(t)),$i=(t,e,r)=>e.has(t)?cb("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Xt=(t,e,r,n)=>(gp(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),yr=(t,e,r)=>(gp(t,e,"access private method"),r),Ho,Wo,ms,Fi,Nn,Dn,gi,Ys,We,ur,lb,Cl,jl,Nl,Dl,pp,yp,fb,db;function dp(t,e=1/0){let r={$kind:"Result",get Result(){return typeof t=="function"?t():t}},n=[],i=s=>n[s]??(n[s]={$kind:"NestedResult",get NestedResult(){return[typeof t=="function"?t():t,s]}});return new Proxy(r,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(s,o){if(o in s)return Reflect.get(s,o);if(o===Symbol.iterator)return function*(){let c=0;for(;c<e;)yield i(c),c++};if(typeof o=="symbol")return;let u=parseInt(o,10);if(!(Number.isNaN(u)||u<0))return i(u)}})}var hb=Symbol.for("@mysten/transaction");function Bl(t){return!!t&&typeof t=="object"&&t[hb]===!0}var ub={buildPlugins:new Map,serializationPlugins:new Map},hp=Symbol.for("@mysten/transaction/registry");function Vu(){try{let t=globalThis;return t[hp]||(t[hp]=ub),t[hp]}catch{return ub}}var pb=class mp{constructor(){$i(this,ur),$i(this,Ho),$i(this,Wo),$i(this,ms,new Map),$i(this,Fi,[]),$i(this,Nn,[]),$i(this,Dn,new Set),$i(this,gi,new Set),$i(this,Ys,new Map),$i(this,We),this.object=ib(r=>{if(typeof r=="function")return this.object(this.add(r));if(typeof r=="object"&&Ru(Kt,r))return r;let n=fp(r),i=ge(this,We).inputs.find(s=>n===fp(s));return i?.Object?.SharedObject&&typeof r=="object"&&r.Object?.SharedObject&&(i.Object.SharedObject.mutable=i.Object.SharedObject.mutable||r.Object.SharedObject.mutable),i?{$kind:"Input",Input:ge(this,We).inputs.indexOf(i),type:"object"}:yr(this,ur,jl).call(this,"object",typeof r=="string"?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:$e(r)}}:r)});let e=Vu();Xt(this,We,new jn),Xt(this,Wo,[...e.buildPlugins.values()]),Xt(this,Ho,[...e.serializationPlugins.values()])}static fromKind(e){let r=new mp;return Xt(r,We,jn.fromKindBytes(typeof e=="string"?sr(e):e)),Xt(r,Fi,ge(r,We).inputs.slice()),Xt(r,Nn,ge(r,We).commands.slice()),Xt(r,Dn,new Set(ge(r,Nn).map((n,i)=>i))),r}static from(e){let r=new mp;return Bl(e)?Xt(r,We,new jn(e.getData())):typeof e!="string"||!e.startsWith("{")?Xt(r,We,jn.fromBytes(typeof e=="string"?sr(e):e)):Xt(r,We,jn.restore(JSON.parse(e))),Xt(r,Fi,ge(r,We).inputs.slice()),Xt(r,Nn,ge(r,We).commands.slice()),Xt(r,Dn,new Set(ge(r,Nn).map((n,i)=>i))),r}static registerGlobalSerializationPlugin(e,r){Vu().serializationPlugins.set(e,r??e)}static unregisterGlobalSerializationPlugin(e){Vu().serializationPlugins.delete(e)}static registerGlobalBuildPlugin(e,r){Vu().buildPlugins.set(e,r??e)}static unregisterGlobalBuildPlugin(e){Vu().buildPlugins.delete(e)}addSerializationPlugin(e){ge(this,Ho).push(e)}addBuildPlugin(e){ge(this,Wo).push(e)}addIntentResolver(e,r){if(ge(this,ms).has(e)&&ge(this,ms).get(e)!==r)throw new Error(`Intent resolver for ${e} already exists`);ge(this,ms).set(e,r)}setSender(e){ge(this,We).sender=e}setSenderIfNotSet(e){ge(this,We).sender||(ge(this,We).sender=e)}setExpiration(e){ge(this,We).expiration=e?jt(Qh,e):null}setGasPrice(e){ge(this,We).gasConfig.price=String(e)}setGasBudget(e){ge(this,We).gasConfig.budget=String(e)}setGasBudgetIfNotSet(e){ge(this,We).gasData.budget==null&&(ge(this,We).gasConfig.budget=String(e))}setGasOwner(e){ge(this,We).gasConfig.owner=e}setGasPayment(e){ge(this,We).gasConfig.payment=e.map(r=>jt(pi,r))}get blockData(){return rp(ge(this,We).snapshot())}getData(){return ge(this,We).snapshot()}get[hb](){return!0}get pure(){return Object.defineProperty(this,"pure",{enumerable:!1,value:sb(e=>Ma(e)?yr(this,ur,jl).call(this,"pure",{$kind:"Pure",Pure:{bytes:e.toBase64()}}):yr(this,ur,jl).call(this,"pure",Ru(Yh,e)?jt(Yh,e):e instanceof Uint8Array?Cn.Pure(e):{$kind:"UnresolvedPure",UnresolvedPure:{value:e}}))}),this.pure}get gas(){return{$kind:"GasCoin",GasCoin:!0}}objectRef(...e){return this.object(Cn.ObjectRef(...e))}receivingRef(...e){return this.object(Cn.ReceivingRef(...e))}sharedObjectRef(...e){return this.object(Cn.SharedObjectRef(...e))}add(e){if(typeof e=="function"){if(ge(this,Ys).has(e))return ge(this,Ys).get(e);let r=yr(this,ur,lb).call(this),n=e(r);if(!(n&&typeof n=="object"&&"then"in n))return Xt(this,Dn,ge(r,Dn)),ge(this,Ys).set(e,n),n;let i=yr(this,ur,Cl).call(this,{$kind:"$Intent",$Intent:{name:"AsyncTransactionThunk",inputs:{},data:{resultIndex:ge(this,We).commands.length,result:null}}});ge(this,gi).add(Promise.resolve(n).then(o=>{i.$Intent.data.result=o}));let s=dp(()=>i.$Intent.data.resultIndex);return ge(this,Ys).set(e,s),s}else yr(this,ur,Cl).call(this,e);return dp(ge(this,We).commands.length-1)}splitCoins(e,r){let n=Js.SplitCoins(typeof e=="string"?this.object(e):yr(this,ur,Dl).call(this,e),r.map(i=>typeof i=="number"||typeof i=="bigint"||typeof i=="string"?this.pure.u64(i):yr(this,ur,Nl).call(this,i)));return yr(this,ur,Cl).call(this,n),dp(ge(this,We).commands.length-1,r.length)}mergeCoins(e,r){return this.add(Js.MergeCoins(this.object(e),r.map(n=>this.object(n))))}publish({modules:e,dependencies:r}){return this.add(Js.Publish({modules:e,dependencies:r}))}upgrade({modules:e,dependencies:r,package:n,ticket:i}){return this.add(Js.Upgrade({modules:e,dependencies:r,package:n,ticket:this.object(i)}))}moveCall({arguments:e,...r}){return this.add(Js.MoveCall({...r,arguments:e?.map(n=>yr(this,ur,Nl).call(this,n))}))}transferObjects(e,r){return this.add(Js.TransferObjects(e.map(n=>this.object(n)),typeof r=="string"?this.pure.address(r):yr(this,ur,Nl).call(this,r)))}makeMoveVec({type:e,elements:r}){return this.add(Js.MakeMoveVec({type:e,elements:r.map(n=>this.object(n))}))}serialize(){return JSON.stringify(rp(ge(this,We).snapshot()))}async toJSON(e={}){await this.prepareForSerialization(e);let r=this.isFullyResolved();return JSON.stringify(jt($v,r?{...ge(this,We).snapshot(),digest:ge(this,We).getDigest()}:ge(this,We).snapshot()),(n,i)=>typeof i=="bigint"?i.toString():i,2)}async sign(e){let{signer:r,...n}=e,i=await this.build(n);return r.signTransaction(i)}isFullyResolved(){return!(!ge(this,We).sender||ge(this,gi).size>0||ge(this,We).commands.some(e=>e.$Intent)||lp(ge(this,We),{}))}async build(e={}){return await this.prepareForSerialization(e),await yr(this,ur,pp).call(this,e),ge(this,We).build({onlyTransactionKind:e.onlyTransactionKind})}async getDigest(e={}){return await yr(this,ur,pp).call(this,e),ge(this,We).getDigest()}async prepareForSerialization(e){await yr(this,ur,fb).call(this),yr(this,ur,db).call(this);let r=new Set;for(let i of ge(this,We).commands)i.$Intent&&r.add(i.$Intent.name);let n=[...ge(this,Ho)];for(let i of r)if(!e.supportedIntents?.includes(i)){if(!ge(this,ms).has(i))throw new Error(`Missing intent resolver for ${i}`);n.push(ge(this,ms).get(i))}await yr(this,ur,yp).call(this,n,e)}};Ho=new WeakMap;Wo=new WeakMap;ms=new WeakMap;Fi=new WeakMap;Nn=new WeakMap;Dn=new WeakMap;gi=new WeakMap;Ys=new WeakMap;We=new WeakMap;ur=new WeakSet;lb=function(){let t=new pb;return Xt(t,We,ge(this,We)),Xt(t,Ho,ge(this,Ho)),Xt(t,Wo,ge(this,Wo)),Xt(t,ms,ge(this,ms)),Xt(t,gi,ge(this,gi)),Xt(t,Dn,new Set(ge(this,Dn))),Xt(t,Ys,ge(this,Ys)),ge(this,Fi).push(ge(t,Fi)),ge(this,Nn).push(ge(t,Nn)),t};Cl=function(t){let e=ge(this,We).commands.length;return ge(this,Nn).push(t),ge(this,Dn).add(e),ge(this,We).commands.push(t),ge(this,We).mapCommandArguments(e,r=>{if(r.$kind==="Result"&&!ge(this,Dn).has(r.Result))throw new Error(`Result { Result: ${r.Result} } is not available to use the current transaction`);if(r.$kind==="NestedResult"&&!ge(this,Dn).has(r.NestedResult[0]))throw new Error(`Result { NestedResult: [${r.NestedResult[0]}, ${r.NestedResult[1]}] } is not available to use the current transaction`);if(r.$kind==="Input"&&r.Input>=ge(this,We).inputs.length)throw new Error(`Input { Input: ${r.Input} } references an input that does not exist in the current transaction`);return r}),t};jl=function(t,e){return ge(this,Fi).push(e),ge(this,We).addInput(t,e)};Nl=function(t){return Ma(t)?this.pure(t):yr(this,ur,Dl).call(this,t)};Dl=function(t){if(typeof t=="function"){let e=this.add(t);return typeof e=="function"?yr(this,ur,Dl).call(this,e):jt(Kt,e)}return jt(Kt,t)};pp=async function(t){if(!t.onlyTransactionKind&&!ge(this,We).sender)throw new Error("Missing transaction sender");await yr(this,ur,yp).call(this,[...ge(this,Wo),nb],t)};yp=async function(t,e){let r=n=>{if(n>=t.length)return()=>{};let i=t[n];return async()=>{let s=r(n+1),o=!1,u=!1;if(await i(ge(this,We),e,async()=>{if(o)throw new Error(`next() was call multiple times in TransactionPlugin ${n}`);o=!0,await s(),u=!0}),!o)throw new Error(`next() was not called in TransactionPlugin ${n}`);if(!u)throw new Error(`next() was not awaited in TransactionPlugin ${n}`)}};await r(0)(),Xt(this,Fi,ge(this,We).inputs.slice()),Xt(this,Nn,ge(this,We).commands.slice())};fb=async function(){for(;ge(this,gi).size>0;){let t=Promise.all(ge(this,gi));ge(this,gi).clear(),ge(this,gi).add(t),await t,ge(this,gi).delete(t)}};db=function(){let t=ge(this,We).commands,e=ge(this,We).inputs,r=ge(this,Nn).flat(1/0),n=ge(this,Fi).flat(1/0);if(r.length!==t.length)throw new Error("Unexpected number of commands found in transaction data");if(n.length!==e.length)throw new Error("Unexpected number of inputs found in transaction data");let i=r.filter(o=>o.$Intent?.name!=="AsyncTransactionThunk");ge(this,We).commands=i,ge(this,We).inputs=n,Xt(this,Nn,i),Xt(this,Fi,n),Xt(this,Dn,new Set(i.map((o,u)=>u)));function s(o){let u=t[o];if(u.$Intent?.name==="AsyncTransactionThunk"){let d=u.$Intent.data.result;if(d==null)throw new Error("AsyncTransactionThunk has not been resolved");return s(d.Result)}let c=i.indexOf(u);if(c===-1)throw new Error("Unable to find original index for command");return c}ge(this,We).mapArguments(o=>{if(o.$kind==="Input"){let u=n.indexOf(e[o.Input]);if(u===-1)throw new Error("Input has not been resolved");return{...o,Input:u}}else if(o.$kind==="Result"){let u=s(o.Result);return{...o,Result:u}}else if(o.$kind==="NestedResult"){let u=s(o.NestedResult[0]);return{...o,NestedResult:[u,o.NestedResult[1]]}}return o});for(let[o,u]of t.entries())if(u.$Intent?.name==="AsyncTransactionThunk")try{u.$Intent.data.resultIndex=s(o)}catch{}};var ot=pb;import{addHexPrefix as mb,getObjectFields as gb}from"@cetusprotocol/common-sdk";var yb=t=>{let e=[];return t.forEach(r=>{e.push(_p(r))}),e},_p=t=>{let e=gb(t);return{marketId:e.id.id,baseToken:mb(e.base_token.fields.name),quoteToken:mb(e.quote_token.fields.name),isOpenPause:e.is_open_pause,isClosePause:e.is_close_pause,maxLongLeverage:e.max_long_leverage,maxShortLeverage:e.max_short_leverage,openFeeRate:(e.open_fee_rate/1e6).toString(),closeFeeRate:(e.close_fee_rate/1e6).toString(),positionsHandle:e.positions.fields.id.id}},vp=t=>{let e=gb(t);return{createdAt:e.created_ts,id:e.id.id,initDepositAmount:e.init_deposit_amount,isLong:e.is_long,lendingMarketId:e.lending_market_id,obligationOwnerCap:e.obligation_owner_cap.fields.obligation_id}};import{parseObligation as pC}from"@suilend/sdk/parsers/obligation";import{obligation as mC}from"@suilend/sdk/_generated/suilend/lending-market/functions";var Rl=class{constructor(e){this.getLeverageConfig=async()=>{let e=_r(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:e.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(e=!1)=>{let r="leverage_markets_list",n=this._sdk.getCache(r,e);if(n)return n;let i=_r(this._sdk.sdkOptions.leverage),s=50,o=null,u=[];for(;;){let b=await this._sdk.FullClient.getDynamicFields({parentId:i.markets_table_id,limit:s,cursor:o});if(b.data.forEach(O=>{u.push(O.objectId)}),b.data.length<s)break;o=b.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",u);let c=await this._sdk.FullClient.batchGetObjects(u,{showContent:!0}),d=[];c.forEach(b=>{d.push(b.data.content.fields.value.fields.market_id)});let p=await this._sdk.FullClient.batchGetObjects(d,{showContent:!0}),_=yb(p);return this._sdk.updateCache(r,_,_b),_};this.getLeverageMarketInfo=async e=>{let r=`leverage_market_info_${e}`,n=this._sdk.getCache(r);if(n)return n;let i=await this._sdk.FullClient.getObject({id:e,options:{showContent:!0}}),s=_p(i);return this._sdk.updateCache(r,s,_b),s};this.getLeveragePositionList=async()=>{let e=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:r,lendingMarketType:n}=_r(this._sdk.sdkOptions.suilend),i=await this._sdk.SuiLendModule.getSuilendClient(r,n),s=[];for(let o=0;o<e.data.length;o++){let u=vp(e.data[o]),c=await i.getObligation(u.obligationOwnerCap);s.push({...u,...c})}return s};this.getLeveragePosition=async e=>{let r=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:e}}),n=vp(r.data[0]),{lendingMarketId:i,lendingMarketType:s}=_r(this._sdk.sdkOptions.suilend),o=await this._sdk.SuiLendModule.getSuilendClient(i,s),{allLendingMarketData:u}=await this._sdk.SuiLendModule.getLendingMarketData(),c=u[i].reserveMap,d=await o.getObligation(n.obligationOwnerCap);return{...pC(d,c||{}),...n}};this.getClmmPoolInfo=async e=>{let r=await this._sdk.ClmmSDK.Pool.getPool(e),{coin_type_a:n,coin_type_b:i,fee_rate:s}=r;return{clmmFeeTier:s/1e6,clmmPoolCoinTypeA:n,clmmPoolCoinTypeB:i}};this.openLeveragePosition=async e=>{let{isQuote:r,isLong:n,depositAmount:i,clmmPool:s,slippage:o,leverage:u,marketId:c}=e,{lendingMarketId:d}=_r(this._sdk.sdkOptions.suilend),p=new ot,{openFeeRate:_,baseToken:b,quoteToken:O}=await this.getLeverageMarketInfo(c),{clmmFeeTier:T,clmmPoolCoinTypeA:x,clmmPoolCoinTypeB:F}=await this.getClmmPoolInfo(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",T,x,F);let{baseReserveArrayIndex:R,quoteReserveArrayIndex:H,reserve:J}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(b,O),ee=n&&r||!n&&!r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",ee);let ae=i.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",ae);let te,he;if(ee){let z=n&&r?O:b,Z=n&&r?b:O,ce=await this.findRouters(z,Z,i,!0,[s]);if(ae=ce?.amount_out.toString(),ce){let E=Qt.buildCoinWithBalance(BigInt(i.toString()),z,p);he=await this.routerSwap({router:ce.route_obj,slippage:o,inputCoin:E,txb:p}),te=he}}else te=Qt.buildCoinWithBalance(BigInt(i.toString()),r?O:b,p);let{flashAmount:A}=await this.calculateFlashLoanParams({isLong:n,leverage:u,baseToken:b,quoteToken:O,initDepositAmount:ae,reserve:J});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",A);let I=n?O:b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",I);let C=x===I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",x),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",C);let D=Mt(A).mul(T).toString(),{balanceA:N,balanceB:k,receipt:m}=this.flashLoan({amount:Mt(A),clmmPool:s,clmmPoolCoinTypeA:x,clmmPoolCoinTypeB:F,flashLoanCoin:I,tx:p}),a=n?O:b,l=n?b:O,h=await this.findRouters(a,l,Mt(A),!0,[s]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:h,debtFrom:a,debtTo:l,clmmPoolCoinTypeA:x,clmmPoolCoinTypeB:F});let y=Mt(h?.amount_out||0),v;h&&(v=await this.routerSwap({router:h.route_obj,inputCoin:C?Qt.fromBalance(N,x,p):Qt.fromBalance(k,F,p),slippage:o,txb:p}));let M=Mt(y).add(ae).mul(1-_).toDP(0,Ri.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",M,ae,y);let w=this.createLeveragePosition({leverage:u,marketId:c,baseToken:b,quoteToken:O,isLong:n,totalDepositAmount:M,tx:p});for(let z=0;z<J.length;z++){let Z=as(new Uint8Array(J[z].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(p,Z,BigInt(J[z].arrayIndex))}let g=n?R:H;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",te),await p.mergeCoins(v,[te]),await this.depositToLeveragePosition({isLong:n,marketId:c,position:w,depositReserveArrayIndex:g,inputCoin:v},p);let f=Mt(A).add(D).toDP(0,Ri.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",f,A,D);let S=await this.borrowAsset({position:w,reserveArrayIndex:n?H:R,borrowAmount:Mt(f),baseToken:b,quoteToken:O,isLong:n,lendingMarketId:d},p);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",S);let V=Qt.mintBalanceZero(C?F:x,p);return this.repayFlashLoan({tx:p,clmmPool:s,repayBase:C?Qt.intoBalance(S,x,p):V,repayQuote:C?V:Qt.intoBalance(S,F,p),receipt:m,clmmPoolCoinTypeA:x,clmmPoolCoinTypeB:F}),p.transferObjects([w],p.pure.address(this._sdk.getSenderAddress())),Qt.destroyBalanceZero(C?k:N,C?F:x,p),p};this.positionManageSizeDeposit=async e=>{let{marketId:r,positionId:n,isQuote:i,depositAmount:s,clmmPool:o,slippage:u,leverage:c,txb:d}=e,{lendingMarketId:p}=_r(this._sdk.sdkOptions.suilend),{baseToken:_,quoteToken:b}=await this.getLeverageMarketInfo(r),{isLong:O,deposits:T,borrows:x}=await this.getLeveragePosition(n),{reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(_,b),{clmmFeeTier:R,clmmPoolCoinTypeA:H,clmmPoolCoinTypeB:J}=await this.getClmmPoolInfo(o),ee=d||new ot,ae=T[0].reserveArrayIndex.toString(),te=x[0].reserveArrayIndex.toString(),he=i&&O||!i&&!O,A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",he);let I;if(he){let S=i&&O?b:_,V=i&&O?_:b,z=await this.findRouters(S,V,s,!0,[o]);if(z){let Z=Qt.buildCoinWithBalance(BigInt(s.toString()),S,ee);I=await this.routerSwap({router:z.route_obj,inputCoin:Z,slippage:u,txb:ee}),A=I}}else A=Qt.buildCoinWithBalance(BigInt(s.toString()),i?b:_,ee);let C=O?b:_;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",C);let{flashAmount:D}=await this.calculateFlashLoanParams({isLong:O,leverage:c,baseToken:_,quoteToken:b,initDepositAmount:s.toString(),reserve:F}),N=Mt(D).mul(R).toString(),k=H===C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",k);let{balanceA:m,balanceB:a,receipt:l}=this.flashLoan({amount:Mt(D),clmmPool:o,clmmPoolCoinTypeA:H,clmmPoolCoinTypeB:J,flashLoanCoin:C,tx:ee}),h=O?b:_,y=O?_:b,v=await this.findRouters(h,y,Mt(D),!0,[o]),M;v&&(M=await this.routerSwap({router:v.route_obj,inputCoin:k?Qt.fromBalance(m,H,ee):Qt.fromBalance(a,J,ee),slippage:u,txb:ee})),ee.mergeCoins(M,[A]);for(let S=0;S<F.length;S++){let V=as(new Uint8Array(F[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(ee,V,BigInt(F[S].arrayIndex))}this.depositToLeveragePosition({isLong:O,marketId:r,positionId:n,depositReserveArrayIndex:ae,inputCoin:M},ee);let w=Mt(D).add(N).toDP(0,Ri.ROUND_UP).toString(),g=this.borrowAsset({positionId:n,reserveArrayIndex:te,borrowAmount:Mt(w),baseToken:_,quoteToken:b,isLong:O,lendingMarketId:p},ee),f=Qt.mintBalanceZero(k?J:H,ee);return this.repayFlashLoan({tx:ee,clmmPool:o,repayBase:k?Qt.intoBalance(g,H,ee):f,repayQuote:k?f:Qt.intoBalance(g,J,ee),receipt:l,clmmPoolCoinTypeA:H,clmmPoolCoinTypeB:J}),Qt.destroyBalanceZero(k?a:m,k?J:H,ee),ee};this.positionManageSizeWithdraw=async e=>{let{marketId:r,positionId:n,withdrawAmount:i,isQuote:s,txb:o,clmmPool:u,slippage:c,leverage:d}=e,{lendingMarketType:p,lendingMarketId:_}=_r(this._sdk.sdkOptions.suilend),b=o||new ot,{baseToken:O,quoteToken:T}=await this.getLeverageMarketInfo(r),{isLong:x,deposits:F,borrows:R}=await this.getLeveragePosition(n),{reserve:H}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(O,T),J=s&&x||!s&&!x;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",J);let ee=i;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",ee);let ae=null;if(J){let M=O,w=T;ae=await this.findRouters(M,w,i,!1,[u]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:ae,from:M,to:w}),ee=ae?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",ee);for(let M=0;M<H.length;M++){let w=as(new Uint8Array(H[M].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(b,w,BigInt(H[M].arrayIndex))}let{token:te}=R[0].reserve,he=Mt(F[0].depositedCtokenAmount.toString()).div(Mt(d)).toDP(0,Ri.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",he);let A=Mt(ee).div(Mt(he)).toString(),I=Mt(R[0].borrowedAmount.toString()).mul(10**te.decimals).toString(),C=Mt(I).mul(A).toDP(0,Ri.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:C,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:ee,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:he});let D=await this._sdk.SuiLendModule.getSuilendClient(_,p),N=await this._sdk.PythConnection.getPriceFeedsUpdateData([F[0].reserve.priceIdentifier]),k=await D.pythClient.updatePriceFeeds(b,N,[F[0].reserve.priceIdentifier]),m=this.withdrawAsset({marketId:r,positionId:n,withdrawAmount:Mt(ee),withdrawReserveArrayIndex:F[0].reserveArrayIndex.toString(),withdrawCoinType:x?O:T,baseToken:O,quoteToken:T,priceObjectId:k&&k[0]},b),a=x?O:T,l=x?T:O;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let h=await this.findRouters(a,l,Mt(C),!1,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:h,debtFrom:a,debtTo:l});let y;h&&(y=await this.routerSwap({router:h.route_obj,inputCoin:m,slippage:c,txb:b}));let v=b.splitCoins(y,[C]);return this.repay({txb:b,positionId:n,repayReserveArrayIndex:R[0].reserveArrayIndex.toString(),repayCoin:v,repayCoinType:x?T:O,repayAmount:Mt(0)}),b.transferObjects([y,v],this._sdk.getSenderAddress()),b};this.positionManageLeverageIncrease=async e=>{let{marketId:r,positionId:n,isLong:i,currentLeverage:s,targetLeverage:o,clmmPool:u,slippage:c}=e,{baseToken:d,quoteToken:p}=await this.getLeverageMarketInfo(r),{deposits:_,borrows:b}=await this.getLeveragePosition(n),{reserve:O}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(d,p),{clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:x,clmmFeeTier:F}=await this.getClmmPoolInfo(u),{lendingMarketId:R}=_r(this._sdk.sdkOptions.suilend),{token:H}=b[0].reserve,J=new ot,ee=Mt(b[0].borrowedAmount.toString()).mul(Mt(o).sub(Mt(s))).mul(10**H.decimals).toDP(0,Ri.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",ee);let ae=ee,te=i?p:d,{balanceA:he,balanceB:A,receipt:I}=this.flashLoan({tx:J,amount:Mt(ae),clmmPool:u,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:x,flashLoanCoin:te}),C=i?p:d,D=i?d:p,N=await this.findRouters(C,D,Mt(ee),!0,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",N,C,D);let k=await this.routerSwap({router:N?.route_obj,inputCoin:i?Qt.fromBalance(A,x,J):Qt.fromBalance(he,T,J),slippage:c,txb:J});for(let y=0;y<O.length;y++){let v=as(new Uint8Array(O[y].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(J,v,BigInt(O[y].arrayIndex))}this.depositToLeveragePosition({isLong:i,marketId:r,positionId:n,depositReserveArrayIndex:i?_[0].reserveArrayIndex.toString():b[0].reserveArrayIndex.toString(),inputCoin:k},J);let m=Mt(ae).mul(Mt(1).add(F)).toDP(0,Ri.ROUND_UP).toString(),a=await this.borrowAsset({positionId:n,reserveArrayIndex:b[0].reserveArrayIndex.toString(),borrowAmount:Mt(m),baseToken:d,quoteToken:p,isLong:i,lendingMarketId:R},J),l=Qt.mintBalanceZero(i?d:p,J),h=T===te;return this.repayFlashLoan({tx:J,clmmPool:u,repayBase:i?l:Qt.intoBalance(a,d,J),repayQuote:i?Qt.intoBalance(a,p,J):l,receipt:I,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:x}),Qt.destroyBalanceZero(h?A:he,h?x:T,J),J};this.positionManageLeverageDecrease=async e=>{let{marketId:r,positionId:n,isLong:i,currentLeverage:s,targetLeverage:o,clmmPool:u,slippage:c}=e,{baseToken:d,quoteToken:p,closeFeeRate:_}=await this.getLeverageMarketInfo(r),{deposits:b,borrows:O}=await this.getLeveragePosition(n),{reserve:T}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(d,p),{lendingMarketId:x,lendingMarketType:F}=_r(this._sdk.sdkOptions.suilend),R=new ot,H=Mt(b[0].depositedCtokenAmount.toString()).mul(Mt(s).sub(Mt(o))).toString(),J=Mt(H).toDP(0,Ri.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",J);for(let N=0;N<T.length;N++){let k=as(new Uint8Array(T[N].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(R,k,BigInt(T[N].arrayIndex))}let ee=await this._sdk.SuiLendModule.getSuilendClient(x,F),ae=await this._sdk.PythConnection.getPriceFeedsUpdateData([b[0].reserve.priceIdentifier]),te=await ee.pythClient.updatePriceFeeds(R,ae,[b[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",d);let he=this.withdrawAsset({marketId:r,positionId:n,withdrawAmount:Mt(J),withdrawReserveArrayIndex:b[0].reserveArrayIndex.toString(),withdrawCoinType:i?d:p,baseToken:d,quoteToken:p,priceObjectId:te&&te[0]},R),A=i?d:p,I=i?p:d,C=await this.findRouters(A,I,Mt(J),!0,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",C,C?.route_obj.paths,A,I);let D=await this.routerSwap({router:C?.route_obj,inputCoin:he,slippage:c,txb:R});return this.repay({txb:R,positionId:n,repayReserveArrayIndex:O[0].reserveArrayIndex.toString(),repayCoin:D,repayCoinType:i?p:d,repayAmount:Mt(0)}),D&&R.transferObjects([D],this._sdk.getSenderAddress()),R};this.leveragePositionClose=async(e,r)=>{let n=r||new ot,{marketId:i,positionId:s}=e,{leverage:o}=this._sdk.sdkOptions,{global_config_id:u}=_r(this._sdk.sdkOptions.leverage),{lendingMarketType:c,lendingMarketId:d}=_r(this._sdk.sdkOptions.suilend),{baseToken:p,quoteToken:_}=await this.getLeverageMarketInfo(i),b=await this.getLeveragePosition(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:541 ~ LeverageModules ~ positionInfo:",b.original.id);let O=mC(n,c,{obligationId:b.original.id,lendingMarket:n.object(d)});return n.moveCall({target:`${o.published_at}::position::close_Position`,typeArguments:[c,p,_],arguments:[n.object(u),n.object(i),n.object(s),O,n.object(Qs)]}),n};this.flashLoan=e=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",e);let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:n}=_r(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:i,clmmPool:s,clmmPoolCoinTypeA:o,clmmPoolCoinTypeB:u,flashLoanCoin:c,tx:d}=e,p=o===c,[_,b,O]=d.moveCall({target:`${r.published_at}::pool::flash_loan`,arguments:[d.object(n),d.object(s),d.pure.bool(p),d.pure.u64(i.toString())],typeArguments:[o,u]});return{balanceA:_,balanceB:b,receipt:O}};this.repayFlashLoan=e=>{let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:n}=_r(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:i,repayBase:s,repayQuote:o,receipt:u,clmmPool:c,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:p}=e;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",e),i.moveCall({target:`${r.published_at}::pool::repay_flash_loan`,arguments:[i.object(n),i.object(c),s,o,u],typeArguments:[d,p]}),i};this.borrowAsset=(e,r)=>{let{position:n,reserveArrayIndex:i,borrowAmount:s,baseToken:o,quoteToken:u,lendingMarketId:c,isLong:d,positionId:p}=e;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",e);let{leverage:_}=this._sdk.sdkOptions,{lendingMarketType:b}=_r(this._sdk.sdkOptions.suilend);return Qt.isSuiCoin(d?u:o)?r.moveCall({target:`${_.published_at}::position::borrow_sui`,typeArguments:[b],arguments:[r.object(c),n,r.pure.u64(i),r.pure.u64(s.toString()),r.object(al),r.object(Qs)]}):r.moveCall({target:`${_.published_at}::position::borrow_not_sui`,typeArguments:[b,d?u:o],arguments:[r.object(c),p?r.object(p):n,r.pure.u64(i),r.pure.u64(s.toString()),r.object(Qs)]})};this.withdrawAsset=(e,r)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",e);let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:i,lendingMarketType:s}=_r(this._sdk.sdkOptions.suilend),{package_id:o}=this._sdk.sdkOptions.suilend,{marketId:u,positionId:c,withdrawAmount:d,withdrawReserveArrayIndex:p,withdrawCoinType:_,baseToken:b,quoteToken:O,priceObjectId:T}=e,[x]=r.moveCall({target:"0x1::option::none",typeArguments:[`${o}::lending_market::RateLimiterExemption<${s}, ${_}>`],arguments:[]});return Qt.isSuiCoin(_)?r.moveCall({target:`${n.published_at}::position::withdraw_sui`,typeArguments:[s,b,O],arguments:[r.object(i),r.object(u),r.object(c),r.object(T),r.object(x),r.pure.u64(d.toString()),r.pure.u64(p),r.object(al),r.object(Qs)]}):r.moveCall({target:`${n.published_at}::position::withdraw_not_sui`,typeArguments:[s,b,O,_],arguments:[r.object(i),r.object(u),r.object(c),r.object(T),r.object(x),r.pure.u64(d.toString()),r.pure.u64(p),r.object(Qs)]})};this.repay=e=>{let{leverage:r}=this._sdk.sdkOptions,{lendingMarketId:n,lendingMarketType:i}=_r(this._sdk.sdkOptions.suilend),{txb:s,positionId:o,repayAmount:u,repayCoinType:c,repayCoin:d,repayReserveArrayIndex:p}=e,_=s||new ot,b=d||Qt.buildCoinWithBalance(BigInt(u.toString()),c,_);_.moveCall({target:`${r.published_at}::position::repay`,typeArguments:[i,c],arguments:[_.object(n),_.object(o),_.object(b),_.pure.u64(p.toString()),_.object(Qs)]})};this.routerSwap=async e=>{let{slippage:r,txb:n,inputCoin:i,router:s}=e,o=n||new ot;if(s)return await this._sdk.AggregatorClient.routerSwap({router:s,inputCoin:i,slippage:r,txb:o})};this.calculateOpenPosition=async e=>{let{isQuote:r,isLong:n,depositAmount:i,clmmPool:s,slippage:o,leverage:u,marketId:c}=e,{baseToken:d,quoteToken:p}=await this.getLeverageMarketInfo(c),{reserve:_}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(d,p),b=n&&r||!n&&!r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",b);let O=i.toString();if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",O),b){let H=n&&r?p:d,J=n&&r?d:p;O=(await this.findRouters(H,J,i,!0,[s]))?.amount_out.toString()}let{flashAmount:T}=await this.calculateFlashLoanParams({isLong:n,leverage:u,baseToken:d,quoteToken:p,initDepositAmount:O,reserve:_});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",T);let x=n?p:d,F=n?d:p,R=await this.findRouters(x,F,Mt(T),!0,[s]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",R),R};this._sdk=e}async calculateFlashLoanParams(e){let{isLong:r,leverage:n,baseToken:i,quoteToken:s,initDepositAmount:o,reserve:u}=e,c=await this._sdk.SuiLendModule.getLatestPriceFeeds(u);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",c,s,i);let d=c[vb(s)]?.price,p=c[vb(i)]?.price,_=r?Mt(p).div(Mt(d)).toString():Mt(d).div(Mt(p)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",o.toString(),r,_,d,p),{flashAmount:Mt(o).mul(n-1).mul(_).toDP(0,Ri.ROUND_UP).toString(),rate:_,quotePrice:d,basePrice:p}}createLeveragePosition(e){let{lendingMarketId:r,lendingMarketType:n}=_r(this._sdk.sdkOptions.suilend),{global_config_id:i}=_r(this._sdk.sdkOptions.leverage),s=this._sdk.sdkOptions.leverage,{leverage:o,marketId:u,baseToken:c,quoteToken:d,isLong:p,totalDepositAmount:_,tx:b}=e;return b.moveCall({target:`${s.published_at}::position::open_position`,arguments:[b.object(i),b.object(u),b.object(r),b.pure.u64(_),b.pure.u64(o*1e4),b.object(Qs)],typeArguments:[n,c,d,p?c:d]})}async depositToLeveragePosition(e,r){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",e);let{leverage:n}=this._sdk.sdkOptions,{lendingMarketType:i,lendingMarketId:s}=_r(this._sdk.sdkOptions.suilend),{isLong:o,marketId:u,position:c,positionId:d,depositReserveArrayIndex:p,inputCoin:_}=e,{baseToken:b,quoteToken:O}=await this.getLeverageMarketInfo(u);return r.moveCall({target:`${n.published_at}::position::deposit`,typeArguments:[i,b,O,o?b:O],arguments:[r.object(s),r.object(u),c||r.object(d),_,r.pure.u64(p),r.object(Qs)]}),r}async findRouters(e,r,n,i,s){let{providers:o}=this._sdk.sdkOptions;try{let u={from:e,target:r,amount:new bp.default(n.toFixed(0).toString()),byAmountIn:i,depth:3,providers:o},c=await this._sdk.AggregatorClient.findRouters(u);if(c?.error?.code===10001)return{...c,is_exceed:c.insufficientLiquidity};if(c?.insufficientLiquidity)return{...c,is_exceed:c.insufficientLiquidity};if(!c?.paths||c?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:c.amountIn.toString(),amount_out:c.amountOut.toString(),is_exceed:c.insufficientLiquidity,route_obj:c,byAmountIn:!0,originRes:c}}catch{try{if(s){let c=await this._sdk.AggregatorClient.swapInPools({from:e,target:r,amount:new bp.default(n.toFixed(0).toString()),byAmountIn:i,pools:s});return c?{amount_in:c.routeData.amountIn.toString(),amount_out:c.routeData.amountOut.toString(),is_exceed:c.isExceed,route_obj:c.routeData,byAmountIn:!0,originRes:c}:null}return null}catch{return null}}}};var Gc=m_(AI());var pG={"-32700":"ParseError","-32701":"OversizedRequest","-32702":"OversizedResponse","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError","-32604":"ServerBusy","-32000":"CallExecutionFailed","-32001":"UnknownError","-32003":"SubscriptionClosed","-32004":"SubscriptionClosedWithError","-32005":"BatchesNotSupported","-32006":"TooManySubscriptions","-32050":"TransientError","-32002":"TransactionExecutionClientError"},md=class extends Error{},au=class extends md{constructor(e,r){super(e),this.code=r,this.type=pG[r]??"ServerError"}},gd=class extends md{constructor(e,r,n){super(e),this.status=r,this.statusText=n}};var II=t=>{throw TypeError(t)},Dy=(t,e,r)=>e.has(t)||II("Cannot "+r),nr=(t,e,r)=>(Dy(t,e,"read from private field"),r?r.call(t):e.get(t)),ha=(t,e,r)=>e.has(t)?II("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),uu=(t,e,r,n)=>(Dy(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),TI=(t,e,r)=>(Dy(t,e,"access private method"),r),mG=(t,e,r,n)=>({set _(i){uu(t,e,i,r)},get _(){return nr(t,e,n)}}),ko,Dc,xs,pa,Bc,ma,yd,xI,PI;function gG(t){let e=new URL(t);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var yG={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},_d=class{constructor(e,r={}){if(ha(this,yd),ha(this,ko,0),ha(this,Dc,0),ha(this,xs,null),ha(this,pa,null),ha(this,Bc,new Set),ha(this,ma,new Map),this.endpoint=e,this.options={...yG,...r},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=gG(this.endpoint))}async makeRequest(e,r,n){let i=await TI(this,yd,xI).call(this);return new Promise((s,o)=>{uu(this,ko,nr(this,ko)+1),nr(this,ma).set(nr(this,ko),{resolve:s,reject:o,timeout:setTimeout(()=>{nr(this,ma).delete(nr(this,ko)),o(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n?.addEventListener("abort",()=>{nr(this,ma).delete(nr(this,ko)),o(n.reason)}),i.send(JSON.stringify({jsonrpc:"2.0",id:nr(this,ko),method:e,params:r}))}).then(({error:s,result:o})=>{if(s)throw new au(s.message,s.code);return o})}async subscribe(e){let r=new Ny(e);return nr(this,Bc).add(r),await r.subscribe(this),()=>r.unsubscribe(this)}};ko=new WeakMap;Dc=new WeakMap;xs=new WeakMap;pa=new WeakMap;Bc=new WeakMap;ma=new WeakMap;yd=new WeakSet;xI=function(){return nr(this,pa)?nr(this,pa):(uu(this,pa,new Promise(t=>{nr(this,xs)?.close(),uu(this,xs,new this.options.WebSocketConstructor(this.endpoint)),nr(this,xs).addEventListener("open",()=>{uu(this,Dc,0),t(nr(this,xs))}),nr(this,xs).addEventListener("close",()=>{mG(this,Dc)._++,nr(this,Dc)<=this.options.maxReconnects&&setTimeout(()=>{TI(this,yd,PI).call(this)},this.options.reconnectTimeout)}),nr(this,xs).addEventListener("message",({data:e})=>{let r;try{r=JSON.parse(e)}catch(n){console.error(new Error(`Failed to parse RPC message: ${e}`,{cause:n}));return}if("id"in r&&r.id!=null&&nr(this,ma).has(r.id)){let{resolve:n,timeout:i}=nr(this,ma).get(r.id);clearTimeout(i),n(r)}else if("params"in r){let{params:n}=r;nr(this,Bc).forEach(i=>{i.subscriptionId===n.subscription&&n.subscription===i.subscriptionId&&i.onMessage(n.result)})}})})),nr(this,pa))};PI=async function(){return nr(this,xs)?.close(),uu(this,pa,null),Promise.allSettled([...nr(this,Bc)].map(t=>t.subscribe(this)))};var Ny=class{constructor(e){this.subscriptionId=null,this.subscribed=!1,this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:r}=this;return this.subscribed=!1,r==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[r]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let r=await e.makeRequest(this.input.method,this.input.params,this.input.signal);this.subscribed&&(this.subscriptionId=r)}};var CI=t=>{throw TypeError(t)},Uy=(t,e,r)=>e.has(t)||CI("Cannot "+r),Vn=(t,e,r)=>(Uy(t,e,"read from private field"),r?r.call(t):e.get(t)),vd=(t,e,r)=>e.has(t)?CI("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),By=(t,e,r,n)=>(Uy(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_G=(t,e,r)=>(Uy(t,e,"access private method"),r),Rc,Ai,Uc,Ry,jI,bd=class{constructor(e){vd(this,Ry),vd(this,Rc,0),vd(this,Ai),vd(this,Uc),By(this,Ai,e)}fetch(e,r){let n=Vn(this,Ai).fetch??fetch;if(!n)throw new Error("The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.");return n(e,r)}async request(e){By(this,Rc,Vn(this,Rc)+1);let r=await this.fetch(Vn(this,Ai).rpc?.url??Vn(this,Ai).url,{method:"POST",signal:e.signal,headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":Il,"Client-Target-Api-Version":Hv,"Client-Request-Method":e.method,...Vn(this,Ai).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:Vn(this,Rc),method:e.method,params:e.params})});if(!r.ok)throw new gd(`Unexpected status code: ${r.status}`,r.status,r.statusText);let n=await r.json();if("error"in n&&n.error!=null)throw new au(n.error.message,n.error.code);return n.result}async subscribe(e){let r=await _G(this,Ry,jI).call(this).subscribe(e);return e.signal&&(e.signal.throwIfAborted(),e.signal.addEventListener("abort",()=>{r()})),async()=>!!await r()}};Rc=new WeakMap;Ai=new WeakMap;Uc=new WeakMap;Ry=new WeakSet;jI=function(){if(!Vn(this,Uc)){let t=Vn(this,Ai).WebSocketConstructor??WebSocket;if(!t)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");By(this,Uc,new _d(Vn(this,Ai).websocket?.url??Vn(this,Ai).url,{WebSocketConstructor:t,...Vn(this,Ai).websocket}))}return Vn(this,Uc)};var cu=class{constructor({network:e,base:r}){this.cache=new Al,this.network=e,this.base=r??this}$extend(...e){return Object.create(this,Object.fromEntries(e.map(r=>{if("experimental_asClientExtension"in r){let{name:n,register:i}=r.experimental_asClientExtension();return[n,{value:i(this)}]}return[r.name,{value:r.register(this)}]})))}};var wd=class extends cu{constructor(e){super(e),this.core=this,this.mvr=new Ta({cache:this.base.cache.scope("core"),url:e.mvr?.url,pageSize:e.mvr?.pageSize,overrides:e.mvr?.overrides})}async getObject(e){let{objectId:r}=e,{objects:[n]}=await this.getObjects({objectIds:[r],signal:e.signal});if(n instanceof Error)throw n;return{object:n}}async getDynamicField(e){let r=fv(e.parentId,fi.parseFromStr(e.name.type),e.name.bcs),{objects:[n]}=await this.getObjects({objectIds:[r],signal:e.signal});if(n instanceof Error)throw n;let i=ji(n.type),s=await n.content;return{dynamicField:{id:n.id,digest:n.digest,version:n.version,type:n.type,name:{type:typeof i.typeParams[0]=="string"?i.typeParams[0]:Uo(i.typeParams[0]),bcs:e.name.bcs},value:{type:typeof i.typeParams[1]=="string"?i.typeParams[1]:Uo(i.typeParams[1]),bcs:s.slice(Ro+e.name.bcs.length)}}}}async waitForTransaction({signal:e,timeout:r=60*1e3,...n}){let i=e?AbortSignal.any([AbortSignal.timeout(r),e]):AbortSignal.timeout(r),s=new Promise((o,u)=>{i.addEventListener("abort",()=>u(i.reason))});for(s.catch(()=>{});;){i.throwIfAborted();try{return await this.getTransaction({...n,signal:i})}catch{await Promise.race([new Promise(u=>setTimeout(u,2e3)),s])}}}};var Ly=class extends Error{},Lc=class t extends Ly{constructor(e,r){super(r),this.code=e}static fromResponse(e,r){switch(e.code){case"notExists":return new t(e.code,`Object ${e.object_id} does not exist`);case"dynamicFieldNotFound":return new t(e.code,`Dynamic field not found for object ${e.parent_object_id}`);case"deleted":return new t(e.code,`Object ${e.object_id} has been deleted`);case"displayError":return new t(e.code,`Display error: ${e.error}`);case"unknown":default:return new t(e.code,`Unknown error while loading object${r?` ${r}`:""}`)}}};function NI(t){return{...jn.fromBytes(t).snapshot(),bcs:t}}function DI(t){let e=et.TransactionEffects.parse(t);switch(e.$kind){case"V1":return vG({bytes:t,effects:e.V1});case"V2":return bG({bytes:t,effects:e.V2});default:throw new Error(`Unknown transaction effects version: ${e.$kind}`)}}function vG(t){throw new Error("V1 effects are not supported yet")}function bG({bytes:t,effects:e}){let r=e.changedObjects.map(([n,i])=>({id:n,inputState:i.inputState.$kind==="Exist"?"Exists":"DoesNotExist",inputVersion:i.inputState.Exist?.[0][0]??null,inputDigest:i.inputState.Exist?.[0][1]??null,inputOwner:i.inputState.Exist?.[1]??null,outputState:i.outputState.$kind==="NotExist"?"DoesNotExist":i.outputState.$kind,outputVersion:i.outputState.$kind==="PackageWrite"?i.outputState.PackageWrite?.[0]:i.outputState.ObjectWrite?e.lamportVersion:null,outputDigest:i.outputState.$kind==="PackageWrite"?i.outputState.PackageWrite?.[1]:i.outputState.ObjectWrite?.[0]??null,outputOwner:i.outputState.ObjectWrite?i.outputState.ObjectWrite[1]:null,idOperation:i.idOperation.$kind}));return{bcs:t,digest:e.transactionDigest,version:2,status:e.status.$kind==="Success"?{success:!0,error:null}:{success:!1,error:e.status.Failed.error.$kind},gasUsed:e.gasUsed,transactionDigest:e.transactionDigest,gasObject:e.gasObjectIndex===null?null:r[e.gasObjectIndex]??null,eventsDigest:e.eventsDigest,dependencies:e.dependencies,lamportVersion:e.lamportVersion,changedObjects:r,unchangedSharedObjects:e.unchangedSharedObjects.map(([n,i])=>({kind:i.$kind,objectId:n,version:i.$kind==="ReadOnlyRoot"?i.ReadOnlyRoot[0]:i[i.$kind],digest:i.$kind==="ReadOnlyRoot"?i.ReadOnlyRoot[1]:null})),auxiliaryDataDigest:e.auxDataDigest}}var UI=t=>{throw TypeError(t)},LI=(t,e,r)=>e.has(t)||UI("Cannot "+r),On=(t,e,r)=>(LI(t,e,"read from private field"),r?r.call(t):e.get(t)),wG=(t,e,r)=>e.has(t)?UI("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),MG=(t,e,r,n)=>(LI(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Zr,Md=class extends wd{constructor({jsonRpcClient:e,mvr:r}){super({network:e.network,base:e,mvr:r}),wG(this,Zr),MG(this,Zr,e)}async getObjects(e){let r=Ls(e.objectIds,50),n=[];for(let i of r){let s=await On(this,Zr).multiGetObjects({ids:i,options:{showOwner:!0,showType:!0,showBcs:!0},signal:e.signal});for(let[o,u]of s.entries())u.error?n.push(Lc.fromResponse(u.error,i[o])):n.push(BI(u.data))}return{objects:n}}async getOwnedObjects(e){let r=await On(this,Zr).getOwnedObjects({owner:e.address,limit:e.limit,cursor:e.cursor,options:{showOwner:!0,showType:!0,showBcs:!0},filter:e.type?{StructType:e.type}:null,signal:e.signal});return{objects:r.data.map(n=>{if(n.error)throw Lc.fromResponse(n.error);return BI(n.data)}),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getCoins(e){let r=await On(this,Zr).getCoins({owner:e.address,coinType:e.coinType,limit:e.limit,cursor:e.cursor,signal:e.signal});return{objects:r.data.map(n=>({id:n.coinObjectId,version:n.version,digest:n.digest,balance:n.balance,type:`0x2::coin::Coin<${n.coinType}>`,content:Promise.resolve(OG.serialize({id:n.coinObjectId,balance:{value:n.balance}}).toBytes()),owner:{$kind:"ObjectOwner",ObjectOwner:e.address}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getBalance(e){let r=await On(this,Zr).getBalance({owner:e.address,coinType:e.coinType,signal:e.signal});return{balance:{coinType:r.coinType,balance:r.totalBalance}}}async getAllBalances(e){return{balances:(await On(this,Zr).getAllBalances({owner:e.address,signal:e.signal})).map(n=>({coinType:n.coinType,balance:n.totalBalance})),hasNextPage:!1,cursor:null}}async getTransaction(e){let r=await On(this,Zr).getTransactionBlock({digest:e.digest,options:{showRawInput:!0,showObjectChanges:!0,showRawEffects:!0,showEvents:!0,showEffects:!0},signal:e.signal});return{transaction:RI(r)}}async executeTransaction(e){let r=await On(this,Zr).executeTransactionBlock({transactionBlock:e.transaction,signature:e.signatures,options:{showRawEffects:!0,showEvents:!0,showObjectChanges:!0,showRawInput:!0,showEffects:!0},signal:e.signal});return{transaction:RI(r)}}async dryRunTransaction(e){let r=ot.from(e.transaction),n=await On(this,Zr).dryRunTransactionBlock({transactionBlock:e.transaction,signal:e.signal}),{effects:i,objectTypes:s}=SG({effects:n.effects,objectChanges:n.objectChanges});return{transaction:{digest:await r.getDigest(),epoch:null,effects:i,objectTypes:Promise.resolve(s),signatures:[],transaction:NI(e.transaction)}}}async getReferenceGasPrice(e){let r=await On(this,Zr).getReferenceGasPrice({signal:e?.signal});return{referenceGasPrice:String(r)}}async getDynamicFields(e){let r=await On(this,Zr).getDynamicFields({parentId:e.parentId,limit:e.limit,cursor:e.cursor});return{dynamicFields:r.data.map(n=>({id:n.objectId,type:n.objectType,name:{type:n.name.type,bcs:sr(n.bcsName)}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor}}async verifyZkLoginSignature(e){let r=await On(this,Zr).verifyZkLoginSignature({bytes:e.bytes,signature:e.signature,intentScope:e.intentScope,author:e.author});return{success:r.success,errors:r.errors}}resolveNameServiceNames(e){return On(this,Zr).resolveNameServiceNames(e)}resolveTransactionPlugin(){return Pl(On(this,Zr))}};Zr=new WeakMap;function BI(t){return{id:t.objectId,version:t.version,digest:t.digest,type:t.type,content:Promise.resolve(t.bcs?.dataType==="moveObject"?sr(t.bcs.bcsBytes):new Uint8Array),owner:lu(t.owner)}}function lu(t){if(t==="Immutable")return{$kind:"Immutable",Immutable:!0};if("ConsensusV2"in t)return{$kind:"ConsensusV2",ConsensusV2:{authenticator:{$kind:"SingleOwner",SingleOwner:t.ConsensusV2.authenticator.SingleOwner},startVersion:t.ConsensusV2.start_version}};if("AddressOwner"in t)return{$kind:"AddressOwner",AddressOwner:t.AddressOwner};if("ObjectOwner"in t)return{$kind:"ObjectOwner",ObjectOwner:t.ObjectOwner};if("Shared"in t)return{$kind:"Shared",Shared:{initialSharedVersion:t.Shared.initial_shared_version}};throw new Error(`Unknown owner type: ${JSON.stringify(t)}`)}function RI(t){let e=et.SenderSignedData.parse(sr(t.rawTransaction))[0],r={};t.objectChanges?.forEach(s=>{s.type!=="published"&&(r[s.objectId]=s.objectType)});let n=et.TransactionData.serialize(e.intentMessage.value).toBytes(),i=jn.restore({version:2,sender:e.intentMessage.value.V1.sender,expiration:e.intentMessage.value.V1.expiration,gasData:e.intentMessage.value.V1.gasData,inputs:e.intentMessage.value.V1.kind.ProgrammableTransaction.inputs,commands:e.intentMessage.value.V1.kind.ProgrammableTransaction.commands});return{digest:t.digest,epoch:t.effects?.executedEpoch??null,effects:DI(new Uint8Array(t.rawEffects)),objectTypes:Promise.resolve(r),transaction:{...i,bcs:n},signatures:e.txSignatures}}function SG({bytes:t,effects:e,objectChanges:r}){let n=[],i=[],s={};return r?.forEach(o=>{switch(o.type){case"published":n.push({id:o.packageId,inputState:"DoesNotExist",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"PackageWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:null,idOperation:"Created"});break;case"transferred":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:o.digest,inputOwner:{$kind:"AddressOwner",AddressOwner:o.sender},outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:lu(o.recipient),idOperation:"None"}),s[o.objectId]=o.objectType;break;case"mutated":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.previousVersion,inputDigest:null,inputOwner:lu(o.owner),outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:lu(o.owner),idOperation:"None"}),s[o.objectId]=o.objectType;break;case"deleted":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:e.deleted?.find(u=>u.objectId===o.objectId)?.digest??null,inputOwner:null,outputState:"DoesNotExist",outputVersion:null,outputDigest:null,outputOwner:null,idOperation:"Deleted"}),s[o.objectId]=o.objectType;break;case"wrapped":n.push({id:o.objectId,inputState:"Exists",inputVersion:o.version,inputDigest:null,inputOwner:{$kind:"AddressOwner",AddressOwner:o.sender},outputState:"ObjectWrite",outputVersion:o.version,outputDigest:e.wrapped?.find(u=>u.objectId===o.objectId)?.digest??null,outputOwner:{$kind:"ObjectOwner",ObjectOwner:o.sender},idOperation:"None"}),s[o.objectId]=o.objectType;break;case"created":n.push({id:o.objectId,inputState:"DoesNotExist",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:lu(o.owner),idOperation:"Created"}),s[o.objectId]=o.objectType;break}}),{objectTypes:s,effects:{bcs:t??null,digest:e.transactionDigest,version:2,status:e.status.status==="success"?{success:!0,error:null}:{success:!1,error:e.status.error},gasUsed:e.gasUsed,transactionDigest:e.transactionDigest,gasObject:{id:e.gasObject?.reference.objectId,inputState:"Exists",inputVersion:null,inputDigest:null,inputOwner:null,outputState:"ObjectWrite",outputVersion:e.gasObject.reference.version,outputDigest:e.gasObject.reference.digest,outputOwner:lu(e.gasObject.owner),idOperation:"None"},eventsDigest:e.eventsDigest??null,dependencies:e.dependencies??[],lamportVersion:e.gasObject.reference.version,changedObjects:n,unchangedSharedObjects:i,auxiliaryDataDigest:null}}}var kG=et.struct("Balance",{value:et.u64()}),OG=et.struct("Coin",{id:et.Address,balance:kG});var EG=Symbol.for("@mysten/SuiClient");var Ps=class extends cu{constructor(e){super({network:e.network??"unknown"}),this.jsonRpc=this,this.transport=e.transport??new bd({url:e.url}),this.core=new Md({jsonRpcClient:this,mvr:e.mvr})}get[EG](){return!0}async getRpcApiVersion({signal:e}={}){return(await this.transport.request({method:"rpc.discover",params:[],signal:e})).info.version}async getCoins({coinType:e,owner:r,cursor:n,limit:i,signal:s}){if(!r||!Fr($e(r)))throw new Error("Invalid Sui address");return e&&rn(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getCoins",params:[r,e,n,i],signal:s})}async getAllCoins(e){if(!e.owner||!Fr($e(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllCoins",params:[e.owner,e.cursor,e.limit],signal:e.signal})}async getBalance({owner:e,coinType:r,signal:n}){if(!e||!Fr($e(e)))throw new Error("Invalid Sui address");return r&&rn(r)&&(r=(await this.core.mvr.resolveType({type:r})).type),await this.transport.request({method:"suix_getBalance",params:[e,r],signal:n})}async getAllBalances(e){if(!e.owner||!Fr($e(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllBalances",params:[e.owner],signal:e.signal})}async getCoinMetadata({coinType:e,signal:r}){return e&&rn(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getCoinMetadata",params:[e],signal:r})}async getTotalSupply({coinType:e,signal:r}){return e&&rn(e)&&(e=(await this.core.mvr.resolveType({type:e})).type),await this.transport.request({method:"suix_getTotalSupply",params:[e],signal:r})}async call(e,r,{signal:n}={}){return await this.transport.request({method:e,params:r,signal:n})}async getMoveFunctionArgTypes({package:e,module:r,function:n,signal:i}){return e&&$r(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getMoveFunctionArgTypes",params:[e,r,n],signal:i})}async getNormalizedMoveModulesByPackage({package:e,signal:r}){return e&&$r(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveModulesByPackage",params:[e],signal:r})}async getNormalizedMoveModule({package:e,module:r,signal:n}){return e&&$r(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveModule",params:[e,r],signal:n})}async getNormalizedMoveFunction({package:e,module:r,function:n,signal:i}){return e&&$r(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveFunction",params:[e,r,n],signal:i})}async getNormalizedMoveStruct({package:e,module:r,struct:n,signal:i}){return e&&$r(e)&&(e=(await this.core.mvr.resolvePackage({package:e})).package),await this.transport.request({method:"sui_getNormalizedMoveStruct",params:[e,r,n],signal:i})}async getOwnedObjects(e){if(!e.owner||!Fr($e(e.owner)))throw new Error("Invalid Sui address");let r=e.filter?{...e.filter}:void 0;return r&&"MoveModule"in r&&$r(r.MoveModule.package)?r.MoveModule={module:r.MoveModule.module,package:(await this.core.mvr.resolvePackage({package:r.MoveModule.package})).package}:r&&"StructType"in r&&rn(r.StructType)&&(r.StructType=(await this.core.mvr.resolveType({type:r.StructType})).type),await this.transport.request({method:"suix_getOwnedObjects",params:[e.owner,{filter:r,options:e.options},e.cursor,e.limit],signal:e.signal})}async getObject(e){if(!e.id||!Fs(Ar(e.id)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"sui_getObject",params:[e.id,e.options],signal:e.signal})}async tryGetPastObject(e){return await this.transport.request({method:"sui_tryGetPastObject",params:[e.id,e.version,e.options],signal:e.signal})}async multiGetObjects(e){if(e.ids.forEach(n=>{if(!n||!Fs(Ar(n)))throw new Error(`Invalid Sui Object id ${n}`)}),e.ids.length!==new Set(e.ids).size)throw new Error(`Duplicate object ids in batch call ${e.ids}`);return await this.transport.request({method:"sui_multiGetObjects",params:[e.ids,e.options],signal:e.signal})}async queryTransactionBlocks({filter:e,options:r,cursor:n,limit:i,order:s,signal:o}){return e&&"MoveFunction"in e&&$r(e.MoveFunction.package)&&(e={...e,MoveFunction:{package:(await this.core.mvr.resolvePackage({package:e.MoveFunction.package})).package}}),await this.transport.request({method:"suix_queryTransactionBlocks",params:[{filter:e,options:r},n,i,(s||"descending")==="descending"],signal:o})}async getTransactionBlock(e){if(!sl(e.digest))throw new Error("Invalid Transaction digest");return await this.transport.request({method:"sui_getTransactionBlock",params:[e.digest,e.options],signal:e.signal})}async multiGetTransactionBlocks(e){if(e.digests.forEach(n=>{if(!sl(n))throw new Error(`Invalid Transaction digest ${n}`)}),e.digests.length!==new Set(e.digests).size)throw new Error(`Duplicate digests in batch call ${e.digests}`);return await this.transport.request({method:"sui_multiGetTransactionBlocks",params:[e.digests,e.options],signal:e.signal})}async executeTransactionBlock({transactionBlock:e,signature:r,options:n,requestType:i,signal:s}){let o=await this.transport.request({method:"sui_executeTransactionBlock",params:[typeof e=="string"?e:Ht(e),Array.isArray(r)?r:[r],n],signal:s});if(i==="WaitForLocalExecution")try{await this.waitForTransaction({digest:o.digest})}catch{}return o}async signAndExecuteTransaction({transaction:e,signer:r,...n}){let i;e instanceof Uint8Array?i=e:(e.setSenderIfNotSet(r.toSuiAddress()),i=await e.build({client:this}));let{signature:s,bytes:o}=await r.signTransaction(i);return this.executeTransactionBlock({transactionBlock:o,signature:s,...n})}async getTotalTransactionBlocks({signal:e}={}){let r=await this.transport.request({method:"sui_getTotalTransactionBlocks",params:[],signal:e});return BigInt(r)}async getReferenceGasPrice({signal:e}={}){let r=await this.transport.request({method:"suix_getReferenceGasPrice",params:[],signal:e});return BigInt(r)}async getStakes(e){if(!e.owner||!Fr($e(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getStakes",params:[e.owner],signal:e.signal})}async getStakesByIds(e){return e.stakedSuiIds.forEach(r=>{if(!r||!Fs(Ar(r)))throw new Error(`Invalid Sui Stake id ${r}`)}),await this.transport.request({method:"suix_getStakesByIds",params:[e.stakedSuiIds],signal:e.signal})}async getLatestSuiSystemState({signal:e}={}){return await this.transport.request({method:"suix_getLatestSuiSystemState",params:[],signal:e})}async queryEvents({query:e,cursor:r,limit:n,order:i,signal:s}){return e&&"MoveEventType"in e&&rn(e.MoveEventType)&&(e={...e,MoveEventType:(await this.core.mvr.resolveType({type:e.MoveEventType})).type}),e&&"MoveEventModule"in e&&$r(e.MoveEventModule.package)&&(e={...e,MoveEventModule:{module:e.MoveEventModule.module,package:(await this.core.mvr.resolvePackage({package:e.MoveEventModule.package})).package}}),"MoveModule"in e&&$r(e.MoveModule.package)&&(e={...e,MoveModule:{module:e.MoveModule.module,package:(await this.core.mvr.resolvePackage({package:e.MoveModule.package})).package}}),await this.transport.request({method:"suix_queryEvents",params:[e,r,n,(i||"descending")==="descending"],signal:s})}async subscribeEvent(e){return this.transport.subscribe({method:"suix_subscribeEvent",unsubscribe:"suix_unsubscribeEvent",params:[e.filter],onMessage:e.onMessage,signal:e.signal})}async subscribeTransaction(e){return this.transport.subscribe({method:"suix_subscribeTransaction",unsubscribe:"suix_unsubscribeTransaction",params:[e.filter],onMessage:e.onMessage,signal:e.signal})}async devInspectTransactionBlock(e){let r;if(Bl(e.transactionBlock))e.transactionBlock.setSenderIfNotSet(e.sender),r=Ht(await e.transactionBlock.build({client:this,onlyTransactionKind:!0}));else if(typeof e.transactionBlock=="string")r=e.transactionBlock;else if(e.transactionBlock instanceof Uint8Array)r=Ht(e.transactionBlock);else throw new Error("Unknown transaction block format.");return e.signal?.throwIfAborted(),await this.transport.request({method:"sui_devInspectTransactionBlock",params:[e.sender,r,e.gasPrice?.toString(),e.epoch],signal:e.signal})}async dryRunTransactionBlock(e){return await this.transport.request({method:"sui_dryRunTransactionBlock",params:[typeof e.transactionBlock=="string"?e.transactionBlock:Ht(e.transactionBlock)]})}async getDynamicFields(e){if(!e.parentId||!Fs(Ar(e.parentId)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"suix_getDynamicFields",params:[e.parentId,e.cursor,e.limit],signal:e.signal})}async getDynamicFieldObject(e){return await this.transport.request({method:"suix_getDynamicFieldObject",params:[e.parentId,e.name],signal:e.signal})}async getLatestCheckpointSequenceNumber({signal:e}={}){let r=await this.transport.request({method:"sui_getLatestCheckpointSequenceNumber",params:[],signal:e});return String(r)}async getCheckpoint(e){return await this.transport.request({method:"sui_getCheckpoint",params:[e.id],signal:e.signal})}async getCheckpoints(e){return await this.transport.request({method:"sui_getCheckpoints",params:[e.cursor,e?.limit,e.descendingOrder],signal:e.signal})}async getCommitteeInfo(e){return await this.transport.request({method:"suix_getCommitteeInfo",params:[e?.epoch],signal:e?.signal})}async getNetworkMetrics({signal:e}={}){return await this.transport.request({method:"suix_getNetworkMetrics",params:[],signal:e})}async getAddressMetrics({signal:e}={}){return await this.transport.request({method:"suix_getLatestAddressMetrics",params:[],signal:e})}async getEpochMetrics(e){return await this.transport.request({method:"suix_getEpochMetrics",params:[e?.cursor,e?.limit,e?.descendingOrder],signal:e?.signal})}async getAllEpochAddressMetrics(e){return await this.transport.request({method:"suix_getAllEpochAddressMetrics",params:[e?.descendingOrder],signal:e?.signal})}async getEpochs(e){return await this.transport.request({method:"suix_getEpochs",params:[e?.cursor,e?.limit,e?.descendingOrder],signal:e?.signal})}async getMoveCallMetrics({signal:e}={}){return await this.transport.request({method:"suix_getMoveCallMetrics",params:[],signal:e})}async getCurrentEpoch({signal:e}={}){return await this.transport.request({method:"suix_getCurrentEpoch",params:[],signal:e})}async getValidatorsApy({signal:e}={}){return await this.transport.request({method:"suix_getValidatorsApy",params:[],signal:e})}async getChainIdentifier({signal:e}={}){let r=await this.getCheckpoint({id:"0",signal:e}),n=yn(r.digest);return Qr(n.slice(0,4))}async resolveNameServiceAddress(e){return await this.transport.request({method:"suix_resolveNameServiceAddress",params:[e.name],signal:e.signal})}async resolveNameServiceNames({format:e="dot",...r}){let{nextCursor:n,hasNextPage:i,data:s}=await this.transport.request({method:"suix_resolveNameServiceNames",params:[r.address,r.cursor,r.limit],signal:r.signal});return{hasNextPage:i,nextCursor:n,data:s.map(o=>V_(o,e))}}async getProtocolConfig(e){return await this.transport.request({method:"sui_getProtocolConfig",params:[e?.version],signal:e?.signal})}async verifyZkLoginSignature(e){return await this.transport.request({method:"sui_verifyZkLoginSignature",params:[e.bytes,e.signature,e.intentScope,e.author],signal:e.signal})}async waitForTransaction({signal:e,timeout:r=60*1e3,pollInterval:n=2*1e3,...i}){let s=AbortSignal.timeout(r),o=new Promise((u,c)=>{s.addEventListener("abort",()=>c(s.reason))});for(o.catch(()=>{});!s.aborted;){e?.throwIfAborted();try{return await this.getTransactionBlock(i)}catch{await Promise.race([new Promise(c=>setTimeout(c,n)),o])}}throw s.throwIfAborted(),new Error("Unexpected error while waiting for transaction block.")}experimental_asClientExtension(){return{name:"jsonRPC",register:()=>this}}};import{SdkWrapper as DG}from"@cetusprotocol/common-sdk";import{CACHE_TIME_24H as Ii,CACHE_TIME_5MIN as BG,CachedContent as RG,DETAILS_KEYS as $c,extractStructTagFromType as $y,fixCoinType as UG,getFutureTime as $I,getObjectFields as Sd,getObjectId as Fy,getObjectPreviousTransactionDigest as LG,getObjectType as $G,getPackagerConfigs as Oo,normalizeCoinType as FI}from"@cetusprotocol/common-sdk";import{BaseError as ZG}from"@cetusprotocol/common-sdk";import{asUintN as WI,FEE_RATE_DENOMINATOR as Od,getDeltaDownFromOutput as KI,getDeltaUpFromInput as XI,getNextSqrtPriceFromInput as dH,getNextSqrtPriceFromOutput as hH,MathUtil as ya,ZERO as Ti}from"@cetusprotocol/common-sdk";import{adjustForSlippage as mH,CLOCK_ADDRESS as Ed,CoinAssist as En,getPackagerConfigs as JI,MathUtil as cte,MAX_SQRT_PRICE as gH,MIN_SQRT_PRICE as yH,U64_MAX as _H,ZERO as vH}from"@cetusprotocol/common-sdk";import{asUintN as ZI,ClmmPoolUtil as kH,CLOCK_ADDRESS as YI,CoinAssist as An,getPackagerConfigs as OH,normalizeCoinType as Vy}from"@cetusprotocol/common-sdk";import{asIntN as va,buildNFT as SW,d as Fc,DETAILS_KEYS as Gd,extractStructTagFromType as Eu,getMoveObjectType as VT,getObjectDeletedResponse as kW,getObjectFields as h_,getObjectId as a_,getObjectNotExistsResponse as OW,getObjectOwner as EW,MathUtil as AW}from"@cetusprotocol/common-sdk";import{asUintN as fu,CACHE_TIME_24H as Id,ClmmPoolUtil as jW,CLOCK_ADDRESS as rT,CoinAssist as Td,createFullClient as NW,d as du,DETAILS_KEYS as Dt,extractStructTagFromType as hu,getObjectFields as DW,getObjectPreviousTransactionDigest as BW,getPackagerConfigs as Wy,isSortedSymbols as nT,TickMath as Ky,tickScore as RW,TickUtil as iT}from"@cetusprotocol/common-sdk";import{asIntN as sT,d as oT,extractStructTagFromType as UW,fixCoinType as aT,getObjectFields as Xy,getObjectType as LW}from"@cetusprotocol/common-sdk";import{asUintN as pu,ClmmPoolUtil as uT,CLOCK_ADDRESS as Pd,CoinAssist as Cd,d as rs,DETAILS_KEYS as Eo,extractStructTagFromType as qW,getObjectFields as cT,getPackagerConfigs as Cs,TickMath as mu,TickUtil as jd,createFullClient as VW,deriveDynamicFieldIdByType as zW}from"@cetusprotocol/common-sdk";import{CLOCK_ADDRESS as Jy,CoinAssist as Zy,DETAILS_KEYS as fT,getPackagerConfigs as Yy,MathUtil as HW,normalizeCoinType as Qy,ZERO as gu}from"@cetusprotocol/common-sdk";import{d as _u,DETAILS_KEYS as Ao,extractStructTagFromType as dT,TickMath as hT,U64_MAX as KW,ZERO as XW}from"@cetusprotocol/common-sdk";import{CLOCK_ADDRESS as ZW,CoinAssist as YW,DETAILS_KEYS as ga,getPackagerConfigs as e_}from"@cetusprotocol/common-sdk";import{FullRpcUrlMainnet as eK}from"@cetusprotocol/common-sdk";import{FullRpcUrlTestnet as rK}from"@cetusprotocol/common-sdk";import{MathUtil as Pte,TickMath as Cte}from"@cetusprotocol/common-sdk";var AG=Object.create,mT=Object.defineProperty,IG=Object.getOwnPropertyDescriptor,TG=Object.getOwnPropertyNames,xG=Object.getPrototypeOf,PG=Object.prototype.hasOwnProperty,CG=(t=>typeof xr<"u"?xr:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof xr<"u"?xr:e)[r]}):t)(function(t){if(typeof xr<"u")return xr.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),jG=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),NG=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of TG(e))!PG.call(t,i)&&i!==r&&mT(t,i,{get:()=>e[i],enumerable:!(n=IG(e,i))||n.enumerable});return t},Ds=(t,e,r)=>(r=t!=null?AG(xG(t)):{},NG(e||!t||!t.__esModule?mT(r,"default",{value:t,enumerable:!0}):r,t)),Bs=jG((t,e)=>{"use strict";(function(r,n){"use strict";function i(a,l){if(!a)throw new Error(l||"Assertion failed")}function s(a,l){a.super_=l;var h=function(){};h.prototype=l.prototype,a.prototype=new h,a.prototype.constructor=a}function o(a,l,h){if(o.isBN(a))return a;this.negative=0,this.words=null,this.length=0,this.red=null,a!==null&&((l==="le"||l==="be")&&(h=l,l=10),this._init(a||0,l||10,h||"be"))}typeof r=="object"?r.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=CG("buffer").Buffer}catch{}o.isBN=function(a){return a instanceof o?!0:a!==null&&typeof a=="object"&&a.constructor.wordSize===o.wordSize&&Array.isArray(a.words)},o.max=function(a,l){return a.cmp(l)>0?a:l},o.min=function(a,l){return a.cmp(l)<0?a:l},o.prototype._init=function(a,l,h){if(typeof a=="number")return this._initNumber(a,l,h);if(typeof a=="object")return this._initArray(a,l,h);l==="hex"&&(l=16),i(l===(l|0)&&l>=2&&l<=36),a=a.toString().replace(/\s+/g,"");var y=0;a[0]==="-"&&(y++,this.negative=1),y<a.length&&(l===16?this._parseHex(a,y,h):(this._parseBase(a,l,y),h==="le"&&this._initArray(this.toArray(),l,h)))},o.prototype._initNumber=function(a,l,h){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[a&67108863],this.length=1):a<4503599627370496?(this.words=[a&67108863,a/67108864&67108863],this.length=2):(i(a<9007199254740992),this.words=[a&67108863,a/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),l,h)},o.prototype._initArray=function(a,l,h){if(i(typeof a.length=="number"),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var v,M,w=0;if(h==="be")for(y=a.length-1,v=0;y>=0;y-=3)M=a[y]|a[y-1]<<8|a[y-2]<<16,this.words[v]|=M<<w&67108863,this.words[v+1]=M>>>26-w&67108863,w+=24,w>=26&&(w-=26,v++);else if(h==="le")for(y=0,v=0;y<a.length;y+=3)M=a[y]|a[y+1]<<8|a[y+2]<<16,this.words[v]|=M<<w&67108863,this.words[v+1]=M>>>26-w&67108863,w+=24,w>=26&&(w-=26,v++);return this._strip()};function c(a,l){var h=a.charCodeAt(l);if(h>=48&&h<=57)return h-48;if(h>=65&&h<=70)return h-55;if(h>=97&&h<=102)return h-87;i(!1,"Invalid character in "+a)}function d(a,l,h){var y=c(a,h);return h-1>=l&&(y|=c(a,h-1)<<4),y}o.prototype._parseHex=function(a,l,h){this.length=Math.ceil((a.length-l)/6),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var v=0,M=0,w;if(h==="be")for(y=a.length-1;y>=l;y-=2)w=d(a,l,y)<<v,this.words[M]|=w&67108863,v>=18?(v-=18,M+=1,this.words[M]|=w>>>26):v+=8;else{var g=a.length-l;for(y=g%2===0?l+1:l;y<a.length;y+=2)w=d(a,l,y)<<v,this.words[M]|=w&67108863,v>=18?(v-=18,M+=1,this.words[M]|=w>>>26):v+=8}this._strip()};function p(a,l,h,y){for(var v=0,M=0,w=Math.min(a.length,h),g=l;g<w;g++){var f=a.charCodeAt(g)-48;v*=y,f>=49?M=f-49+10:f>=17?M=f-17+10:M=f,i(f>=0&&M<y,"Invalid character"),v+=M}return v}o.prototype._parseBase=function(a,l,h){this.words=[0],this.length=1;for(var y=0,v=1;v<=67108863;v*=l)y++;y--,v=v/l|0;for(var M=a.length-h,w=M%y,g=Math.min(M,M-w)+h,f=0,S=h;S<g;S+=y)f=p(a,S,S+y,l),this.imuln(v),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(w!==0){var V=1;for(f=p(a,S,a.length,l),S=0;S<w;S++)V*=l;this.imuln(V),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this._strip()},o.prototype.copy=function(a){a.words=new Array(this.length);for(var l=0;l<this.length;l++)a.words[l]=this.words[l];a.length=this.length,a.negative=this.negative,a.red=this.red};function _(a,l){a.words=l.words,a.length=l.length,a.negative=l.negative,a.red=l.red}if(o.prototype._move=function(a){_(a,this)},o.prototype.clone=function(){var a=new o(null);return this.copy(a),a},o.prototype._expand=function(a){for(;this.length<a;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=b}catch{o.prototype.inspect=b}else o.prototype.inspect=b;function b(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var O=["","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"],T=[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],x=[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];o.prototype.toString=function(a,l){a=a||10,l=l|0||1;var h;if(a===16||a==="hex"){h="";for(var y=0,v=0,M=0;M<this.length;M++){var w=this.words[M],g=((w<<y|v)&16777215).toString(16);v=w>>>24-y&16777215,y+=2,y>=26&&(y-=26,M--),v!==0||M!==this.length-1?h=O[6-g.length]+g+h:h=g+h}for(v!==0&&(h=v.toString(16)+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(a===(a|0)&&a>=2&&a<=36){var f=T[a],S=x[a];h="";var V=this.clone();for(V.negative=0;!V.isZero();){var z=V.modrn(S).toString(a);V=V.idivn(S),V.isZero()?h=z+h:h=O[f-z.length]+z+h}for(this.isZero()&&(h="0"+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var a=this.words[0];return this.length===2?a+=this.words[1]*67108864:this.length===3&&this.words[2]===1?a+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-a:a},o.prototype.toJSON=function(){return this.toString(16,2)},u&&(o.prototype.toBuffer=function(a,l){return this.toArrayLike(u,a,l)}),o.prototype.toArray=function(a,l){return this.toArrayLike(Array,a,l)};var F=function(a,l){return a.allocUnsafe?a.allocUnsafe(l):new a(l)};o.prototype.toArrayLike=function(a,l,h){this._strip();var y=this.byteLength(),v=h||Math.max(1,y);i(y<=v,"byte array longer than desired length"),i(v>0,"Requested array length <= 0");var M=F(a,v),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](M,y),M},o.prototype._toArrayLikeLE=function(a,l){for(var h=0,y=0,v=0,M=0;v<this.length;v++){var w=this.words[v]<<M|y;a[h++]=w&255,h<a.length&&(a[h++]=w>>8&255),h<a.length&&(a[h++]=w>>16&255),M===6?(h<a.length&&(a[h++]=w>>24&255),y=0,M=0):(y=w>>>24,M+=2)}if(h<a.length)for(a[h++]=y;h<a.length;)a[h++]=0},o.prototype._toArrayLikeBE=function(a,l){for(var h=a.length-1,y=0,v=0,M=0;v<this.length;v++){var w=this.words[v]<<M|y;a[h--]=w&255,h>=0&&(a[h--]=w>>8&255),h>=0&&(a[h--]=w>>16&255),M===6?(h>=0&&(a[h--]=w>>24&255),y=0,M=0):(y=w>>>24,M+=2)}if(h>=0)for(a[h--]=y;h>=0;)a[h--]=0},Math.clz32?o.prototype._countBits=function(a){return 32-Math.clz32(a)}:o.prototype._countBits=function(a){var l=a,h=0;return l>=4096&&(h+=13,l>>>=13),l>=64&&(h+=7,l>>>=7),l>=8&&(h+=4,l>>>=4),l>=2&&(h+=2,l>>>=2),h+l},o.prototype._zeroBits=function(a){if(a===0)return 26;var l=a,h=0;return(l&8191)===0&&(h+=13,l>>>=13),(l&127)===0&&(h+=7,l>>>=7),(l&15)===0&&(h+=4,l>>>=4),(l&3)===0&&(h+=2,l>>>=2),(l&1)===0&&h++,h},o.prototype.bitLength=function(){var a=this.words[this.length-1],l=this._countBits(a);return(this.length-1)*26+l};function R(a){for(var l=new Array(a.bitLength()),h=0;h<l.length;h++){var y=h/26|0,v=h%26;l[h]=a.words[y]>>>v&1}return l}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,l=0;l<this.length;l++){var h=this._zeroBits(this.words[l]);if(a+=h,h!==26)break}return a},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(a){return this.negative!==0?this.abs().inotn(a).iaddn(1):this.clone()},o.prototype.fromTwos=function(a){return this.testn(a-1)?this.notn(a).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(a){for(;this.length<a.length;)this.words[this.length++]=0;for(var l=0;l<a.length;l++)this.words[l]=this.words[l]|a.words[l];return this._strip()},o.prototype.ior=function(a){return i((this.negative|a.negative)===0),this.iuor(a)},o.prototype.or=function(a){return this.length>a.length?this.clone().ior(a):a.clone().ior(this)},o.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},o.prototype.iuand=function(a){var l;this.length>a.length?l=a:l=this;for(var h=0;h<l.length;h++)this.words[h]=this.words[h]&a.words[h];return this.length=l.length,this._strip()},o.prototype.iand=function(a){return i((this.negative|a.negative)===0),this.iuand(a)},o.prototype.and=function(a){return this.length>a.length?this.clone().iand(a):a.clone().iand(this)},o.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},o.prototype.iuxor=function(a){var l,h;this.length>a.length?(l=this,h=a):(l=a,h=this);for(var y=0;y<h.length;y++)this.words[y]=l.words[y]^h.words[y];if(this!==l)for(;y<l.length;y++)this.words[y]=l.words[y];return this.length=l.length,this._strip()},o.prototype.ixor=function(a){return i((this.negative|a.negative)===0),this.iuxor(a)},o.prototype.xor=function(a){return this.length>a.length?this.clone().ixor(a):a.clone().ixor(this)},o.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},o.prototype.inotn=function(a){i(typeof a=="number"&&a>=0);var l=Math.ceil(a/26)|0,h=a%26;this._expand(l),h>0&&l--;for(var y=0;y<l;y++)this.words[y]=~this.words[y]&67108863;return h>0&&(this.words[y]=~this.words[y]&67108863>>26-h),this._strip()},o.prototype.notn=function(a){return this.clone().inotn(a)},o.prototype.setn=function(a,l){i(typeof a=="number"&&a>=0);var h=a/26|0,y=a%26;return this._expand(h+1),l?this.words[h]=this.words[h]|1<<y:this.words[h]=this.words[h]&~(1<<y),this._strip()},o.prototype.iadd=function(a){var l;if(this.negative!==0&&a.negative===0)return this.negative=0,l=this.isub(a),this.negative^=1,this._normSign();if(this.negative===0&&a.negative!==0)return a.negative=0,l=this.isub(a),a.negative=1,l._normSign();var h,y;this.length>a.length?(h=this,y=a):(h=a,y=this);for(var v=0,M=0;M<y.length;M++)l=(h.words[M]|0)+(y.words[M]|0)+v,this.words[M]=l&67108863,v=l>>>26;for(;v!==0&&M<h.length;M++)l=(h.words[M]|0)+v,this.words[M]=l&67108863,v=l>>>26;if(this.length=h.length,v!==0)this.words[this.length]=v,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];return this},o.prototype.add=function(a){var l;return a.negative!==0&&this.negative===0?(a.negative=0,l=this.sub(a),a.negative^=1,l):a.negative===0&&this.negative!==0?(this.negative=0,l=a.sub(this),this.negative=1,l):this.length>a.length?this.clone().iadd(a):a.clone().iadd(this)},o.prototype.isub=function(a){if(a.negative!==0){a.negative=0;var l=this.iadd(a);return a.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var h=this.cmp(a);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var y,v;h>0?(y=this,v=a):(y=a,v=this);for(var M=0,w=0;w<v.length;w++)l=(y.words[w]|0)-(v.words[w]|0)+M,M=l>>26,this.words[w]=l&67108863;for(;M!==0&&w<y.length;w++)l=(y.words[w]|0)+M,M=l>>26,this.words[w]=l&67108863;if(M===0&&w<y.length&&y!==this)for(;w<y.length;w++)this.words[w]=y.words[w];return this.length=Math.max(this.length,w),y!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(a){return this.clone().isub(a)};function H(a,l,h){h.negative=l.negative^a.negative;var y=a.length+l.length|0;h.length=y,y=y-1|0;var v=a.words[0]|0,M=l.words[0]|0,w=v*M,g=w&67108863,f=w/67108864|0;h.words[0]=g;for(var S=1;S<y;S++){for(var V=f>>>26,z=f&67108863,Z=Math.min(S,l.length-1),ce=Math.max(0,S-a.length+1);ce<=Z;ce++){var E=S-ce|0;v=a.words[E]|0,M=l.words[ce]|0,w=v*M+z,V+=w/67108864|0,z=w&67108863}h.words[S]=z|0,f=V|0}return f!==0?h.words[S]=f|0:h.length--,h._strip()}var J=function(a,l,h){var y=a.words,v=l.words,M=h.words,w=0,g,f,S,V=y[0]|0,z=V&8191,Z=V>>>13,ce=y[1]|0,E=ce&8191,P=ce>>>13,j=y[2]|0,L=j&8191,U=j>>>13,W=y[3]|0,q=W&8191,$=W>>>13,X=y[4]|0,G=X&8191,K=X>>>13,ie=y[5]|0,oe=ie&8191,pe=ie>>>13,Fe=y[6]|0,_e=Fe&8191,Ie=Fe>>>13,Le=y[7]|0,me=Le&8191,Ue=Le>>>13,It=y[8]|0,Ee=It&8191,tt=It>>>13,kt=y[9]|0,Oe=kt&8191,Ve=kt>>>13,wt=v[0]|0,ve=wt&8191,lt=wt>>>13,Rt=v[1]|0,Te=Rt&8191,ft=Rt>>>13,Ut=v[2]|0,xe=Ut&8191,dt=Ut>>>13,Lt=v[3]|0,Pe=Lt&8191,ht=Lt>>>13,$t=v[4]|0,Ce=$t&8191,pt=$t>>>13,Ft=v[5]|0,je=Ft&8191,mt=Ft>>>13,qt=v[6]|0,Ne=qt&8191,gt=qt>>>13,Vt=v[7]|0,De=Vt&8191,yt=Vt>>>13,zt=v[8]|0,Be=zt&8191,_t=zt>>>13,Gt=v[9]|0,Re=Gt&8191,ct=Gt>>>13;h.negative=a.negative^l.negative,h.length=19,g=Math.imul(z,ve),f=Math.imul(z,lt),f=f+Math.imul(Z,ve)|0,S=Math.imul(Z,lt);var zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(zn>>>26)|0,zn&=67108863,g=Math.imul(E,ve),f=Math.imul(E,lt),f=f+Math.imul(P,ve)|0,S=Math.imul(P,lt),g=g+Math.imul(z,Te)|0,f=f+Math.imul(z,ft)|0,f=f+Math.imul(Z,Te)|0,S=S+Math.imul(Z,ft)|0;var Gn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Gn>>>26)|0,Gn&=67108863,g=Math.imul(L,ve),f=Math.imul(L,lt),f=f+Math.imul(U,ve)|0,S=Math.imul(U,lt),g=g+Math.imul(E,Te)|0,f=f+Math.imul(E,ft)|0,f=f+Math.imul(P,Te)|0,S=S+Math.imul(P,ft)|0,g=g+Math.imul(z,xe)|0,f=f+Math.imul(z,dt)|0,f=f+Math.imul(Z,xe)|0,S=S+Math.imul(Z,dt)|0;var Hn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Hn>>>26)|0,Hn&=67108863,g=Math.imul(q,ve),f=Math.imul(q,lt),f=f+Math.imul($,ve)|0,S=Math.imul($,lt),g=g+Math.imul(L,Te)|0,f=f+Math.imul(L,ft)|0,f=f+Math.imul(U,Te)|0,S=S+Math.imul(U,ft)|0,g=g+Math.imul(E,xe)|0,f=f+Math.imul(E,dt)|0,f=f+Math.imul(P,xe)|0,S=S+Math.imul(P,dt)|0,g=g+Math.imul(z,Pe)|0,f=f+Math.imul(z,ht)|0,f=f+Math.imul(Z,Pe)|0,S=S+Math.imul(Z,ht)|0;var Wn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Wn>>>26)|0,Wn&=67108863,g=Math.imul(G,ve),f=Math.imul(G,lt),f=f+Math.imul(K,ve)|0,S=Math.imul(K,lt),g=g+Math.imul(q,Te)|0,f=f+Math.imul(q,ft)|0,f=f+Math.imul($,Te)|0,S=S+Math.imul($,ft)|0,g=g+Math.imul(L,xe)|0,f=f+Math.imul(L,dt)|0,f=f+Math.imul(U,xe)|0,S=S+Math.imul(U,dt)|0,g=g+Math.imul(E,Pe)|0,f=f+Math.imul(E,ht)|0,f=f+Math.imul(P,Pe)|0,S=S+Math.imul(P,ht)|0,g=g+Math.imul(z,Ce)|0,f=f+Math.imul(z,pt)|0,f=f+Math.imul(Z,Ce)|0,S=S+Math.imul(Z,pt)|0;var Kn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Kn>>>26)|0,Kn&=67108863,g=Math.imul(oe,ve),f=Math.imul(oe,lt),f=f+Math.imul(pe,ve)|0,S=Math.imul(pe,lt),g=g+Math.imul(G,Te)|0,f=f+Math.imul(G,ft)|0,f=f+Math.imul(K,Te)|0,S=S+Math.imul(K,ft)|0,g=g+Math.imul(q,xe)|0,f=f+Math.imul(q,dt)|0,f=f+Math.imul($,xe)|0,S=S+Math.imul($,dt)|0,g=g+Math.imul(L,Pe)|0,f=f+Math.imul(L,ht)|0,f=f+Math.imul(U,Pe)|0,S=S+Math.imul(U,ht)|0,g=g+Math.imul(E,Ce)|0,f=f+Math.imul(E,pt)|0,f=f+Math.imul(P,Ce)|0,S=S+Math.imul(P,pt)|0,g=g+Math.imul(z,je)|0,f=f+Math.imul(z,mt)|0,f=f+Math.imul(Z,je)|0,S=S+Math.imul(Z,mt)|0;var Xn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Xn>>>26)|0,Xn&=67108863,g=Math.imul(_e,ve),f=Math.imul(_e,lt),f=f+Math.imul(Ie,ve)|0,S=Math.imul(Ie,lt),g=g+Math.imul(oe,Te)|0,f=f+Math.imul(oe,ft)|0,f=f+Math.imul(pe,Te)|0,S=S+Math.imul(pe,ft)|0,g=g+Math.imul(G,xe)|0,f=f+Math.imul(G,dt)|0,f=f+Math.imul(K,xe)|0,S=S+Math.imul(K,dt)|0,g=g+Math.imul(q,Pe)|0,f=f+Math.imul(q,ht)|0,f=f+Math.imul($,Pe)|0,S=S+Math.imul($,ht)|0,g=g+Math.imul(L,Ce)|0,f=f+Math.imul(L,pt)|0,f=f+Math.imul(U,Ce)|0,S=S+Math.imul(U,pt)|0,g=g+Math.imul(E,je)|0,f=f+Math.imul(E,mt)|0,f=f+Math.imul(P,je)|0,S=S+Math.imul(P,mt)|0,g=g+Math.imul(z,Ne)|0,f=f+Math.imul(z,gt)|0,f=f+Math.imul(Z,Ne)|0,S=S+Math.imul(Z,gt)|0;var Jn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Jn>>>26)|0,Jn&=67108863,g=Math.imul(me,ve),f=Math.imul(me,lt),f=f+Math.imul(Ue,ve)|0,S=Math.imul(Ue,lt),g=g+Math.imul(_e,Te)|0,f=f+Math.imul(_e,ft)|0,f=f+Math.imul(Ie,Te)|0,S=S+Math.imul(Ie,ft)|0,g=g+Math.imul(oe,xe)|0,f=f+Math.imul(oe,dt)|0,f=f+Math.imul(pe,xe)|0,S=S+Math.imul(pe,dt)|0,g=g+Math.imul(G,Pe)|0,f=f+Math.imul(G,ht)|0,f=f+Math.imul(K,Pe)|0,S=S+Math.imul(K,ht)|0,g=g+Math.imul(q,Ce)|0,f=f+Math.imul(q,pt)|0,f=f+Math.imul($,Ce)|0,S=S+Math.imul($,pt)|0,g=g+Math.imul(L,je)|0,f=f+Math.imul(L,mt)|0,f=f+Math.imul(U,je)|0,S=S+Math.imul(U,mt)|0,g=g+Math.imul(E,Ne)|0,f=f+Math.imul(E,gt)|0,f=f+Math.imul(P,Ne)|0,S=S+Math.imul(P,gt)|0,g=g+Math.imul(z,De)|0,f=f+Math.imul(z,yt)|0,f=f+Math.imul(Z,De)|0,S=S+Math.imul(Z,yt)|0;var Zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,g=Math.imul(Ee,ve),f=Math.imul(Ee,lt),f=f+Math.imul(tt,ve)|0,S=Math.imul(tt,lt),g=g+Math.imul(me,Te)|0,f=f+Math.imul(me,ft)|0,f=f+Math.imul(Ue,Te)|0,S=S+Math.imul(Ue,ft)|0,g=g+Math.imul(_e,xe)|0,f=f+Math.imul(_e,dt)|0,f=f+Math.imul(Ie,xe)|0,S=S+Math.imul(Ie,dt)|0,g=g+Math.imul(oe,Pe)|0,f=f+Math.imul(oe,ht)|0,f=f+Math.imul(pe,Pe)|0,S=S+Math.imul(pe,ht)|0,g=g+Math.imul(G,Ce)|0,f=f+Math.imul(G,pt)|0,f=f+Math.imul(K,Ce)|0,S=S+Math.imul(K,pt)|0,g=g+Math.imul(q,je)|0,f=f+Math.imul(q,mt)|0,f=f+Math.imul($,je)|0,S=S+Math.imul($,mt)|0,g=g+Math.imul(L,Ne)|0,f=f+Math.imul(L,gt)|0,f=f+Math.imul(U,Ne)|0,S=S+Math.imul(U,gt)|0,g=g+Math.imul(E,De)|0,f=f+Math.imul(E,yt)|0,f=f+Math.imul(P,De)|0,S=S+Math.imul(P,yt)|0,g=g+Math.imul(z,Be)|0,f=f+Math.imul(z,_t)|0,f=f+Math.imul(Z,Be)|0,S=S+Math.imul(Z,_t)|0;var Yn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,g=Math.imul(Oe,ve),f=Math.imul(Oe,lt),f=f+Math.imul(Ve,ve)|0,S=Math.imul(Ve,lt),g=g+Math.imul(Ee,Te)|0,f=f+Math.imul(Ee,ft)|0,f=f+Math.imul(tt,Te)|0,S=S+Math.imul(tt,ft)|0,g=g+Math.imul(me,xe)|0,f=f+Math.imul(me,dt)|0,f=f+Math.imul(Ue,xe)|0,S=S+Math.imul(Ue,dt)|0,g=g+Math.imul(_e,Pe)|0,f=f+Math.imul(_e,ht)|0,f=f+Math.imul(Ie,Pe)|0,S=S+Math.imul(Ie,ht)|0,g=g+Math.imul(oe,Ce)|0,f=f+Math.imul(oe,pt)|0,f=f+Math.imul(pe,Ce)|0,S=S+Math.imul(pe,pt)|0,g=g+Math.imul(G,je)|0,f=f+Math.imul(G,mt)|0,f=f+Math.imul(K,je)|0,S=S+Math.imul(K,mt)|0,g=g+Math.imul(q,Ne)|0,f=f+Math.imul(q,gt)|0,f=f+Math.imul($,Ne)|0,S=S+Math.imul($,gt)|0,g=g+Math.imul(L,De)|0,f=f+Math.imul(L,yt)|0,f=f+Math.imul(U,De)|0,S=S+Math.imul(U,yt)|0,g=g+Math.imul(E,Be)|0,f=f+Math.imul(E,_t)|0,f=f+Math.imul(P,Be)|0,S=S+Math.imul(P,_t)|0,g=g+Math.imul(z,Re)|0,f=f+Math.imul(z,ct)|0,f=f+Math.imul(Z,Re)|0,S=S+Math.imul(Z,ct)|0;var Qn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,g=Math.imul(Oe,Te),f=Math.imul(Oe,ft),f=f+Math.imul(Ve,Te)|0,S=Math.imul(Ve,ft),g=g+Math.imul(Ee,xe)|0,f=f+Math.imul(Ee,dt)|0,f=f+Math.imul(tt,xe)|0,S=S+Math.imul(tt,dt)|0,g=g+Math.imul(me,Pe)|0,f=f+Math.imul(me,ht)|0,f=f+Math.imul(Ue,Pe)|0,S=S+Math.imul(Ue,ht)|0,g=g+Math.imul(_e,Ce)|0,f=f+Math.imul(_e,pt)|0,f=f+Math.imul(Ie,Ce)|0,S=S+Math.imul(Ie,pt)|0,g=g+Math.imul(oe,je)|0,f=f+Math.imul(oe,mt)|0,f=f+Math.imul(pe,je)|0,S=S+Math.imul(pe,mt)|0,g=g+Math.imul(G,Ne)|0,f=f+Math.imul(G,gt)|0,f=f+Math.imul(K,Ne)|0,S=S+Math.imul(K,gt)|0,g=g+Math.imul(q,De)|0,f=f+Math.imul(q,yt)|0,f=f+Math.imul($,De)|0,S=S+Math.imul($,yt)|0,g=g+Math.imul(L,Be)|0,f=f+Math.imul(L,_t)|0,f=f+Math.imul(U,Be)|0,S=S+Math.imul(U,_t)|0,g=g+Math.imul(E,Re)|0,f=f+Math.imul(E,ct)|0,f=f+Math.imul(P,Re)|0,S=S+Math.imul(P,ct)|0;var ei=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,g=Math.imul(Oe,xe),f=Math.imul(Oe,dt),f=f+Math.imul(Ve,xe)|0,S=Math.imul(Ve,dt),g=g+Math.imul(Ee,Pe)|0,f=f+Math.imul(Ee,ht)|0,f=f+Math.imul(tt,Pe)|0,S=S+Math.imul(tt,ht)|0,g=g+Math.imul(me,Ce)|0,f=f+Math.imul(me,pt)|0,f=f+Math.imul(Ue,Ce)|0,S=S+Math.imul(Ue,pt)|0,g=g+Math.imul(_e,je)|0,f=f+Math.imul(_e,mt)|0,f=f+Math.imul(Ie,je)|0,S=S+Math.imul(Ie,mt)|0,g=g+Math.imul(oe,Ne)|0,f=f+Math.imul(oe,gt)|0,f=f+Math.imul(pe,Ne)|0,S=S+Math.imul(pe,gt)|0,g=g+Math.imul(G,De)|0,f=f+Math.imul(G,yt)|0,f=f+Math.imul(K,De)|0,S=S+Math.imul(K,yt)|0,g=g+Math.imul(q,Be)|0,f=f+Math.imul(q,_t)|0,f=f+Math.imul($,Be)|0,S=S+Math.imul($,_t)|0,g=g+Math.imul(L,Re)|0,f=f+Math.imul(L,ct)|0,f=f+Math.imul(U,Re)|0,S=S+Math.imul(U,ct)|0;var ti=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,g=Math.imul(Oe,Pe),f=Math.imul(Oe,ht),f=f+Math.imul(Ve,Pe)|0,S=Math.imul(Ve,ht),g=g+Math.imul(Ee,Ce)|0,f=f+Math.imul(Ee,pt)|0,f=f+Math.imul(tt,Ce)|0,S=S+Math.imul(tt,pt)|0,g=g+Math.imul(me,je)|0,f=f+Math.imul(me,mt)|0,f=f+Math.imul(Ue,je)|0,S=S+Math.imul(Ue,mt)|0,g=g+Math.imul(_e,Ne)|0,f=f+Math.imul(_e,gt)|0,f=f+Math.imul(Ie,Ne)|0,S=S+Math.imul(Ie,gt)|0,g=g+Math.imul(oe,De)|0,f=f+Math.imul(oe,yt)|0,f=f+Math.imul(pe,De)|0,S=S+Math.imul(pe,yt)|0,g=g+Math.imul(G,Be)|0,f=f+Math.imul(G,_t)|0,f=f+Math.imul(K,Be)|0,S=S+Math.imul(K,_t)|0,g=g+Math.imul(q,Re)|0,f=f+Math.imul(q,ct)|0,f=f+Math.imul($,Re)|0,S=S+Math.imul($,ct)|0;var ri=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(Oe,Ce),f=Math.imul(Oe,pt),f=f+Math.imul(Ve,Ce)|0,S=Math.imul(Ve,pt),g=g+Math.imul(Ee,je)|0,f=f+Math.imul(Ee,mt)|0,f=f+Math.imul(tt,je)|0,S=S+Math.imul(tt,mt)|0,g=g+Math.imul(me,Ne)|0,f=f+Math.imul(me,gt)|0,f=f+Math.imul(Ue,Ne)|0,S=S+Math.imul(Ue,gt)|0,g=g+Math.imul(_e,De)|0,f=f+Math.imul(_e,yt)|0,f=f+Math.imul(Ie,De)|0,S=S+Math.imul(Ie,yt)|0,g=g+Math.imul(oe,Be)|0,f=f+Math.imul(oe,_t)|0,f=f+Math.imul(pe,Be)|0,S=S+Math.imul(pe,_t)|0,g=g+Math.imul(G,Re)|0,f=f+Math.imul(G,ct)|0,f=f+Math.imul(K,Re)|0,S=S+Math.imul(K,ct)|0;var ni=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(Oe,je),f=Math.imul(Oe,mt),f=f+Math.imul(Ve,je)|0,S=Math.imul(Ve,mt),g=g+Math.imul(Ee,Ne)|0,f=f+Math.imul(Ee,gt)|0,f=f+Math.imul(tt,Ne)|0,S=S+Math.imul(tt,gt)|0,g=g+Math.imul(me,De)|0,f=f+Math.imul(me,yt)|0,f=f+Math.imul(Ue,De)|0,S=S+Math.imul(Ue,yt)|0,g=g+Math.imul(_e,Be)|0,f=f+Math.imul(_e,_t)|0,f=f+Math.imul(Ie,Be)|0,S=S+Math.imul(Ie,_t)|0,g=g+Math.imul(oe,Re)|0,f=f+Math.imul(oe,ct)|0,f=f+Math.imul(pe,Re)|0,S=S+Math.imul(pe,ct)|0;var ii=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,g=Math.imul(Oe,Ne),f=Math.imul(Oe,gt),f=f+Math.imul(Ve,Ne)|0,S=Math.imul(Ve,gt),g=g+Math.imul(Ee,De)|0,f=f+Math.imul(Ee,yt)|0,f=f+Math.imul(tt,De)|0,S=S+Math.imul(tt,yt)|0,g=g+Math.imul(me,Be)|0,f=f+Math.imul(me,_t)|0,f=f+Math.imul(Ue,Be)|0,S=S+Math.imul(Ue,_t)|0,g=g+Math.imul(_e,Re)|0,f=f+Math.imul(_e,ct)|0,f=f+Math.imul(Ie,Re)|0,S=S+Math.imul(Ie,ct)|0;var si=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(Oe,De),f=Math.imul(Oe,yt),f=f+Math.imul(Ve,De)|0,S=Math.imul(Ve,yt),g=g+Math.imul(Ee,Be)|0,f=f+Math.imul(Ee,_t)|0,f=f+Math.imul(tt,Be)|0,S=S+Math.imul(tt,_t)|0,g=g+Math.imul(me,Re)|0,f=f+Math.imul(me,ct)|0,f=f+Math.imul(Ue,Re)|0,S=S+Math.imul(Ue,ct)|0;var oi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(Oe,Be),f=Math.imul(Oe,_t),f=f+Math.imul(Ve,Be)|0,S=Math.imul(Ve,_t),g=g+Math.imul(Ee,Re)|0,f=f+Math.imul(Ee,ct)|0,f=f+Math.imul(tt,Re)|0,S=S+Math.imul(tt,ct)|0;var ai=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(Oe,Re),f=Math.imul(Oe,ct),f=f+Math.imul(Ve,Re)|0,S=Math.imul(Ve,ct);var jo=(w+g|0)+((f&8191)<<13)|0;return w=(S+(f>>>13)|0)+(jo>>>26)|0,jo&=67108863,M[0]=zn,M[1]=Gn,M[2]=Hn,M[3]=Wn,M[4]=Kn,M[5]=Xn,M[6]=Jn,M[7]=Zn,M[8]=Yn,M[9]=Qn,M[10]=ei,M[11]=ti,M[12]=ri,M[13]=ni,M[14]=ii,M[15]=si,M[16]=oi,M[17]=ai,M[18]=jo,w!==0&&(M[19]=w,h.length++),h};Math.imul||(J=H);function ee(a,l,h){h.negative=l.negative^a.negative,h.length=a.length+l.length;for(var y=0,v=0,M=0;M<h.length-1;M++){var w=v;v=0;for(var g=y&67108863,f=Math.min(M,l.length-1),S=Math.max(0,M-a.length+1);S<=f;S++){var V=M-S,z=a.words[V]|0,Z=l.words[S]|0,ce=z*Z,E=ce&67108863;w=w+(ce/67108864|0)|0,E=E+g|0,g=E&67108863,w=w+(E>>>26)|0,v+=w>>>26,w&=67108863}h.words[M]=g,y=w,w=v}return y!==0?h.words[M]=y:h.length--,h._strip()}function ae(a,l,h){return ee(a,l,h)}o.prototype.mulTo=function(a,l){var h,y=this.length+a.length;return this.length===10&&a.length===10?h=J(this,a,l):y<63?h=H(this,a,l):y<1024?h=ee(this,a,l):h=ae(this,a,l),h};function te(a,l){this.x=a,this.y=l}te.prototype.makeRBT=function(a){for(var l=new Array(a),h=o.prototype._countBits(a)-1,y=0;y<a;y++)l[y]=this.revBin(y,h,a);return l},te.prototype.revBin=function(a,l,h){if(a===0||a===h-1)return a;for(var y=0,v=0;v<l;v++)y|=(a&1)<<l-v-1,a>>=1;return y},te.prototype.permute=function(a,l,h,y,v,M){for(var w=0;w<M;w++)y[w]=l[a[w]],v[w]=h[a[w]]},te.prototype.transform=function(a,l,h,y,v,M){this.permute(M,a,l,h,y,v);for(var w=1;w<v;w<<=1)for(var g=w<<1,f=Math.cos(2*Math.PI/g),S=Math.sin(2*Math.PI/g),V=0;V<v;V+=g)for(var z=f,Z=S,ce=0;ce<w;ce++){var E=h[V+ce],P=y[V+ce],j=h[V+ce+w],L=y[V+ce+w],U=z*j-Z*L;L=z*L+Z*j,j=U,h[V+ce]=E+j,y[V+ce]=P+L,h[V+ce+w]=E-j,y[V+ce+w]=P-L,ce!==g&&(U=f*z-S*Z,Z=f*Z+S*z,z=U)}},te.prototype.guessLen13b=function(a,l){var h=Math.max(l,a)|1,y=h&1,v=0;for(h=h/2|0;h;h=h>>>1)v++;return 1<<v+1+y},te.prototype.conjugate=function(a,l,h){if(!(h<=1))for(var y=0;y<h/2;y++){var v=a[y];a[y]=a[h-y-1],a[h-y-1]=v,v=l[y],l[y]=-l[h-y-1],l[h-y-1]=-v}},te.prototype.normalize13b=function(a,l){for(var h=0,y=0;y<l/2;y++){var v=Math.round(a[2*y+1]/l)*8192+Math.round(a[2*y]/l)+h;a[y]=v&67108863,v<67108864?h=0:h=v/67108864|0}return a},te.prototype.convert13b=function(a,l,h,y){for(var v=0,M=0;M<l;M++)v=v+(a[M]|0),h[2*M]=v&8191,v=v>>>13,h[2*M+1]=v&8191,v=v>>>13;for(M=2*l;M<y;++M)h[M]=0;i(v===0),i((v&-8192)===0)},te.prototype.stub=function(a){for(var l=new Array(a),h=0;h<a;h++)l[h]=0;return l},te.prototype.mulp=function(a,l,h){var y=2*this.guessLen13b(a.length,l.length),v=this.makeRBT(y),M=this.stub(y),w=new Array(y),g=new Array(y),f=new Array(y),S=new Array(y),V=new Array(y),z=new Array(y),Z=h.words;Z.length=y,this.convert13b(a.words,a.length,w,y),this.convert13b(l.words,l.length,S,y),this.transform(w,M,g,f,y,v),this.transform(S,M,V,z,y,v);for(var ce=0;ce<y;ce++){var E=g[ce]*V[ce]-f[ce]*z[ce];f[ce]=g[ce]*z[ce]+f[ce]*V[ce],g[ce]=E}return this.conjugate(g,f,y),this.transform(g,f,Z,M,y,v),this.conjugate(Z,M,y),this.normalize13b(Z,y),h.negative=a.negative^l.negative,h.length=a.length+l.length,h._strip()},o.prototype.mul=function(a){var l=new o(null);return l.words=new Array(this.length+a.length),this.mulTo(a,l)},o.prototype.mulf=function(a){var l=new o(null);return l.words=new Array(this.length+a.length),ae(this,a,l)},o.prototype.imul=function(a){return this.clone().mulTo(a,this)},o.prototype.imuln=function(a){var l=a<0;l&&(a=-a),i(typeof a=="number"),i(a<67108864);for(var h=0,y=0;y<this.length;y++){var v=(this.words[y]|0)*a,M=(v&67108863)+(h&67108863);h>>=26,h+=v/67108864|0,h+=M>>>26,this.words[y]=M&67108863}return h!==0&&(this.words[y]=h,this.length++),this.length=a===0?1:this.length,l?this.ineg():this},o.prototype.muln=function(a){return this.clone().imuln(a)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(a){var l=R(a);if(l.length===0)return new o(1);for(var h=this,y=0;y<l.length&&l[y]===0;y++,h=h.sqr());if(++y<l.length)for(var v=h.sqr();y<l.length;y++,v=v.sqr())l[y]!==0&&(h=h.mul(v));return h},o.prototype.iushln=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26,y=67108863>>>26-l<<26-l,v;if(l!==0){var M=0;for(v=0;v<this.length;v++){var w=this.words[v]&y,g=(this.words[v]|0)-w<<l;this.words[v]=g|M,M=w>>>26-l}M&&(this.words[v]=M,this.length++)}if(h!==0){for(v=this.length-1;v>=0;v--)this.words[v+h]=this.words[v];for(v=0;v<h;v++)this.words[v]=0;this.length+=h}return this._strip()},o.prototype.ishln=function(a){return i(this.negative===0),this.iushln(a)},o.prototype.iushrn=function(a,l,h){i(typeof a=="number"&&a>=0);var y;l?y=(l-l%26)/26:y=0;var v=a%26,M=Math.min((a-v)/26,this.length),w=67108863^67108863>>>v<<v,g=h;if(y-=M,y=Math.max(0,y),g){for(var f=0;f<M;f++)g.words[f]=this.words[f];g.length=M}if(M!==0)if(this.length>M)for(this.length-=M,f=0;f<this.length;f++)this.words[f]=this.words[f+M];else this.words[0]=0,this.length=1;var S=0;for(f=this.length-1;f>=0&&(S!==0||f>=y);f--){var V=this.words[f]|0;this.words[f]=S<<26-v|V>>>v,S=V&w}return g&&S!==0&&(g.words[g.length++]=S),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(a,l,h){return i(this.negative===0),this.iushrn(a,l,h)},o.prototype.shln=function(a){return this.clone().ishln(a)},o.prototype.ushln=function(a){return this.clone().iushln(a)},o.prototype.shrn=function(a){return this.clone().ishrn(a)},o.prototype.ushrn=function(a){return this.clone().iushrn(a)},o.prototype.testn=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26,y=1<<l;if(this.length<=h)return!1;var v=this.words[h];return!!(v&y)},o.prototype.imaskn=function(a){i(typeof a=="number"&&a>=0);var l=a%26,h=(a-l)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(l!==0&&h++,this.length=Math.min(h,this.length),l!==0){var y=67108863^67108863>>>l<<l;this.words[this.length-1]&=y}return this._strip()},o.prototype.maskn=function(a){return this.clone().imaskn(a)},o.prototype.iaddn=function(a){return i(typeof a=="number"),i(a<67108864),a<0?this.isubn(-a):this.negative!==0?this.length===1&&(this.words[0]|0)<=a?(this.words[0]=a-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(a),this.negative=1,this):this._iaddn(a)},o.prototype._iaddn=function(a){this.words[0]+=a;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},o.prototype.isubn=function(a){if(i(typeof a=="number"),i(a<67108864),a<0)return this.iaddn(-a);if(this.negative!==0)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},o.prototype.addn=function(a){return this.clone().iaddn(a)},o.prototype.subn=function(a){return this.clone().isubn(a)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(a,l,h){var y=a.length+h,v;this._expand(y);var M,w=0;for(v=0;v<a.length;v++){M=(this.words[v+h]|0)+w;var g=(a.words[v]|0)*l;M-=g&67108863,w=(M>>26)-(g/67108864|0),this.words[v+h]=M&67108863}for(;v<this.length-h;v++)M=(this.words[v+h]|0)+w,w=M>>26,this.words[v+h]=M&67108863;if(w===0)return this._strip();for(i(w===-1),w=0,v=0;v<this.length;v++)M=-(this.words[v]|0)+w,w=M>>26,this.words[v]=M&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(a,l){var h=this.length-a.length,y=this.clone(),v=a,M=v.words[v.length-1]|0,w=this._countBits(M);h=26-w,h!==0&&(v=v.ushln(h),y.iushln(h),M=v.words[v.length-1]|0);var g=y.length-v.length,f;if(l!=="mod"){f=new o(null),f.length=g+1,f.words=new Array(f.length);for(var S=0;S<f.length;S++)f.words[S]=0}var V=y.clone()._ishlnsubmul(v,1,g);V.negative===0&&(y=V,f&&(f.words[g]=1));for(var z=g-1;z>=0;z--){var Z=(y.words[v.length+z]|0)*67108864+(y.words[v.length+z-1]|0);for(Z=Math.min(Z/M|0,67108863),y._ishlnsubmul(v,Z,z);y.negative!==0;)Z--,y.negative=0,y._ishlnsubmul(v,1,z),y.isZero()||(y.negative^=1);f&&(f.words[z]=Z)}return f&&f._strip(),y._strip(),l!=="div"&&h!==0&&y.iushrn(h),{div:f||null,mod:y}},o.prototype.divmod=function(a,l,h){if(i(!a.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var y,v,M;return this.negative!==0&&a.negative===0?(M=this.neg().divmod(a,l),l!=="mod"&&(y=M.div.neg()),l!=="div"&&(v=M.mod.neg(),h&&v.negative!==0&&v.iadd(a)),{div:y,mod:v}):this.negative===0&&a.negative!==0?(M=this.divmod(a.neg(),l),l!=="mod"&&(y=M.div.neg()),{div:y,mod:M.mod}):(this.negative&a.negative)!==0?(M=this.neg().divmod(a.neg(),l),l!=="div"&&(v=M.mod.neg(),h&&v.negative!==0&&v.isub(a)),{div:M.div,mod:v}):a.length>this.length||this.cmp(a)<0?{div:new o(0),mod:this}:a.length===1?l==="div"?{div:this.divn(a.words[0]),mod:null}:l==="mod"?{div:null,mod:new o(this.modrn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new o(this.modrn(a.words[0]))}:this._wordDiv(a,l)},o.prototype.div=function(a){return this.divmod(a,"div",!1).div},o.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},o.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},o.prototype.divRound=function(a){var l=this.divmod(a);if(l.mod.isZero())return l.div;var h=l.div.negative!==0?l.mod.isub(a):l.mod,y=a.ushrn(1),v=a.andln(1),M=h.cmp(y);return M<0||v===1&&M===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},o.prototype.modrn=function(a){var l=a<0;l&&(a=-a),i(a<=67108863);for(var h=(1<<26)%a,y=0,v=this.length-1;v>=0;v--)y=(h*y+(this.words[v]|0))%a;return l?-y:y},o.prototype.modn=function(a){return this.modrn(a)},o.prototype.idivn=function(a){var l=a<0;l&&(a=-a),i(a<=67108863);for(var h=0,y=this.length-1;y>=0;y--){var v=(this.words[y]|0)+h*67108864;this.words[y]=v/a|0,h=v%a}return this._strip(),l?this.ineg():this},o.prototype.divn=function(a){return this.clone().idivn(a)},o.prototype.egcd=function(a){i(a.negative===0),i(!a.isZero());var l=this,h=a.clone();l.negative!==0?l=l.umod(a):l=l.clone();for(var y=new o(1),v=new o(0),M=new o(0),w=new o(1),g=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++g;for(var f=h.clone(),S=l.clone();!l.isZero();){for(var V=0,z=1;(l.words[0]&z)===0&&V<26;++V,z<<=1);if(V>0)for(l.iushrn(V);V-- >0;)(y.isOdd()||v.isOdd())&&(y.iadd(f),v.isub(S)),y.iushrn(1),v.iushrn(1);for(var Z=0,ce=1;(h.words[0]&ce)===0&&Z<26;++Z,ce<<=1);if(Z>0)for(h.iushrn(Z);Z-- >0;)(M.isOdd()||w.isOdd())&&(M.iadd(f),w.isub(S)),M.iushrn(1),w.iushrn(1);l.cmp(h)>=0?(l.isub(h),y.isub(M),v.isub(w)):(h.isub(l),M.isub(y),w.isub(v))}return{a:M,b:w,gcd:h.iushln(g)}},o.prototype._invmp=function(a){i(a.negative===0),i(!a.isZero());var l=this,h=a.clone();l.negative!==0?l=l.umod(a):l=l.clone();for(var y=new o(1),v=new o(0),M=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var w=0,g=1;(l.words[0]&g)===0&&w<26;++w,g<<=1);if(w>0)for(l.iushrn(w);w-- >0;)y.isOdd()&&y.iadd(M),y.iushrn(1);for(var f=0,S=1;(h.words[0]&S)===0&&f<26;++f,S<<=1);if(f>0)for(h.iushrn(f);f-- >0;)v.isOdd()&&v.iadd(M),v.iushrn(1);l.cmp(h)>=0?(l.isub(h),y.isub(v)):(h.isub(l),v.isub(y))}var V;return l.cmpn(1)===0?V=y:V=v,V.cmpn(0)<0&&V.iadd(a),V},o.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var l=this.clone(),h=a.clone();l.negative=0,h.negative=0;for(var y=0;l.isEven()&&h.isEven();y++)l.iushrn(1),h.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;h.isEven();)h.iushrn(1);var v=l.cmp(h);if(v<0){var M=l;l=h,h=M}else if(v===0||h.cmpn(1)===0)break;l.isub(h)}while(!0);return h.iushln(y)},o.prototype.invm=function(a){return this.egcd(a).a.umod(a)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(a){return this.words[0]&a},o.prototype.bincn=function(a){i(typeof a=="number");var l=a%26,h=(a-l)/26,y=1<<l;if(this.length<=h)return this._expand(h+1),this.words[h]|=y,this;for(var v=y,M=h;v!==0&&M<this.length;M++){var w=this.words[M]|0;w+=v,v=w>>>26,w&=67108863,this.words[M]=w}return v!==0&&(this.words[M]=v,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(a){var l=a<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var h;if(this.length>1)h=1;else{l&&(a=-a),i(a<=67108863,"Number is too big");var y=this.words[0]|0;h=y===a?0:y<a?-1:1}return this.negative!==0?-h|0:h},o.prototype.cmp=function(a){if(this.negative!==0&&a.negative===0)return-1;if(this.negative===0&&a.negative!==0)return 1;var l=this.ucmp(a);return this.negative!==0?-l|0:l},o.prototype.ucmp=function(a){if(this.length>a.length)return 1;if(this.length<a.length)return-1;for(var l=0,h=this.length-1;h>=0;h--){var y=this.words[h]|0,v=a.words[h]|0;if(y!==v){y<v?l=-1:y>v&&(l=1);break}}return l},o.prototype.gtn=function(a){return this.cmpn(a)===1},o.prototype.gt=function(a){return this.cmp(a)===1},o.prototype.gten=function(a){return this.cmpn(a)>=0},o.prototype.gte=function(a){return this.cmp(a)>=0},o.prototype.ltn=function(a){return this.cmpn(a)===-1},o.prototype.lt=function(a){return this.cmp(a)===-1},o.prototype.lten=function(a){return this.cmpn(a)<=0},o.prototype.lte=function(a){return this.cmp(a)<=0},o.prototype.eqn=function(a){return this.cmpn(a)===0},o.prototype.eq=function(a){return this.cmp(a)===0},o.red=function(a){return new k(a)},o.prototype.toRed=function(a){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),a.convertTo(this)._forceRed(a)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(a){return this.red=a,this},o.prototype.forceRed=function(a){return i(!this.red,"Already a number in reduction context"),this._forceRed(a)},o.prototype.redAdd=function(a){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},o.prototype.redIAdd=function(a){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},o.prototype.redSub=function(a){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},o.prototype.redISub=function(a){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},o.prototype.redShl=function(a){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},o.prototype.redMul=function(a){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},o.prototype.redIMul=function(a){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(a){return i(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var he={k256:null,p224:null,p192:null,p25519:null};function A(a,l){this.name=a,this.p=new o(l,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}A.prototype._tmp=function(){var a=new o(null);return a.words=new Array(Math.ceil(this.n/13)),a},A.prototype.ireduce=function(a){var l=a,h;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),h=l.bitLength();while(h>this.n);var y=h<this.n?-1:l.ucmp(this.p);return y===0?(l.words[0]=0,l.length=1):y>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},A.prototype.split=function(a,l){a.iushrn(this.n,0,l)},A.prototype.imulK=function(a){return a.imul(this.k)};function I(){A.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(I,A),I.prototype.split=function(a,l){for(var h=4194303,y=Math.min(a.length,9),v=0;v<y;v++)l.words[v]=a.words[v];if(l.length=y,a.length<=9){a.words[0]=0,a.length=1;return}var M=a.words[9];for(l.words[l.length++]=M&h,v=10;v<a.length;v++){var w=a.words[v]|0;a.words[v-10]=(w&h)<<4|M>>>22,M=w}M>>>=22,a.words[v-10]=M,M===0&&a.length>10?a.length-=10:a.length-=9},I.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var l=0,h=0;h<a.length;h++){var y=a.words[h]|0;l+=y*977,a.words[h]=l&67108863,l=y*64+(l/67108864|0)}return a.words[a.length-1]===0&&(a.length--,a.words[a.length-1]===0&&a.length--),a};function C(){A.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(C,A);function D(){A.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(D,A);function N(){A.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(N,A),N.prototype.imulK=function(a){for(var l=0,h=0;h<a.length;h++){var y=(a.words[h]|0)*19+l,v=y&67108863;y>>>=26,a.words[h]=v,l=y}return l!==0&&(a.words[a.length++]=l),a},o._prime=function(a){if(he[a])return he[a];var l;if(a==="k256")l=new I;else if(a==="p224")l=new C;else if(a==="p192")l=new D;else if(a==="p25519")l=new N;else throw new Error("Unknown prime "+a);return he[a]=l,l};function k(a){if(typeof a=="string"){var l=o._prime(a);this.m=l.p,this.prime=l}else i(a.gtn(1),"modulus must be greater than 1"),this.m=a,this.prime=null}k.prototype._verify1=function(a){i(a.negative===0,"red works only with positives"),i(a.red,"red works only with red numbers")},k.prototype._verify2=function(a,l){i((a.negative|l.negative)===0,"red works only with positives"),i(a.red&&a.red===l.red,"red works only with red numbers")},k.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):(_(a,a.umod(this.m)._forceRed(this)),a)},k.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},k.prototype.add=function(a,l){this._verify2(a,l);var h=a.add(l);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},k.prototype.iadd=function(a,l){this._verify2(a,l);var h=a.iadd(l);return h.cmp(this.m)>=0&&h.isub(this.m),h},k.prototype.sub=function(a,l){this._verify2(a,l);var h=a.sub(l);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},k.prototype.isub=function(a,l){this._verify2(a,l);var h=a.isub(l);return h.cmpn(0)<0&&h.iadd(this.m),h},k.prototype.shl=function(a,l){return this._verify1(a),this.imod(a.ushln(l))},k.prototype.imul=function(a,l){return this._verify2(a,l),this.imod(a.imul(l))},k.prototype.mul=function(a,l){return this._verify2(a,l),this.imod(a.mul(l))},k.prototype.isqr=function(a){return this.imul(a,a.clone())},k.prototype.sqr=function(a){return this.mul(a,a)},k.prototype.sqrt=function(a){if(a.isZero())return a.clone();var l=this.m.andln(3);if(i(l%2===1),l===3){var h=this.m.add(new o(1)).iushrn(2);return this.pow(a,h)}for(var y=this.m.subn(1),v=0;!y.isZero()&&y.andln(1)===0;)v++,y.iushrn(1);i(!y.isZero());var M=new o(1).toRed(this),w=M.redNeg(),g=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new o(2*f*f).toRed(this);this.pow(f,g).cmp(w)!==0;)f.redIAdd(w);for(var S=this.pow(f,y),V=this.pow(a,y.addn(1).iushrn(1)),z=this.pow(a,y),Z=v;z.cmp(M)!==0;){for(var ce=z,E=0;ce.cmp(M)!==0;E++)ce=ce.redSqr();i(E<Z);var P=this.pow(S,new o(1).iushln(Z-E-1));V=V.redMul(P),S=P.redSqr(),z=z.redMul(S),Z=E}return V},k.prototype.invm=function(a){var l=a._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},k.prototype.pow=function(a,l){if(l.isZero())return new o(1).toRed(this);if(l.cmpn(1)===0)return a.clone();var h=4,y=new Array(1<<h);y[0]=new o(1).toRed(this),y[1]=a;for(var v=2;v<y.length;v++)y[v]=this.mul(y[v-1],a);var M=y[0],w=0,g=0,f=l.bitLength()%26;for(f===0&&(f=26),v=l.length-1;v>=0;v--){for(var S=l.words[v],V=f-1;V>=0;V--){var z=S>>V&1;if(M!==y[0]&&(M=this.sqr(M)),z===0&&w===0){g=0;continue}w<<=1,w|=z,g++,!(g!==h&&(v!==0||V!==0))&&(M=this.mul(M,y[w]),g=0,w=0)}f=26}return M},k.prototype.convertTo=function(a){var l=a.umod(this.m);return l===a?l.clone():l},k.prototype.convertFrom=function(a){var l=a.clone();return l.red=null,l},o.mont=function(a){return new m(a)};function m(a){k.call(this,a),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(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(m,k),m.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},m.prototype.convertFrom=function(a){var l=this.imod(a.mul(this.rinv));return l.red=null,l},m.prototype.imul=function(a,l){if(a.isZero()||l.isZero())return a.words[0]=0,a.length=1,a;var h=a.imul(l),y=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),v=h.isub(y).iushrn(this.shift),M=v;return v.cmp(this.m)>=0?M=v.isub(this.m):v.cmpn(0)<0&&(M=v.iadd(this.m)),M._forceRed(this)},m.prototype.mul=function(a,l){if(a.isZero()||l.isZero())return new o(0)._forceRed(this);var h=a.mul(l),y=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),v=h.isub(y).iushrn(this.shift),M=v;return v.cmp(this.m)>=0?M=v.isub(this.m):v.cmpn(0)<0&&(M=v.iadd(this.m)),M._forceRed(this)},m.prototype.invm=function(a){var l=this.imod(a._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof e>"u"||e,t)}),gT="3.7.8",FG=gT,Au=typeof Buffer=="function",qI=typeof TextDecoder=="function"?new TextDecoder:void 0,VI=typeof TextEncoder=="function"?new TextEncoder:void 0,qG="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",qc=Array.prototype.slice.call(qG),kd=(t=>{let e={};return t.forEach((r,n)=>e[r]=n),e})(qc),VG=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Ur=String.fromCharCode.bind(String),zI=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),yT=t=>t.replace(/=/g,"").replace(/[+\/]/g,e=>e=="+"?"-":"_"),_T=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),vT=t=>{let e,r,n,i,s="",o=t.length%3;for(let u=0;u<t.length;){if((r=t.charCodeAt(u++))>255||(n=t.charCodeAt(u++))>255||(i=t.charCodeAt(u++))>255)throw new TypeError("invalid character found");e=r<<16|n<<8|i,s+=qc[e>>18&63]+qc[e>>12&63]+qc[e>>6&63]+qc[e&63]}return o?s.slice(0,o-3)+"===".substring(o):s},l_=typeof btoa=="function"?t=>btoa(t):Au?t=>Buffer.from(t,"binary").toString("base64"):vT,t_=Au?t=>Buffer.from(t).toString("base64"):t=>{let e=[];for(let r=0,n=t.length;r<n;r+=4096)e.push(Ur.apply(null,t.subarray(r,r+4096)));return l_(e.join(""))},Nd=(t,e=!1)=>e?yT(t_(t)):t_(t),zG=t=>{if(t.length<2){var e=t.charCodeAt(0);return e<128?t:e<2048?Ur(192|e>>>6)+Ur(128|e&63):Ur(224|e>>>12&15)+Ur(128|e>>>6&63)+Ur(128|e&63)}else{var e=65536+(t.charCodeAt(0)-55296)*1024+(t.charCodeAt(1)-56320);return Ur(240|e>>>18&7)+Ur(128|e>>>12&63)+Ur(128|e>>>6&63)+Ur(128|e&63)}},GG=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,bT=t=>t.replace(GG,zG),GI=Au?t=>Buffer.from(t,"utf8").toString("base64"):VI?t=>t_(VI.encode(t)):t=>l_(bT(t)),wu=(t,e=!1)=>e?yT(GI(t)):GI(t),HI=t=>wu(t,!0),HG=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,WG=t=>{switch(t.length){case 4:var e=(7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3),r=e-65536;return Ur((r>>>10)+55296)+Ur((r&1023)+56320);case 3:return Ur((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return Ur((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},wT=t=>t.replace(HG,WG),MT=t=>{if(t=t.replace(/\s+/g,""),!VG.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(t.length&3));let e,r,n,i=[];for(let s=0;s<t.length;)e=kd[t.charAt(s++)]<<18|kd[t.charAt(s++)]<<12|(r=kd[t.charAt(s++)])<<6|(n=kd[t.charAt(s++)]),r===64?i.push(Ur(e>>16&255)):n===64?i.push(Ur(e>>16&255,e>>8&255)):i.push(Ur(e>>16&255,e>>8&255,e&255));return i.join("")},f_=typeof atob=="function"?t=>atob(_T(t)):Au?t=>Buffer.from(t,"base64").toString("binary"):MT,ST=Au?t=>zI(Buffer.from(t,"base64")):t=>zI(f_(t).split("").map(e=>e.charCodeAt(0))),kT=t=>ST(OT(t)),KG=Au?t=>Buffer.from(t,"base64").toString("utf8"):qI?t=>qI.decode(ST(t)):t=>wT(f_(t)),OT=t=>_T(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),r_=t=>KG(OT(t)),XG=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(e)||!/[^\s0-9a-zA-Z\-_]/.test(e)},ET=t=>({value:t,enumerable:!1,writable:!0,configurable:!0}),AT=function(){let t=(e,r)=>Object.defineProperty(String.prototype,e,ET(r));t("fromBase64",function(){return r_(this)}),t("toBase64",function(e){return wu(this,e)}),t("toBase64URI",function(){return wu(this,!0)}),t("toBase64URL",function(){return wu(this,!0)}),t("toUint8Array",function(){return kT(this)})},IT=function(){let t=(e,r)=>Object.defineProperty(Uint8Array.prototype,e,ET(r));t("toBase64",function(e){return Nd(this,e)}),t("toBase64URI",function(){return Nd(this,!0)}),t("toBase64URL",function(){return Nd(this,!0)})},JG=()=>{AT(),IT()},qy={version:gT,VERSION:FG,atob:f_,atobPolyfill:MT,btoa:l_,btoaPolyfill:vT,fromBase64:r_,toBase64:wu,encode:wu,encodeURI:HI,encodeURL:HI,utob:bT,btou:wT,decode:r_,isValid:XG,fromUint8Array:Nd,toUint8Array:kT,extendString:AT,extendUint8Array:IT,extendBuiltins:JG},YG=(t=>(t.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",t.ZeroTradableAmount="ZeroTradableAmount",t.AmountOutBelowMinimum="AmountOutBelowMinimum",t.AmountInAboveMaximum="AmountInAboveMaximum",t.NextTickNotFound="NextTickNotFound",t.TickArraySequenceInvalid="TickArraySequenceInvalid",t.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",t.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",t.ParamsLengthNotEqual="ParamsLengthNotEqual",t))(YG||{}),QG=(t=>(t.InvalidTickEvent="InvalidTickEvent",t.InvalidPositionObject="InvalidPositionObject",t.InvalidPositionRewardObject="InvalidPositionRewardObject",t.InvalidParams="InvalidParams",t.FetchError="FetchError",t))(QG||{}),eH=(t=>(t.InvalidCoinTypeSequence="InvalidCoinTypeSequence",t.InvalidTickIndex="InvalidTickIndex",t.InvalidPoolObject="InvalidPoolObject",t.InvalidTickObjectId="InvalidTickObjectId",t.InvalidTickObject="InvalidTickObject",t.InvalidTickFields="InvalidTickFields",t.PoolsNotFound="PoolsNotFound",t.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",t.FetchError="FetchError",t))(eH||{}),tH=(t=>(t.ClmmVestNotSet="ClmmVestNotSet",t.ClmmVestFetchError="ClmmVestFetchError",t))(tH||{}),rH=(t=>(t.NotFoundPartnerObject="NotFoundPartnerObject",t.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",t))(rH||{}),nH=(t=>(t.InvalidConfig="InvalidConfig",t.InvalidConfigHandle="InvalidConfigHandle",t.InvalidSimulateAccount="InvalidSimulateAccount",t))(nH||{}),iH=(t=>(t.InvalidSendAddress="InvalidSendAddress",t.InvalidRecipientAddress="InvalidRecipientAddress",t.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",t.InsufficientBalance="InsufficientBalance",t.InvalidTarget="InvalidTarget",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t))(iH||{}),sH=(t=>(t.InvalidCoin="InvalidCoin",t.NotFoundPath="NotFoundPath",t.NoDowngradeNeedParams="NoDowngradeNeedParams",t.InvalidSwapCountUrl="InvalidSwapCountUrl",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t.InvalidServerResponse="InvalidServerResponse",t))(sH||{}),oH=(t=>(t.InvalidType="InvalidType",t))(oH||{}),TT=class extends ZG{constructor(t,e,r){super(t,e||"UnknownError",r)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},Ns=(t,e,r)=>{throw new TT(e.message,t,r)},St=(t,e,r)=>{throw new TT(e,t,r)},aH=class{constructor(t){this._cache={},this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=Oo(this.sdk.sdkOptions.cetus_config),r=`${e}_getCoinConfigs`,n=this.getCache(r),i=n?[...n,...t]:t;this.updateCache(r,i)}async getTokenListByCoinTypes(t){let e={},{coin_list_handle:r}=Oo(this.sdk.sdkOptions.cetus_config),n=`${r}_getCoinConfigs`,i=this.getCache(n);if(i!==void 0){let o=i;for(let u of t)for(let c of o)if(FI(u)===FI(c.address)){e[u]=c;continue}}let s=t.filter(o=>e[o]===void 0);for(let o of s){let u=`${o}_metadata`,c=this.getCache(u);if(c!==void 0)e[o]=c;else{let d=await this._sdk.FullClient.getCoinMetadata({coinType:o});if(d){let p={id:d.id,pyth_id:"",name:d.name,symbol:d.symbol,official_symbol:d.symbol,coingecko_id:"",decimals:d.decimals,project_url:"",logo_url:d.iconUrl,address:o};e[o]=p,this.updateCache(u,p,Ii)}else console.log(`not found ${o}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:r}=Oo(this.sdk.sdkOptions.cetus_config),n=`${r}_getCoinConfigs`,i=this.getCache(n,t);if(i)return i;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(r)).data.map(c=>c.objectId),o=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),u=[];return o.forEach(c=>{(c.error!=null||c.data?.content?.dataType!=="moveObject")&&St("FetchError",`when getCoinConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[$c.METHOD_NAME]:"getCoinConfigs"});let d=this.buildCoinConfig(c,e);this.updateCache(`${r}_${d.address}_getCoinConfig`,d,Ii),u.push({...d})}),this.updateCache(n,u,Ii),u}async getCoinConfig(t,e=!1,r=!0){let{coin_list_handle:n}=Oo(this.sdk.sdkOptions.cetus_config),i=`${n}_${t}_getCoinConfig`,s=this.getCache(i,e);if(s)return s;let o=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"0x1::type_name::TypeName",value:{name:UG(t)}}});(o.error!=null||o.data?.content?.dataType!=="moveObject")&&St("FetchError",`when getCoinConfig get object error: ${o.error}, please check the rpc and contracts address config.`,{[$c.METHOD_NAME]:"getCoinConfig"});let u=this.buildCoinConfig(o,r);return this.updateCache(i,u,Ii),u}buildCoinConfig(t,e=!0){let r=Sd(t);r=r.value.fields;let n={...r};return n.id=Fy(t),n.address=$y(r.coin_type.fields.name).full_address,r.pyth_id&&(n.pyth_id=Ar(r.pyth_id)),this.transformExtensions(n,r.extension_fields.fields.contents,e),delete n.coin_type,n}async getClmmPoolConfigs(t=!1,e=!0){let{clmm_pools_handle:r}=Oo(this.sdk.sdkOptions.cetus_config),n=`${r}_getClmmPoolConfigs`,i=this.getCache(n,t);if(i)return i;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(r)).data.map(c=>c.objectId),o=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),u=[];return o.forEach(c=>{(c.error!=null||c.data?.content?.dataType!=="moveObject")&&St("FetchError",`when getClmmPoolsConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[$c.METHOD_NAME]:"getClmmPoolConfigs"});let d=this.buildClmmPoolConfig(c,e);this.updateCache(`${d.pool_address}_getClmmPoolConfig`,d,Ii),u.push({...d})}),this.updateCache(n,u,Ii),u}async getClmmPoolConfig(t,e=!1,r=!0){let{clmm_pools_handle:n}=Oo(this.sdk.sdkOptions.cetus_config),i=`${t}_getClmmPoolConfig`,s=this.getCache(i,e);if(s)return s;let o=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),u=this.buildClmmPoolConfig(o,r);return this.updateCache(i,u,Ii),u}buildClmmPoolConfig(t,e=!0){let r=Sd(t);r=r.value.fields;let n={...r};return n.id=Fy(t),n.pool_address=Ar(r.pool_address),this.transformExtensions(n,r.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:r}=Oo(this.sdk.sdkOptions.cetus_config),n=`${r}_getLaunchpadPoolConfigs`,i=this.getCache(n,t);if(i)return i;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(r)).data.map(c=>c.objectId),o=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),u=[];return o.forEach(c=>{(c.error!=null||c.data?.content?.dataType!=="moveObject")&&St("FetchError",`when getCoinConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[$c.METHOD_NAME]:"getLaunchpadPoolConfigs"});let d=this.buildLaunchpadPoolConfig(c,e);this.updateCache(`${d.pool_address}_getLaunchpadPoolConfig`,d,Ii),u.push({...d})}),this.updateCache(n,u,Ii),u}async getLaunchpadPoolConfig(t,e=!1,r=!0){let{launchpad_pools_handle:n}=Oo(this.sdk.sdkOptions.cetus_config),i=`${t}_getLaunchpadPoolConfig`,s=this.getCache(i,e);if(s)return s;let o=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),u=this.buildLaunchpadPoolConfig(o,r);return this.updateCache(i,u,Ii),u}buildLaunchpadPoolConfig(t,e=!0){let r=Sd(t);r=r.value.fields;let n={...r};n.id=Fy(t),n.pool_address=Ar(r.pool_address),this.transformExtensions(n,r.extension_fields.fields.contents,e);let i=[];r.social_media.fields.contents.forEach(s=>{i.push({name:s.fields.value.fields.name,link:s.fields.value.fields.link})}),n.social_media=i;try{n.regulation=decodeURIComponent(qy.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=qy.decode(n.regulation)}return n}transformExtensions(t,e,r=!0){let n=[];for(let i of e){let{key:s}=i.fields,{value:o}=i.fields;if(s==="labels")try{let u=decodeURIComponent(qy.decode(o));try{o=JSON.parse(u)}catch{o=u}}catch{}r&&(t[s]=o),n.push({key:s,value:o})}delete t.extension_fields,r||(t.extensions=n)}async getCetusConfig(t=!1){let e=this._sdk.sdkOptions.cetus_config.package_id,r=`${e}_getCetusConfig`,n=this.getCache(r,t);if(n!==void 0)return n;let i=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),s=LG(i),o=await this._sdk.FullClient.queryEventsByPage({Transaction:s}),u={coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"",global_config_id:"",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""};if(o.data.length>0)for(let c of o.data)switch($y(c.type).name){case"InitCoinListEvent":u.coin_list_id=c.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":u.launchpad_pools_id=c.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":u.clmm_pools_id=c.parsedJson.pools_id;break;case"InitConfigEvent":u.global_config_id=c.parsedJson.global_config_id,u.admin_cap_id=c.parsedJson.admin_cap_id;break;default:break}return u=await this.getCetusConfigHandle(u),u.clmm_pools_id.length>0&&this.updateCache(r,u,Ii),u}async getCetusConfigHandle(t){let e=[t.clmm_pools_id,t.coin_list_id,t.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:e,options:{showContent:!0}})).forEach(r=>{(r.error!=null||r.data?.content?.dataType!=="moveObject")&&St("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${r.error}, please check the rpc and contracts address config.`,{[$c.METHOD_NAME]:"getCetusConfigHandle"});let n=Sd(r),i=$G(r);switch($y(i).name){case"ClmmPools":t.clmm_pools_handle=n.pools.fields.id.id;break;case"CoinList":t.coin_list_handle=n.coins.fields.id.id;break;case"LaunchpadPools":t.launchpad_pools_handle=n.pools.fields.id.id;break;default:break}}),t}updateCache(t,e,r=BG){let n=this._cache[t];n?(n.overdue_time=$I(r),n.value=e):n=new RG(e,$I(r)),this._cache[t]=n}getCache(t,e=!1){try{let r=this._cache[t];if(!r)return;if(e||!r.isValid()){delete this._cache[t];return}return r.value}catch(r){console.error(`Error accessing cache for key ${t}:`,r);return}}},uH=Ds(Bs()),cH="position_liquidity_snapshot",lH=(t=>(t.Deleted="Deleted",t.Exists="Exists",t.NotExists="NotExists",t))(lH||{}),fH=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],ns=Ds(Bs()),pH=Ds(Bs()),bH="partner",Ad="pool_script",Mu="pool_script_v2",xT="pool_script_v3",PT="router",wH="router_with_partner",ku="fetcher_script";var MH="utils";var SH=Ds(Bs()),bu=9e15,Co=1e9,n_="0123456789abcdef",Ud="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ld="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",i_={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-bu,maxE:bu,crypto:!1},CT,js,ut=!0,qd="[DecimalError] ",Po=qd+"Invalid argument: ",jT=qd+"Precision limit exceeded",NT=qd+"crypto unavailable",DT="[object Decimal]",Yr=Math.floor,Or=Math.pow,EH=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,AH=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,IH=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,BT=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Pi=1e7,Qe=7,TH=9007199254740991,xH=Ud.length-1,s_=Ld.length-1,de={toStringTag:DT};de.absoluteValue=de.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),He(t)};de.ceil=function(){return He(new this.constructor(this),this.e+1,2)};de.clampedTo=de.clamp=function(t,e){var r,n=this,i=n.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(Po+e);return r=n.cmp(t),r<0?t:n.cmp(e)>0?e:new i(n)};de.comparedTo=de.cmp=function(t){var e,r,n,i,s=this,o=s.d,u=(t=new s.constructor(t)).d,c=s.s,d=t.s;if(!o||!u)return!c||!d?NaN:c!==d?c:o===u?0:!o^c<0?1:-1;if(!o[0]||!u[0])return o[0]?c:u[0]?-d:0;if(c!==d)return c;if(s.e!==t.e)return s.e>t.e^c<0?1:-1;for(n=o.length,i=u.length,e=0,r=n<i?n:i;e<r;++e)if(o[e]!==u[e])return o[e]>u[e]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};de.cosine=de.cos=function(){var t,e,r=this,n=r.constructor;return r.d?r.d[0]?(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=PH(n,FT(n,r)),n.precision=t,n.rounding=e,He(js==2||js==3?r.neg():r,t,e,!0)):new n(1):new n(NaN)};de.cubeRoot=de.cbrt=function(){var t,e,r,n,i,s,o,u,c,d,p=this,_=p.constructor;if(!p.isFinite()||p.isZero())return new _(p);for(ut=!1,s=p.s*Or(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Lr(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=Or(r,1/3),t=Yr((t+1)/3)-(t%3==(t<0?-1:2)),s==1/0?r="5e"+t:(r=s.toExponential(),r=r.slice(0,r.indexOf("e")+1)+t),n=new _(r),n.s=p.s):n=new _(s.toString()),o=(t=_.precision)+3;;)if(u=n,c=u.times(u).times(u),d=c.plus(p),n=Bt(d.plus(p).times(u),d.plus(c),o+2,1),Lr(u.d).slice(0,o)===(r=Lr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(He(u,t+1,0),u.times(u).times(u).eq(p))){n=u;break}o+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(He(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return ut=!0,He(n,t,_.rounding,e)};de.decimalPlaces=de.dp=function(){var t,e=this.d,r=NaN;if(e){if(t=e.length-1,r=(t-Yr(this.e/Qe))*Qe,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};de.dividedBy=de.div=function(t){return Bt(this,new this.constructor(t))};de.dividedToIntegerBy=de.divToInt=function(t){var e=this,r=e.constructor;return He(Bt(e,new r(t),0,1,1),r.precision,r.rounding)};de.equals=de.eq=function(t){return this.cmp(t)===0};de.floor=function(){return He(new this.constructor(this),this.e+1,3)};de.greaterThan=de.gt=function(t){return this.cmp(t)>0};de.greaterThanOrEqualTo=de.gte=function(t){var e=this.cmp(t);return e==1||e===0};de.hyperbolicCosine=de.cosh=function(){var t,e,r,n,i,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;r=o.precision,n=o.rounding,o.precision=r+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(t=Math.ceil(i/3),e=(1/zd(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=Ou(o,1,s.times(e),new o(1),!0);for(var c,d=t,p=new o(8);d--;)c=s.times(s),s=u.minus(c.times(p.minus(c.times(p))));return He(s,o.precision=r,o.rounding=n,!0)};de.hyperbolicSine=de.sinh=function(){var t,e,r,n,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(e=s.precision,r=s.rounding,s.precision=e+Math.max(i.e,i.sd())+4,s.rounding=1,n=i.d.length,n<3)i=Ou(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/zd(5,t)),i=Ou(s,2,i,i,!0);for(var o,u=new s(5),c=new s(16),d=new s(20);t--;)o=i.times(i),i=i.times(u.plus(o.times(c.times(o).plus(d))))}return s.precision=e,s.rounding=r,He(i,e,r,!0)};de.hyperbolicTangent=de.tanh=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+7,n.rounding=1,Bt(r.sinh(),r.cosh(),n.precision=t,n.rounding=e)):new n(r.s)};de.inverseCosine=de.acos=function(){var t=this,e=t.constructor,r=t.abs().cmp(1),n=e.precision,i=e.rounding;return r!==-1?r===0?t.isNeg()?is(e,n,i):new e(0):new e(NaN):t.isZero()?is(e,n+4,i).times(.5):(e.precision=n+6,e.rounding=1,t=new e(1).minus(t).div(t.plus(1)).sqrt().atan(),e.precision=n,e.rounding=i,t.times(2))};de.inverseHyperbolicCosine=de.acosh=function(){var t,e,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(t=n.precision,e=n.rounding,n.precision=t+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,ut=!1,r=r.times(r).minus(1).sqrt().plus(r),ut=!0,n.precision=t,n.rounding=e,r.ln()):new n(r)};de.inverseHyperbolicSine=de.asinh=function(){var t,e,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,ut=!1,r=r.times(r).plus(1).sqrt().plus(r),ut=!0,n.precision=t,n.rounding=e,r.ln())};de.inverseHyperbolicTangent=de.atanh=function(){var t,e,r,n,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=s.precision,e=s.rounding,n=i.sd(),Math.max(n,t)<2*-i.e-1?He(new s(i),t,e,!0):(s.precision=r=n-i.e,i=Bt(i.plus(1),new s(1).minus(i),r+t,1),s.precision=t+4,s.rounding=1,i=i.ln(),s.precision=t,s.rounding=e,i.times(.5))):new s(NaN)};de.inverseSine=de.asin=function(){var t,e,r,n,i=this,s=i.constructor;return i.isZero()?new s(i):(e=i.abs().cmp(1),r=s.precision,n=s.rounding,e!==-1?e===0?(t=is(s,r+4,n).times(.5),t.s=i.s,t):new s(NaN):(s.precision=r+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=n,i.times(2)))};de.inverseTangent=de.atan=function(){var t,e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding;if(d.isFinite()){if(d.isZero())return new p(d);if(d.abs().eq(1)&&_+4<=s_)return o=is(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=s_)return o=is(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/Qe+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(ut=!1,e=Math.ceil(u/Qe),n=1,c=d.times(d),o=new p(d),i=d;t!==-1;)if(i=i.times(c),s=o.minus(i.div(n+=2)),i=i.times(c),o=s.plus(i.div(n+=2)),o.d[e]!==void 0)for(t=e;o.d[t]===s.d[t]&&t--;);return r&&(o=o.times(2<<r-1)),ut=!0,He(o,p.precision=_,p.rounding=b,!0)};de.isFinite=function(){return!!this.d};de.isInteger=de.isInt=function(){return!!this.d&&Yr(this.e/Qe)>this.d.length-2};de.isNaN=function(){return!this.s};de.isNegative=de.isNeg=function(){return this.s<0};de.isPositive=de.isPos=function(){return this.s>0};de.isZero=function(){return!!this.d&&this.d[0]===0};de.lessThan=de.lt=function(t){return this.cmp(t)<0};de.lessThanOrEqualTo=de.lte=function(t){return this.cmp(t)<1};de.logarithm=de.log=function(t){var e,r,n,i,s,o,u,c,d=this,p=d.constructor,_=p.precision,b=p.rounding,O=5;if(t==null)t=new p(10),e=!0;else{if(t=new p(t),r=t.d,t.s<0||!r||!r[0]||t.eq(1))return new p(NaN);e=t.eq(10)}if(r=d.d,d.s<0||!r||!r[0]||d.eq(1))return new p(r&&!r[0]?-1/0:d.s!=1?NaN:r?0:1/0);if(e)if(r.length>1)s=!0;else{for(i=r[0];i%10===0;)i/=10;s=i!==1}if(ut=!1,u=_+O,o=xo(d,u),n=e?$d(p,u+10):xo(t,u),c=Bt(o,n,u,1),Vc(c.d,i=_,b))do if(u+=10,o=xo(d,u),n=e?$d(p,u+10):xo(t,u),c=Bt(o,n,u,1),!s){+Lr(c.d).slice(i+1,i+15)+1==1e14&&(c=He(c,_+1,0));break}while(Vc(c.d,i+=10,b));return ut=!0,He(c,_,b)};de.minus=de.sub=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.constructor;if(t=new T(t),!O.d||!t.d)return!O.s||!t.s?t=new T(NaN):O.d?t.s=-t.s:t=new T(t.d||O.s!==t.s?O:NaN),t;if(O.s!=t.s)return t.s=-t.s,O.plus(t);if(d=O.d,b=t.d,u=T.precision,c=T.rounding,!d[0]||!b[0]){if(b[0])t.s=-t.s;else if(d[0])t=new T(O);else return new T(c===3?-0:0);return ut?He(t,u,c):t}if(r=Yr(t.e/Qe),p=Yr(O.e/Qe),d=d.slice(),s=p-r,s){for(_=s<0,_?(e=d,s=-s,o=b.length):(e=b,r=p,o=d.length),n=Math.max(Math.ceil(u/Qe),o)+2,s>n&&(s=n,e.length=1),e.reverse(),n=s;n--;)e.push(0);e.reverse()}else{for(n=d.length,o=b.length,_=n<o,_&&(o=n),n=0;n<o;n++)if(d[n]!=b[n]){_=d[n]<b[n];break}s=0}for(_&&(e=d,d=b,b=e,t.s=-t.s),o=d.length,n=b.length-o;n>0;--n)d[o++]=0;for(n=b.length;n>s;){if(d[--n]<b[n]){for(i=n;i&&d[--i]===0;)d[i]=Pi-1;--d[i],d[n]+=Pi}d[n]-=b[n]}for(;d[--o]===0;)d.pop();for(;d[0]===0;d.shift())--r;return d[0]?(t.d=d,t.e=Vd(d,r),ut?He(t,u,c):t):new T(c===3?-0:0)};de.modulo=de.mod=function(t){var e,r=this,n=r.constructor;return t=new n(t),!r.d||!t.s||t.d&&!t.d[0]?new n(NaN):!t.d||r.d&&!r.d[0]?He(new n(r),n.precision,n.rounding):(ut=!1,n.modulo==9?(e=Bt(r,t.abs(),0,3,1),e.s*=t.s):e=Bt(r,t,0,n.modulo,1),e=e.times(t),ut=!0,r.minus(e))};de.naturalExponential=de.exp=function(){return o_(this)};de.naturalLogarithm=de.ln=function(){return xo(this)};de.negated=de.neg=function(){var t=new this.constructor(this);return t.s=-t.s,He(t)};de.plus=de.add=function(t){var e,r,n,i,s,o,u,c,d,p,_=this,b=_.constructor;if(t=new b(t),!_.d||!t.d)return!_.s||!t.s?t=new b(NaN):_.d||(t=new b(t.d||_.s===t.s?_:NaN)),t;if(_.s!=t.s)return t.s=-t.s,_.minus(t);if(d=_.d,p=t.d,u=b.precision,c=b.rounding,!d[0]||!p[0])return p[0]||(t=new b(_)),ut?He(t,u,c):t;if(s=Yr(_.e/Qe),n=Yr(t.e/Qe),d=d.slice(),i=s-n,i){for(i<0?(r=d,i=-i,o=p.length):(r=p,n=s,o=d.length),s=Math.ceil(u/Qe),o=s>o?s+1:o+1,i>o&&(i=o,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(o=d.length,i=p.length,o-i<0&&(i=o,r=p,p=d,d=r),e=0;i;)e=(d[--i]=d[i]+p[i]+e)/Pi|0,d[i]%=Pi;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=Vd(d,n),ut?He(t,u,c):t};de.precision=de.sd=function(t){var e,r=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Po+t);return r.d?(e=RT(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};de.round=function(){var t=this,e=t.constructor;return He(new e(t),t.e+1,e.rounding)};de.sine=de.sin=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=jH(n,FT(n,r)),n.precision=t,n.rounding=e,He(js>2?r.neg():r,t,e,!0)):new n(NaN)};de.squareRoot=de.sqrt=function(){var t,e,r,n,i,s,o=this,u=o.d,c=o.e,d=o.s,p=o.constructor;if(d!==1||!u||!u[0])return new p(!d||d<0&&(!u||u[0])?NaN:u?o:1/0);for(ut=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Lr(u),(e.length+c)%2==0&&(e+="0"),d=Math.sqrt(e),c=Yr((c+1)/2)-(c<0||c%2),d==1/0?e="5e"+c:(e=d.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),n=new p(e)):n=new p(d.toString()),r=(c=p.precision)+3;;)if(s=n,n=s.plus(Bt(o,s,r+2,1)).times(.5),Lr(s.d).slice(0,r)===(e=Lr(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(He(s,c+1,0),s.times(s).eq(o))){n=s;break}r+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(He(n,c+1,1),t=!n.times(n).eq(o));break}return ut=!0,He(n,c,p.rounding,t)};de.tangent=de.tan=function(){var t,e,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(t=n.precision,e=n.rounding,n.precision=t+10,n.rounding=1,r=r.sin(),r.s=1,r=Bt(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,He(js==2||js==4?r.neg():r,t,e,!0)):new n(NaN)};de.times=de.mul=function(t){var e,r,n,i,s,o,u,c,d,p=this,_=p.constructor,b=p.d,O=(t=new _(t)).d;if(t.s*=p.s,!b||!b[0]||!O||!O[0])return new _(!t.s||b&&!b[0]&&!O||O&&!O[0]&&!b?NaN:!b||!O?t.s/0:t.s*0);for(r=Yr(p.e/Qe)+Yr(t.e/Qe),c=b.length,d=O.length,c<d&&(s=b,b=O,O=s,o=c,c=d,d=o),s=[],o=c+d,n=o;n--;)s.push(0);for(n=d;--n>=0;){for(e=0,i=c+n;i>n;)u=s[i]+O[n]*b[i-n-1]+e,s[i--]=u%Pi|0,e=u/Pi|0;s[i]=(s[i]+e)%Pi|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=Vd(s,r),ut?He(t,_.precision,_.rounding):t};de.toBinary=function(t,e){return d_(this,2,t,e)};de.toDecimalPlaces=de.toDP=function(t,e){var r=this,n=r.constructor;return r=new n(r),t===void 0?r:(gn(t,0,Co),e===void 0?e=n.rounding:gn(e,0,8),He(r,t+r.e+1,e))};de.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ss(n,!0):(gn(t,0,Co),e===void 0?e=i.rounding:gn(e,0,8),n=He(new i(n),t+1,e),r=ss(n,!0,t+1)),n.isNeg()&&!n.isZero()?"-"+r:r};de.toFixed=function(t,e){var r,n,i=this,s=i.constructor;return t===void 0?r=ss(i):(gn(t,0,Co),e===void 0?e=s.rounding:gn(e,0,8),n=He(new s(i),t+i.e+1,e),r=ss(n,!1,t+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};de.toFraction=function(t){var e,r,n,i,s,o,u,c,d,p,_,b,O=this,T=O.d,x=O.constructor;if(!T)return new x(O);if(d=r=new x(1),n=c=new x(0),e=new x(n),s=e.e=RT(T)-O.e-1,o=s%Qe,e.d[0]=Or(10,o<0?Qe+o:o),t==null)t=s>0?e:d;else{if(u=new x(t),!u.isInt()||u.lt(d))throw Error(Po+u);t=u.gt(e)?s>0?e:d:u}for(ut=!1,u=new x(Lr(T)),p=x.precision,x.precision=s=T.length*Qe*2;_=Bt(u,e,0,1,1),i=r.plus(_.times(n)),i.cmp(t)!=1;)r=n,n=i,i=d,d=c.plus(_.times(i)),c=i,i=e,e=u.minus(_.times(i)),u=i;return i=Bt(t.minus(r),n,0,1,1),c=c.plus(i.times(d)),r=r.plus(i.times(n)),c.s=d.s=O.s,b=Bt(d,n,s,1).minus(O).abs().cmp(Bt(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,ut=!0,b};de.toHexadecimal=de.toHex=function(t,e){return d_(this,16,t,e)};de.toNearest=function(t,e){var r=this,n=r.constructor;if(r=new n(r),t==null){if(!r.d)return r;t=new n(1),e=n.rounding}else{if(t=new n(t),e===void 0?e=n.rounding:gn(e,0,8),!r.d)return t.s?r:t;if(!t.d)return t.s&&(t.s=r.s),t}return t.d[0]?(ut=!1,r=Bt(r,t,0,e,1).times(t),ut=!0,He(r)):(t.s=r.s,r=t),r};de.toNumber=function(){return+this};de.toOctal=function(t,e){return d_(this,8,t,e)};de.toPower=de.pow=function(t){var e,r,n,i,s,o,u=this,c=u.constructor,d=+(t=new c(t));if(!u.d||!t.d||!u.d[0]||!t.d[0])return new c(Or(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return He(u,n,s);if(e=Yr(t.e/Qe),e>=t.d.length-1&&(r=d<0?-d:d)<=TH)return i=UT(c,u,r,n),t.s<0?new c(1).div(i):He(i,n,s);if(o=u.s,o<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(o=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=o,u}return r=Or(+u,d),e=r==0||!isFinite(r)?Yr(d*(Math.log("0."+Lr(u.d))/Math.LN10+u.e+1)):new c(r+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?o/0:0):(ut=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=o_(t.times(xo(u,n+r)),n),i.d&&(i=He(i,n+5,1),Vc(i.d,n,s)&&(e=n+10,i=He(o_(t.times(xo(u,e+r)),e),e+5,1),+Lr(i.d).slice(n+1,n+15)+1==1e14&&(i=He(i,n+1,0)))),i.s=o,ut=!0,c.rounding=s,He(i,n,s))};de.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ss(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(gn(t,1,Co),e===void 0?e=i.rounding:gn(e,0,8),n=He(new i(n),t,e),r=ss(n,t<=n.e||n.e<=i.toExpNeg,t)),n.isNeg()&&!n.isZero()?"-"+r:r};de.toSignificantDigits=de.toSD=function(t,e){var r=this,n=r.constructor;return t===void 0?(t=n.precision,e=n.rounding):(gn(t,1,Co),e===void 0?e=n.rounding:gn(e,0,8)),He(new n(r),t,e)};de.toString=function(){var t=this,e=t.constructor,r=ss(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};de.truncated=de.trunc=function(){return He(new this.constructor(this),this.e+1,1)};de.valueOf=de.toJSON=function(){var t=this,e=t.constructor,r=ss(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Lr(t){var e,r,n,i=t.length-1,s="",o=t[0];if(i>0){for(s+=o,e=1;e<i;e++)n=t[e]+"",r=Qe-n.length,r&&(s+=To(r)),s+=n;o=t[e],n=o+"",r=Qe-n.length,r&&(s+=To(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function gn(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Po+t)}function Vc(t,e,r,n){var i,s,o,u;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=Qe,i=0):(i=Math.ceil((e+1)/Qe),e%=Qe),s=Or(10,Qe-e),u=t[i]%s|0,n==null?e<3?(e==0?u=u/100|0:e==1&&(u=u/10|0),o=r<4&&u==99999||r>3&&u==49999||u==5e4||u==0):o=(r<4&&u+1==s||r>3&&u+1==s/2)&&(t[i+1]/s/100|0)==Or(10,e-2)-1||(u==s/2||u==0)&&(t[i+1]/s/100|0)==0:e<4?(e==0?u=u/1e3|0:e==1?u=u/100|0:e==2&&(u=u/10|0),o=(n||r<4)&&u==9999||!n&&r>3&&u==4999):o=((n||r<4)&&u+1==s||!n&&r>3&&u+1==s/2)&&(t[i+1]/s/1e3|0)==Or(10,e-3)-1,o}function Dd(t,e,r){for(var n,i=[0],s,o=0,u=t.length;o<u;){for(s=i.length;s--;)i[s]*=e;for(i[0]+=n_.indexOf(t.charAt(o++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function PH(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/zd(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=Ou(t,1,e.times(i),new t(1));for(var s=r;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return t.precision-=r,e}var Bt=(function(){function t(n,i,s){var o,u=0,c=n.length;for(n=n.slice();c--;)o=n[c]*i+u,n[c]=o%s|0,u=o/s|0;return u&&n.unshift(u),n}function e(n,i,s,o){var u,c;if(s!=o)c=s>o?1:-1;else for(u=c=0;u<s;u++)if(n[u]!=i[u]){c=n[u]>i[u]?1:-1;break}return c}function r(n,i,s,o){for(var u=0;s--;)n[s]-=u,u=n[s]<i[s]?1:0,n[s]=u*o+n[s]-i[s];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,s,o,u,c){var d,p,_,b,O,T,x,F,R,H,J,ee,ae,te,he,A,I,C,D,N,k=n.constructor,m=n.s==i.s?1:-1,a=n.d,l=i.d;if(!a||!a[0]||!l||!l[0])return new k(!n.s||!i.s||(a?l&&a[0]==l[0]:!l)?NaN:a&&a[0]==0||!l?m*0:m/0);for(c?(O=1,p=n.e-i.e):(c=Pi,O=Qe,p=Yr(n.e/O)-Yr(i.e/O)),D=l.length,I=a.length,R=new k(m),H=R.d=[],_=0;l[_]==(a[_]||0);_++);if(l[_]>(a[_]||0)&&p--,s==null?(te=s=k.precision,o=k.rounding):u?te=s+(n.e-i.e)+1:te=s,te<0)H.push(1),T=!0;else{if(te=te/O+2|0,_=0,D==1){for(b=0,l=l[0],te++;(_<I||b)&&te--;_++)he=b*c+(a[_]||0),H[_]=he/l|0,b=he%l|0;T=b||_<I}else{for(b=c/(l[0]+1)|0,b>1&&(l=t(l,b,c),a=t(a,b,c),D=l.length,I=a.length),A=D,J=a.slice(0,D),ee=J.length;ee<D;)J[ee++]=0;N=l.slice(),N.unshift(0),C=l[0],l[1]>=c/2&&++C;do b=0,d=e(l,J,D,ee),d<0?(ae=J[0],D!=ee&&(ae=ae*c+(J[1]||0)),b=ae/C|0,b>1?(b>=c&&(b=c-1),x=t(l,b,c),F=x.length,ee=J.length,d=e(x,J,F,ee),d==1&&(b--,r(x,D<F?N:l,F,c))):(b==0&&(d=b=1),x=l.slice()),F=x.length,F<ee&&x.unshift(0),r(J,x,ee,c),d==-1&&(ee=J.length,d=e(l,J,D,ee),d<1&&(b++,r(J,D<ee?N:l,ee,c))),ee=J.length):d===0&&(b++,J=[0]),H[_++]=b,d&&J[0]?J[ee++]=a[A]||0:(J=[a[A]],ee=1);while((A++<I||J[0]!==void 0)&&te--);T=J[0]!==void 0}H[0]||H.shift()}if(O==1)R.e=p,CT=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,He(R,u?s+R.e+1:s,o,T)}return R}})();function He(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor;e:if(e!=null){if(_=t.d,!_)return t;for(i=1,u=_[0];u>=10;u/=10)i++;if(s=e-i,s<0)s+=Qe,o=e,p=_[b=0],c=p/Or(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/Qe),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=Qe,o=s-Qe+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=Qe,o=s-Qe+i,c=o<0?0:p/Or(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%Or(10,i-o-1)),d=r<4?(c||n)&&(r==0||r==(t.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(s>0?o>0?p/Or(10,i-o):0:_[b-1])%10&1||r==(t.s<0?8:7)),e<1||!_[0])return _.length=0,d?(e-=t.e+1,_[0]=Or(10,(Qe-e%Qe)%Qe),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=Or(10,Qe-s),_[b]=o>0?(p/Or(10,i-o)%Or(10,o)|0)*u:0),d)for(;;)if(b==0){for(s=1,o=_[0];o>=10;o/=10)s++;for(o=_[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(t.e++,_[0]==Pi&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=Pi)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return ut&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function ss(t,e,r){if(!t.isFinite())return $T(t);var n,i=t.e,s=Lr(t.d),o=s.length;return e?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+To(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):i<0?(s="0."+To(-i-1)+s,r&&(n=r-o)>0&&(s+=To(n))):i>=o?(s+=To(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+To(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=To(n))),s}function Vd(t,e){var r=t[0];for(e*=Qe;r>=10;r/=10)e++;return e}function $d(t,e,r){if(e>xH)throw ut=!0,r&&(t.precision=r),Error(jT);return He(new t(Ud),e,1,!0)}function is(t,e,r){if(e>s_)throw Error(jT);return He(new t(Ld),e,r,!0)}function RT(t){var e=t.length-1,r=e*Qe+1;if(e=t[e],e){for(;e%10==0;e/=10)r--;for(e=t[0];e>=10;e/=10)r++}return r}function To(t){for(var e="";t--;)e+="0";return e}function UT(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/Qe+4);for(ut=!1;;){if(r%2&&(s=s.times(e),eT(s.d,o)&&(i=!0)),r=Yr(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}e=e.times(e),eT(e.d,o)}return ut=!0,s}function QI(t){return t.d[t.d.length-1]&1}function LT(t,e,r){for(var n,i,s=new t(e[0]),o=0;++o<e.length;){if(i=new t(e[o]),!i.s){s=i;break}n=s.cmp(i),(n===r||n===0&&s.s===r)&&(s=i)}return s}function o_(t,e){var r,n,i,s,o,u,c,d=0,p=0,_=0,b=t.constructor,O=b.rounding,T=b.precision;if(!t.d||!t.d[0]||t.e>17)return new b(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:NaN);for(e==null?(ut=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(Or(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=He(s.times(t),c,1),r=r.times(++p),u=o.plus(Bt(s,r,c,1)),Lr(u.d).slice(0,c)===Lr(o.d).slice(0,c)){for(i=_;i--;)o=He(o.times(o),c,1);if(e==null)if(d<3&&Vc(o.d,c-n,O,d))b.precision=c+=10,r=s=u=new b(1),p=0,d++;else return He(o,b.precision=T,O,ut=!0);else return b.precision=T,o}o=u}}function xo(t,e){var r,n,i,s,o,u,c,d,p,_,b,O=1,T=10,x=t,F=x.d,R=x.constructor,H=R.rounding,J=R.precision;if(x.s<0||!F||!F[0]||!x.e&&F[0]==1&&F.length==1)return new R(F&&!F[0]?-1/0:x.s!=1?NaN:F?0:x);if(e==null?(ut=!1,p=J):p=e,R.precision=p+=T,r=Lr(F),n=r.charAt(0),Math.abs(s=x.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)x=x.times(t),r=Lr(x.d),n=r.charAt(0),O++;s=x.e,n>1?(x=new R("0."+r),s++):x=new R(n+"."+r.slice(1))}else return d=$d(R,p+2,J).times(s+""),x=xo(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?He(x,J,H,ut=!0):x;for(_=x,c=o=x=Bt(x.minus(1),x.plus(1),p,1),b=He(x.times(x),p,1),i=3;;){if(o=He(o.times(b),p,1),d=c.plus(Bt(o,new R(i),p,1)),Lr(d.d).slice(0,p)===Lr(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus($d(R,p+2,J).times(s+""))),c=Bt(c,new R(O),p,1),e==null)if(Vc(c.d,p-T,H,u))R.precision=p+=T,d=o=x=Bt(_.minus(1),_.plus(1),p,1),b=He(x.times(x),p,1),i=u=1;else return He(c,R.precision=J,H,ut=!0);else return R.precision=J,c;c=d,i+=2}}function $T(t){return String(t.s*t.s/0)}function Bd(t,e){var r,n,i;for((r=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(r<0&&(r=n),r+=+e.slice(n+1),e=e.substring(0,n)):r<0&&(r=e.length),n=0;e.charCodeAt(n)===48;n++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(n,i),e){if(i-=n,t.e=r=r-n-1,t.d=[],n=(r+1)%Qe,r<0&&(n+=Qe),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=Qe;n<i;)t.d.push(+e.slice(n,n+=Qe));e=e.slice(n),n=Qe-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),ut&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function CH(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),BT.test(e))return Bd(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(AH.test(e))r=16,e=e.toLowerCase();else if(EH.test(e))r=2;else if(IH.test(e))r=8;else throw Error(Po+e);for(s=e.search(/p/i),s>0?(c=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),s=e.indexOf("."),o=s>=0,n=t.constructor,o&&(e=e.replace(".",""),u=e.length,s=u-s,i=UT(n,new n(r),s,s*2)),d=Dd(e,r,Pi),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=Vd(d,p),t.d=d,ut=!1,o&&(t=Bt(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?Or(2,c):zc.pow(2,c))),ut=!0,t)}function jH(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:Ou(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/zd(5,r)),e=Ou(t,2,e,e);for(var i,s=new t(5),o=new t(16),u=new t(20);r--;)i=e.times(e),e=e.times(s.plus(i.times(o.times(i).minus(u))));return e}function Ou(t,e,r,n,i){var s,o,u,c,d=1,p=t.precision,_=Math.ceil(p/Qe);for(ut=!1,c=r.times(r),u=new t(n);;){if(o=Bt(u.times(c),new t(e++*e++),p,1),u=i?n.plus(o):n.minus(o),n=Bt(o.times(c),new t(e++*e++),p,1),o=u.plus(n),o.d[_]!==void 0){for(s=_;o.d[s]===u.d[s]&&s--;);if(s==-1)break}s=u,u=n,n=o,o=s,d++}return ut=!0,o.d.length=_+1,o}function zd(t,e){for(var r=t;--e;)r*=t;return r}function FT(t,e){var r,n=e.s<0,i=is(t,t.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return js=n?4:1,e;if(r=e.divToInt(i),r.isZero())js=n?3:2;else{if(e=e.minus(r.times(i)),e.lte(s))return js=QI(r)?n?2:3:n?4:1,e;js=QI(r)?n?1:4:n?3:2}return e.minus(i).abs()}function d_(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor,T=r!==void 0;if(T?(gn(r,1,Co),n===void 0?n=O.rounding:gn(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=$T(t);else{for(p=ss(t),o=p.indexOf("."),T?(i=2,e==16?r=r*4-3:e==8&&(r=r*3-2)):i=e,o>=0&&(p=p.replace(".",""),b=new O(1),b.e=p.length-o,b.d=Dd(ss(b),10,i),b.e=b.d.length),_=Dd(p,10,i),s=c=_.length;_[--c]==0;)_.pop();if(!_[0])p=T?"0p+0":"0";else{if(o<0?s--:(t=new O(t),t.d=_,t.e=s,t=Bt(t,b,r,n,0,i),_=t.d,s=t.e,d=CT),o=_[r],u=i/2,d=d||_[r+1]!==void 0,d=n<4?(o!==void 0||d)&&(n===0||n===(t.s<0?3:2)):o>u||o===u&&(n===4||d||n===6&&_[r-1]&1||n===(t.s<0?8:7)),_.length=r,d)for(;++_[--r]>i-1;)_[r]=0,r||(++s,_.unshift(1));for(c=_.length;!_[c-1];--c);for(o=0,p="";o<c;o++)p+=n_.charAt(_[o]);if(T){if(c>1)if(e==16||e==8){for(o=e==16?4:3,--c;c%o;c++)p+="0";for(_=Dd(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=n_.charAt(_[o])}else p=p.charAt(0)+"."+p.slice(1);p=p+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)p="0"+p;p="0."+p}else if(++s>c)for(s-=c;s--;)p+="0";else s<c&&(p=p.slice(0,s)+"."+p.slice(s))}p=(e==16?"0x":e==2?"0b":e==8?"0o":"")+p}return t.s<0?"-"+p:p}function eT(t,e){if(t.length>e)return t.length=e,!0}function NH(t){return new this(t).abs()}function DH(t){return new this(t).acos()}function BH(t){return new this(t).acosh()}function RH(t,e){return new this(t).plus(e)}function UH(t){return new this(t).asin()}function LH(t){return new this(t).asinh()}function $H(t){return new this(t).atan()}function FH(t){return new this(t).atanh()}function qH(t,e){t=new this(t),e=new this(e);var r,n=this.precision,i=this.rounding,s=n+4;return!t.s||!e.s?r=new this(NaN):!t.d&&!e.d?(r=is(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?is(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=is(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan(Bt(t,e,s,1)),e=is(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(Bt(t,e,s,1)),r}function VH(t){return new this(t).cbrt()}function zH(t){return He(t=new this(t),t.e+1,2)}function GH(t,e,r){return new this(t).clamp(e,r)}function HH(t){if(!t||typeof t!="object")throw Error(qd+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,Co,"rounding",0,8,"toExpNeg",-bu,0,"toExpPos",0,bu,"maxE",0,bu,"minE",-bu,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=i_[r]),(n=t[r])!==void 0)if(Yr(n)===n&&n>=s[e+1]&&n<=s[e+2])this[r]=n;else throw Error(Po+r+": "+n);if(r="crypto",i&&(this[r]=i_[r]),(n=t[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(NT);else this[r]=!1;else throw Error(Po+r+": "+n);return this}function WH(t){return new this(t).cos()}function KH(t){return new this(t).cosh()}function qT(t){var e,r,n;function i(s){var o,u,c,d=this;if(!(d instanceof i))return new i(s);if(d.constructor=i,tT(s)){d.s=s.s,ut?!s.d||s.e>i.maxE?(d.e=NaN,d.d=null):s.e<i.minE?(d.e=0,d.d=[0]):(d.e=s.e,d.d=s.d.slice()):(d.e=s.e,d.d=s.d?s.d.slice():s.d);return}if(c=typeof s,c==="number"){if(s===0){d.s=1/s<0?-1:1,d.e=0,d.d=[0];return}if(s<0?(s=-s,d.s=-1):d.s=1,s===~~s&&s<1e7){for(o=0,u=s;u>=10;u/=10)o++;ut?o>i.maxE?(d.e=NaN,d.d=null):o<i.minE?(d.e=0,d.d=[0]):(d.e=o,d.d=[s]):(d.e=o,d.d=[s]);return}if(s*0!==0){s||(d.s=NaN),d.e=NaN,d.d=null;return}return Bd(d,s.toString())}if(c==="string")return(u=s.charCodeAt(0))===45?(s=s.slice(1),d.s=-1):(u===43&&(s=s.slice(1)),d.s=1),BT.test(s)?Bd(d,s):CH(d,s);if(c==="bigint")return s<0?(s=-s,d.s=-1):d.s=1,Bd(d,s.toString());throw Error(Po+s)}if(i.prototype=de,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=HH,i.clone=qT,i.isDecimal=tT,i.abs=NH,i.acos=DH,i.acosh=BH,i.add=RH,i.asin=UH,i.asinh=LH,i.atan=$H,i.atanh=FH,i.atan2=qH,i.cbrt=VH,i.ceil=zH,i.clamp=GH,i.cos=WH,i.cosh=KH,i.div=XH,i.exp=JH,i.floor=ZH,i.hypot=YH,i.ln=QH,i.log=eW,i.log10=rW,i.log2=tW,i.max=nW,i.min=iW,i.mod=sW,i.mul=oW,i.pow=aW,i.random=uW,i.round=cW,i.sign=lW,i.sin=fW,i.sinh=dW,i.sqrt=hW,i.sub=pW,i.sum=mW,i.tan=gW,i.tanh=yW,i.trunc=_W,t===void 0&&(t={}),t&&t.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)t.hasOwnProperty(r=n[e++])||(t[r]=this[r]);return i.config(t),i}function XH(t,e){return new this(t).div(e)}function JH(t){return new this(t).exp()}function ZH(t){return He(t=new this(t),t.e+1,3)}function YH(){var t,e,r=new this(0);for(ut=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)r.d&&(r=r.plus(e.times(e)));else{if(e.s)return ut=!0,new this(1/0);r=e}return ut=!0,r.sqrt()}function tT(t){return t instanceof zc||t&&t.toStringTag===DT||!1}function QH(t){return new this(t).ln()}function eW(t,e){return new this(t).log(e)}function tW(t){return new this(t).log(2)}function rW(t){return new this(t).log(10)}function nW(){return LT(this,arguments,-1)}function iW(){return LT(this,arguments,1)}function sW(t,e){return new this(t).mod(e)}function oW(t,e){return new this(t).mul(e)}function aW(t,e){return new this(t).pow(e)}function uW(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:gn(t,1,Co),n=Math.ceil(t/Qe),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));s<n;)i=e[s],i>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);s<n;)i=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((e[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,s):(u.push(i%1e7),s+=4);s=n/4}else throw Error(NT);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=Qe,n&&t&&(i=Or(10,Qe-t),u[s]=(n/i|0)*i);u[s]===0;s--)u.pop();if(s<0)r=0,u=[0];else{for(r=-1;u[0]===0;r-=Qe)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<Qe&&(r-=Qe-n)}return o.e=r,o.d=u,o}function cW(t){return He(t=new this(t),t.e+1,this.rounding)}function lW(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function fW(t){return new this(t).sin()}function dW(t){return new this(t).sinh()}function hW(t){return new this(t).sqrt()}function pW(t,e){return new this(t).sub(e)}function mW(){var t=0,e=arguments,r=new this(e[t]);for(ut=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return ut=!0,He(r,this.precision,this.rounding)}function gW(t){return new this(t).tan()}function yW(t){return new this(t).tanh()}function _W(t){return He(t=new this(t),t.e+1,1)}de[Symbol.for("nodejs.util.inspect.custom")]=de.toString;de[Symbol.toStringTag]="Decimal";var zc=de.constructor=qT(i_);Ud=new zc(Ud);Ld=new zc(Ld);var Tr=zc;function Fd(t){let e=An.isSuiCoin(t.coin_type_a),r=An.isSuiCoin(t.coin_type_b);return{is_adjust_coin_a:e,is_adjust_coin_b:r}}function vW(t,e){return Tr.ceil(Tr(t).div(1+e)).toString()}var _a=class{static createCollectRewarderAndFeeParams(t,e,r,n,i,s){i===void 0&&(i=[...n]),s===void 0&&(s=[...n]);let o=Vy(r.coin_type_a),u=Vy(r.coin_type_b);if(r.collect_fee){let d=An.buildCoinForAmount(e,i,BigInt(0),o,!1);i=d.remain_coins;let p=An.buildCoinForAmount(e,s,BigInt(0),u,!1);s=p.remain_coins,e=t.Position.createCollectFeePayload({pool_id:r.pool_id,pos_id:r.pos_id,coin_type_a:r.coin_type_a,coin_type_b:r.coin_type_b},e,d.target_coin,p.target_coin)}let c=[];return r.rewarder_coin_types.forEach(d=>{switch(Vy(d)){case o:c.push(An.buildCoinForAmount(e,i,BigInt(0),d,!1).target_coin);break;case u:c.push(An.buildCoinForAmount(e,s,BigInt(0),d,!1).target_coin);break;default:c.push(An.buildCoinForAmount(e,n,BigInt(0),d,!1).target_coin);break}}),e=t.Rewarder.createCollectRewarderPayload(r,e,c),e}static async adjustTransactionForGas(t,e,r,n){n.setSender(t.getSenderAddress());let i=An.selectCoinAssetGreaterThanOrEqual(e,r).selected_coins,s=An.calculateTotalBalance(e);if(i.length===0&&St("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${s}`),s-r>1e9)return{fixAmount:r};let o=await t.FullClient.calculationTxGas(ot.from(n));if(An.selectCoinAssetGreaterThanOrEqual(e,BigInt(o),i.map(u=>u.coin_object_id)).selected_coins.length===0){let u=BigInt(o)+BigInt(500);if(s-r<u){r-=u,r<0&&St("InsufficientBalance","gas Insufficient balance");let c=new ot;return{fixAmount:r,newTx:c}}}return{fixAmount:r}}static async buildAddLiquidityFixTokenForGas(t,e,r,n,i,s,o){i=await this.buildAddLiquidityFixToken(t,e,r,i,s,o);let{is_adjust_coin_a:u}=Fd(r),c=u?r.amount_a:r.amount_b,d=await this.adjustTransactionForGas(t,An.getCoinAssets(u?r.coin_type_a:r.coin_type_b,e),BigInt(c),i),{fixAmount:p}=d,_=d.newTx;if(_!=null){let b,O;if(u)r.amount_a=Number(p),b=this.buildAddLiquidityFixTokenCoinInput(_,!r.fix_amount_a,p.toString(),r.slippage,r.coin_type_a,e,!1,!0),O=this.buildAddLiquidityFixTokenCoinInput(_,r.fix_amount_a,r.amount_b,r.slippage,r.coin_type_b,e,!1,!0);else return r.amount_b=Number(p),b=this.buildAddLiquidityFixTokenCoinInput(_,!r.fix_amount_a,r.amount_a,r.slippage,r.coin_type_a,e,!1,!0),O=this.buildAddLiquidityFixTokenCoinInput(_,r.fix_amount_a,p.toString(),r.slippage,r.coin_type_b,e,!1,!0),r=this.fixAddLiquidityFixTokenParams(r,n.slippage,n.cur_sqrt_price),this.buildAddLiquidityFixTokenArgs(_,t,e,r,b,O)}return i}static async buildAddLiquidityFixToken(t,e,r,n,i,s){n=n||new ot;let o,u;return i==null||s==null?(o=this.buildAddLiquidityFixTokenCoinInput(n,!r.fix_amount_a,r.amount_a,r.slippage,r.coin_type_a,e,!1,!0),u=this.buildAddLiquidityFixTokenCoinInput(n,r.fix_amount_a,r.amount_b,r.slippage,r.coin_type_b,e,!1,!0)):(o={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},u={target_coin:s,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),n=this.buildAddLiquidityFixTokenArgs(n,t,e,r,o,u),n}static buildAddLiquidityFixTokenCoinInput(t,e,r,n,i,s,o=!0,u=!0){return e?An.buildCoinForAmountInterval(t,s,{amount_second:BigInt(vW(r,n)),amount_first:BigInt(r)},i,o,u):An.buildCoinForAmount(t,s,BigInt(r),i,o,u)}static fixAddLiquidityFixTokenParams(t,e,r){let n=t.fix_amount_a?t.amount_a:t.amount_b,i=kH.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new SH.default(n),t.fix_amount_a,!0,e,r);return t.amount_a=t.fix_amount_a?t.amount_a:i.coin_amount_limit_a,t.amount_b=t.fix_amount_a?i.coin_amount_limit_b:t.amount_b,t}static buildAddLiquidityFixTokenArgs(t,e,r,n,i,s){let o=[n.coin_type_a,n.coin_type_b],u=n.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:c,integrate:d}=e.sdkOptions;n.is_open||(t=this.createCollectRewarderAndFeeParams(e,t,n,r,i.remain_coins,s.remain_coins));let p=OH(c),_=n.is_open?[t.object(p.global_config_id),t.object(n.pool_id),t.pure.u32(Number(ZI(BigInt(n.tick_lower)).toString())),t.pure.u32(Number(ZI(BigInt(n.tick_upper)).toString())),i.target_coin,s.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(YI)]:[t.object(p.global_config_id),t.object(n.pool_id),t.object(n.pos_id),i.target_coin,s.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(YI)];return t.moveCall({target:`${d.published_at}::${Mu}::${u}`,typeArguments:o,arguments:_}),t}static checkCoinThreshold(t,e,r,n,i,s){e&&r.moveCall({target:`${t.sdkOptions.integrate.published_at}::${PT}::check_coin_threshold`,typeArguments:[s],arguments:[n,r.pure.u64(i)]})}},vu=class Io{static getDefaultSqrtPriceLimit(e){return new pH.default(e?yH:gH)}static getDefaultOtherAmountThreshold(e){return e?vH:_H}static async buildSwapTransactionForGas(e,r,n,i){let s=this.buildSwapTransaction(e,r,n);s.setSender(e.getSenderAddress());let o=await this.adjustTransactionForGas(e,En.getCoinAssets(r.a2b?r.coin_type_a:r.coin_type_b,n),BigInt(r.by_amount_in?r.amount:r.amount_limit),s),{fixAmount:u,newTx:c}=o;if(c!==void 0){c.setSender(e.getSenderAddress()),r.by_amount_in?r.amount=u.toString():r.amount_limit=u.toString(),r=await this.fixSwapParams(e,r,i);let d=En.buildCoinForAmount(s,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a),p=En.buildCoinForAmount(s,n,r.a2b?BigInt(0):BigInt(r.by_amount_in?r.amount:r.amount_limit),r.coin_type_b);s=this.buildSwapTransactionArgs(c,r,e.sdkOptions,d,p)}return s}static buildSwapTransactionArgs(e,r,n,i,s){let{clmm_pool:o,integrate:u}=n,c=Io.getDefaultSqrtPriceLimit(r.a2b),d=[r.coin_type_a,r.coin_type_b],{global_config_id:p}=JI(o);p===void 0&&St("InvalidConfig","clmm.config.global_config_id is undefined");let _=r.swap_partner!==void 0,b=_?r.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":r.a2b?"swap_a2b":"swap_b2a",O=_?[e.object(p),e.object(r.pool_id),e.object(r.swap_partner),i.target_coin,s.target_coin,e.pure.bool(r.by_amount_in),e.pure.u64(r.amount),e.pure.u64(r.amount_limit),e.pure.u128(c.toString()),e.object(Ed)]:[e.object(p),e.object(r.pool_id),i.target_coin,s.target_coin,e.pure.bool(r.by_amount_in),e.pure.u64(r.amount),e.pure.u64(r.amount_limit),e.pure.u128(c.toString()),e.object(Ed)];return e.moveCall({target:`${u.published_at}::${Mu}::${b}`,typeArguments:d,arguments:O}),e}static async adjustTransactionForGas(e,r,n,i){i.setSender(e.getSenderAddress());let s=En.selectCoinAssetGreaterThanOrEqual(r,n).selected_coins,o=En.calculateTotalBalance(r);if(s.length===0&&St("InsufficientBalance",`Insufficient balance exceed amount ${n} real amount ${o}`),o-n>1e9)return{fixAmount:n};let u=await e.FullClient.calculationTxGas(i);if(En.selectCoinAssetGreaterThanOrEqual(r,BigInt(u),s.map(c=>c.coin_object_id)).selected_coins.length===0){let c=BigInt(u)+BigInt(500);if(o-n<c){n-=c,n<0&&St("InsufficientBalance","gas Insufficient balance");let d=new ot;return{fixAmount:n,newTx:d}}}return{fixAmount:n}}static buildSwapTransaction(e,r,n){let i=new ot;i.setSender(e.getSenderAddress());let s=En.buildCoinForAmount(i,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1),o=En.buildCoinForAmount(i,n,r.a2b?BigInt(0):BigInt(r.by_amount_in?r.amount:r.amount_limit),r.coin_type_b,!1);return i=this.buildSwapTransactionArgs(i,r,e.sdkOptions,s,o),i}static async fixSwapParams(e,r,n){let{current_pool:i}=n;try{let s=await e.Swap.preSwap({decimals_a:n.decimals_a,decimals_b:n.decimals_b,a2b:r.a2b,by_amount_in:r.by_amount_in,amount:r.amount,pool:i,current_sqrt_price:i.current_sqrt_price,coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b}),o=n.by_amount_in?s.estimated_amount_out:s.estimated_amount_in,u=mH(o,n.slippage,!n.by_amount_in);r.amount_limit=u.toString()}catch(s){Ns("InvalidConfig",s)}return r}static async buildSwapTransactionWithoutTransferCoinsForGas(e,r,n,i){let{tx:s,coin_ab_s:o}=Io.buildSwapTransactionWithoutTransferCoins(e,r,n);s.setSender(e.getSenderAddress());let u=await Io.adjustTransactionForGas(e,En.getCoinAssets(r.a2b?r.coin_type_a:r.coin_type_b,n),BigInt(r.by_amount_in?r.amount:r.amount_limit),s),{fixAmount:c,newTx:d}=u;if(d!==void 0){d.setSender(e.getSenderAddress()),r.by_amount_in?r.amount=c.toString():r.amount_limit=c.toString(),r=await Io.fixSwapParams(e,r,i);let p=En.buildCoinForAmount(s,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1,!0),_=En.buildCoinForAmount(s,n,r.a2b?BigInt(0):BigInt(r.by_amount_in?r.amount:r.amount_limit),r.coin_type_b,!1,!0),b=Io.buildSwapTransactionWithoutTransferCoinArgs(e,d,r,e.sdkOptions,p,_);s=b.tx,o=b.txRes}return{tx:s,coin_ab_s:o}}static buildSwapTransactionWithoutTransferCoins(e,r,n){let i=new ot;i.setSender(e.getSenderAddress());let s=En.buildCoinForAmount(i,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1,!0),o=En.buildCoinForAmount(i,n,r.a2b?BigInt(0):BigInt(r.by_amount_in?r.amount:r.amount_limit),r.coin_type_b,!1,!0),u=Io.buildSwapTransactionWithoutTransferCoinArgs(e,i,r,e.sdkOptions,s,o);return{tx:u.tx,coin_ab_s:u.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(e,r,n,i,s,o){let{clmm_pool:u,integrate:c}=i,d=Io.getDefaultSqrtPriceLimit(n.a2b),{global_config_id:p}=JI(u);p===void 0&&St("InvalidConfig","clmm.config.global_config_id is undefined");let _=n.swap_partner!==void 0,b=_?"swap_with_partner":"swap",O=_?wH:PT,T=_?[r.object(p),r.object(n.pool_id),r.object(n.swap_partner),s.target_coin,o.target_coin,r.pure.bool(n.a2b),r.pure.bool(n.by_amount_in),r.pure.u64(n.amount),r.pure.u128(d.toString()),r.pure.bool(!1),r.object(Ed)]:[r.object(p),r.object(n.pool_id),s.target_coin,o.target_coin,r.pure.bool(n.a2b),r.pure.bool(n.by_amount_in),r.pure.u64(n.amount),r.pure.u128(d.toString()),r.pure.bool(!1),r.object(Ed)],x=[n.coin_type_a,n.coin_type_b],F=r.moveCall({target:`${c.published_at}::${O}::${b}`,typeArguments:x,arguments:T});if(n.by_amount_in){let R=n.a2b?n.coin_type_b:n.coin_type_a,H=n.a2b?F[1]:F[0],J=Number(n.amount_limit);_a.checkCoinThreshold(e,n.by_amount_in,r,H,J,R)}return{tx:r,txRes:F}}};function bW(t){return{coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,current_sqrt_price:new ns.default(t.current_sqrt_price),current_tick_index:t.current_tick_index,fee_growth_global_a:new ns.default(t.fee_growth_global_a),fee_growth_global_b:new ns.default(t.fee_growth_global_b),fee_protocol_coin_a:new ns.default(t.fee_protocol_coin_a),fee_protocol_coin_b:new ns.default(t.fee_protocol_coin_b),fee_rate:new ns.default(t.fee_rate),liquidity:new ns.default(t.liquidity),tick_indexes:[],tick_spacing:Number(t.tick_spacing),ticks:[],collection_name:""}}function wW(t,e,r,n,i,s){if(r===Ti)return{amount_in:Ti,amount_out:Ti,next_sqrt_price:e,fee_amount:Ti};let o=t.gte(e),u,c,d,p;if(s){let _=ya.checkMulDivFloor(n,ya.checkUnsignedSub(Od,i),Od,64),b=XI(t,e,r,o);b.gt(_)?(u=_,p=ya.checkUnsignedSub(n,_),d=dH(t,r,_,o)):(u=b,p=ya.checkMulDivCeil(u,i,Od.sub(i),64),d=e),c=KI(t,d,r,o)}else{let _=KI(t,e,r,o);_.gt(n)?(c=n,d=hH(t,r,n,o)):(c=_,d=e),u=XI(t,d,r,o),p=ya.checkMulDivCeil(u,i,Od.sub(i),64)}return{amount_in:u,amount_out:c,next_sqrt_price:d,fee_amount:p}}function MW(t,e,r,n,i){let s=r,o=n.liquidity,{current_sqrt_price:u}=n,c={amount_in:Ti,amount_out:Ti,fee_amount:Ti,ref_amount:Ti,next_sqrt_price:Ti,cross_tick_num:0},d,p,_=vu.getDefaultSqrtPriceLimit(t);for(let b of i){if(t&&n.current_tick_index<b.index||!t&&n.current_tick_index>=b.index||b===null)continue;t&&_.gt(b.sqrt_price)||!t&&_.lt(b.sqrt_price)?d=_:d=b.sqrt_price;let O=wW(u,d,o,s,n.fee_rate,e);if(O.amount_in.eq(Ti)||(s=e?s.sub(O.amount_in.add(O.fee_amount)):s.sub(O.amount_out)),c.amount_in=c.amount_in.add(O.amount_in),c.amount_out=c.amount_out.add(O.amount_out),c.fee_amount=c.fee_amount.add(O.fee_amount),O.next_sqrt_price.eq(b.sqrt_price)?(p=b.liquidity_net.mul(new ns.default(-1)),t?ya.is_neg(p)?o=o.add(new ns.default(WI(BigInt(p.toString()),128))):o=o.add(p):ya.is_neg(p)?o=o.sub(new ns.default(WI(BigInt(p.toString()),128))):o=o.sub(p),u=b.sqrt_price):u=O.next_sqrt_price,c.cross_tick_num+=1,s.eq(Ti))break}return c.amount_in=c.amount_in.add(c.fee_amount),c.next_sqrt_price=u,c}var xi=Ds(Bs());function IW(t,e,r){let n=Eu(t).name,i=Eu(e).name;return`${n}-${i}[${r}]`}function zy(t){let e=VT(t),r=Eu(e),n=h_(t);n==null&&St("InvalidPoolObject",`Pool id ${a_(t)} not exists.`,{[Gd.METHOD_NAME]:"buildPool"});let i=[];n.rewarder_manager.fields.rewarders.forEach(c=>{let{emissions_per_second:d}=c.fields,p=AW.fromX64(new xi.default(d)),_=Math.floor(p.toNumber()*60*60*24);i.push({emissions_per_second:d,coin_type:Eu(c.fields.reward_coin.fields.name).source_address,growth_global:c.fields.growth_global,emissions_every_day:_})});let s=n.is_pause,o={disable_add_liquidity:s,disable_remove_liquidity:s,disable_swap:s,disable_flash_loan:s,disable_collect_fee:s,disable_collect_reward:s},u={id:a_(t),pool_type:e,coin_type_a:r.type_arguments[0],coin_type_b:r.type_arguments[1],coin_amount_a:n.coin_a,coin_amount_b:n.coin_b,current_sqrt_price:n.current_sqrt_price,current_tick_index:va(BigInt(n.current_tick_index.fields.bits)),fee_growth_global_a:n.fee_growth_global_a,fee_growth_global_b:n.fee_growth_global_b,fee_protocol_coin_a:n.fee_protocol_coin_a,fee_protocol_coin_b:n.fee_protocol_coin_b,fee_rate:n.fee_rate,pool_status:o,liquidity:n.liquidity,position_manager:{positions_handle:n.position_manager.fields.positions.fields.id.id,size:n.position_manager.fields.positions.fields.size},rewarder_infos:i,rewarder_last_updated_time:n.rewarder_manager.fields.last_updated_time,tick_spacing:n.tick_spacing,ticks_handle:n.tick_manager.fields.ticks.fields.id.id,uri:n.url,index:Number(n.index),name:""};return u.name=IW(u.coin_type_a,u.coin_type_b,u.tick_spacing),u}function Gy(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&St("InvalidPositionObject",`Position not exists. Get Position error:${t.error}`,{[Gd.METHOD_NAME]:"buildPosition"});let e={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},r={...e,pos_object_id:"",owner:"",type:"",coin_type_a:"",coin_type_b:"",liquidity:"",tick_lower_index:0,tick_upper_index:0,index:0,pool:"",reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"},n=h_(t);if(n){let o=VT(t),u=EW(t);"nft"in n?(n=n.nft.fields,e.description=n.description,e.name=n.name,e.link=n.url):e=SW(t),r={...e,pos_object_id:n.id.id,owner:u.AddressOwner,type:o,liquidity:n.liquidity,coin_type_a:n.coin_type_a.fields.name,coin_type_b:n.coin_type_b.fields.name,tick_lower_index:va(BigInt(n.tick_lower_index.fields.bits)),tick_upper_index:va(BigInt(n.tick_upper_index.fields.bits)),index:n.index,pool:n.pool,reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"}}let i=kW(t);i&&(r.pos_object_id=i.objectId,r.position_status="Deleted");let s=OW(t);return s&&(r.pos_object_id=s,r.position_status="NotExists"),r}function u_(t){let e={reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0"};t="fields"in t?t.fields:t,t.rewards.forEach((i,s)=>{let{amount_owned:o,growth_inside:u}="fields"in i?i.fields:i;s===0?(e.reward_amount_owned_0=o,e.reward_growth_inside_0=u):s===1?(e.reward_amount_owned_1=o,e.reward_growth_inside_1=u):s===2&&(e.reward_amount_owned_2=o,e.reward_growth_inside_2=u)});let r="fields"in t.tick_lower_index?t.tick_lower_index.fields.bits:t.tick_lower_index.bits,n="fields"in t.tick_upper_index?t.tick_upper_index.fields.bits:t.tick_upper_index.bits;return{liquidity:t.liquidity,tick_lower_index:va(BigInt(r)),tick_upper_index:va(BigInt(n)),...e,fee_growth_inside_a:t.fee_growth_inside_a,fee_owned_a:t.fee_owned_a,fee_growth_inside_b:t.fee_growth_inside_b,fee_owned_b:t.fee_owned_b,pos_object_id:t.position_id}}function Hy(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&St("InvalidTickObject",`Tick not exists. Get tick data error:${t.error}`,{[Gd.METHOD_NAME]:"buildTickData"});let e=h_(t).value.fields.value.fields;return{object_id:a_(t),index:va(BigInt(e.index.fields.bits)),sqrt_price:new xi.default(e.sqrt_price),liquidity_net:new xi.default(e.liquidity_net.fields.bits),liquidity_gross:new xi.default(e.liquidity_gross),fee_growth_outside_a:new xi.default(e.fee_growth_outside_a),fee_growth_outside_b:new xi.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function TW(t){(!t||!t.index||!t.sqrt_price||!t.liquidity_net||!t.liquidity_gross||!t.fee_growth_outside_a||!t.fee_growth_outside_b)&&St("InvalidTickFields","Invalid tick fields.",{[Gd.METHOD_NAME]:"buildTickDataByEvent"});let e=va(BigInt(t.index.bits)),r=new xi.default(t.sqrt_price),n=new xi.default(t.liquidity_net.bits),i=new xi.default(t.liquidity_gross),s=new xi.default(t.fee_growth_outside_a),o=new xi.default(t.fee_growth_outside_b),u=t.rewards_growth_outside||[];return{object_id:"",index:e,sqrt_price:r,liquidity_net:n,liquidity_gross:i,fee_growth_outside_a:s,fee_growth_outside_b:o,rewarders_growth_outside:u}}function xW(t,e,r){let n=[],{timestampMs:i,events:s}=t,o=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((u,c)=>{let d=Eu(u.type).name;if(o.includes(d)){let p={tx_digest:u.id.txDigest,package_id:u.packageId,transaction_module:u.transactionModule,sender:u.sender,type:u.type,timestamp_ms:i||"0",parsed_json:u.parsedJson,index:`${e}_${c}`};switch(d){case"CollectFeeEvent":r.includes(p.parsed_json.position)&&(Fc(p.parsed_json.amount_a).gt(0)||Fc(p.parsed_json.amount_b).gt(0))&&n.push(p);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":(Fc(p.parsed_json.amount_a).gt(0)||Fc(p.parsed_json.amount_b).gt(0))&&n.push(p);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(r.includes(p.parsed_json.position)||r.includes(p.parsed_json.wrapped_position_id))&&Fc(p.parsed_json.amount).gt(0)&&n.push(p);break;default:break}}}),n}function PW(t,e,r,n){let i=[],{timestampMs:s,events:o}=t;return o?.forEach((u,c)=>{let{name:d,address:p}=Eu(u.type);if(fH.includes(d)&&p===r&&n===u.parsedJson.pool){let _={tx:u.id.txDigest,sender:u.sender,type:u.type,block_time:s||"0",index:`${e}_${c}`,parsed_json:u.parsedJson};i.push(_)}}),i}function c_(t,e,r,n){e.moveCall({target:`${t.sdkOptions.integrate.published_at}::${MH}::transfer_coin_to_sender`,typeArguments:[n],arguments:[r]})}function CW(t,e,r,n,i){i!=null?e.transferObjects([r],e.pure.address(i)):c_(t,e,r,n)}var $W=1e4,Su=class{static parseClmmVestInfo(t){let e=Xy(t),r=LW(t),n=UW(r),i=e.global_vesting_periods.map(s=>({period:s.fields.period,release_time:s.fields.release_time,redeemed_amount:s.fields.redeemed_amount,percentage:oT(s.fields.percentage).div($W).toNumber()}));return{id:e.id.id,balance:e.balance,global_vesting_periods:i,total_value:e.total_value,total_cetus_amount:e.total_cetus_amount,redeemed_amount:e.redeemed_amount,start_time:e.start_time,type:n.full_address,positions:{id:e.positions.fields.id,size:e.positions.fields.size}}}static parsePositionVesting(t){return{position_id:t.position_id,cetus_amount:t.cetus_amount,redeemed_amount:t.redeemed_amount,is_paused:t.is_paused,impaired_a:t.impaired_a,impaired_b:t.impaired_b,period_details:t.period_details,coin_type_a:aT(t.coin_a.name,!1),coin_type_b:aT(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let e=Xy(t);return{current_sqrt_price:e.current_sqrt_price,remove_percent:oT(e.remove_percent).div(1e6).toString(),snapshots:{id:e.snapshots.fields.id.id,size:e.snapshots.fields.size}}}static parsePositionSnapshot(t){let e=Xy(t),r=e.value.fields.value.fields;return{position_id:e.name,liquidity:r.liquidity,tick_lower_index:sT(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:sT(BigInt(r.tick_upper_index.fields.bits)),fee_owned_a:r.fee_owned_a,fee_owned_b:r.fee_owned_b,value_cut:r.value_cut,rewards:r.rewards}}},FW=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getPositionList(t,e="all"){let r={data:[],has_next_page:!0},n=await this._sdk.FullClient.getDynamicFieldsByPage(t,e);r.has_next_page=n.has_next_page,r.next_cursor=n.next_cursor;let i=n.data.map(o=>(o.error!=null&&St("InvalidConfig",`when getPositionList get position objects error: ${o.error}, please check the rpc, contracts address config and position id.`,{[Dt.METHOD_NAME]:"getPositionList"}),o.name.value)),s=await this._sdk.Position.getSimplePositionList(i);return r.data=s,r}async getPoolImmutablesWithPage(t="all",e=!1){let{package_id:r}=this._sdk.sdkOptions.clmm_pool,n=[],i={data:[],has_next_page:!1},s=t==="all",o=`${r}_getPoolImmutables`;if(s){let u=this._sdk.getCache(o,e);u&&n.push(...u)}if(n.length===0)try{let u=`${r}::factory::CreatePoolEvent`,c=await this._sdk.FullClient.queryEventsByPage({MoveEventType:u},t);i.has_next_page=c.has_next_page,i.next_cursor=c.next_cursor,c.data.forEach(d=>{let p=d.parsedJson;p&&n.push({id:p.pool_id,tick_spacing:p.tick_spacing,coin_type_a:hu(p.coin_type_a).full_address,coin_type_b:hu(p.coin_type_b).full_address})})}catch(u){return Ns("FetchError",u,{[Dt.METHOD_NAME]:"getPoolImmutables"})}return i.data=n,s&&this._sdk.updateCache(`${r}_getPoolImmutables`,n,Id),i}async getPoolsWithPage(t="all",e=!1){let r={data:[],has_next_page:!1},n=await this.getPoolImmutablesWithPage(t,e),i=await this._sdk.FullClient.batchGetObjects(n.data.map(s=>s.id),{showContent:!0,showType:!0});for(let s of i){(s.error!=null||s.data?.content?.dataType!=="moveObject")&&St("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[Dt.METHOD_NAME]:"getPoolsWithPage"});let o=zy(s);r.data.push(o);let u=`${o.id}_getPoolObject`;this._sdk.updateCache(u,o,Id)}return r.has_next_page=n.has_next_page,r.next_cursor=n.next_cursor,r}async getPoolLiquiditySnapshot(t,e=!1){try{let r=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:cH}}),n=Su.parsePoolLiquiditySnapshot(r);if(e){let i=(await this._sdk.FullClient.getDynamicFieldsByPage(n.snapshots.id)).data.map(s=>s.objectId);if(i.length>0){let s=await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0}),o=[];s.forEach(u=>{let c=Su.parsePositionSnapshot(u);o.push(c)}),n.position_snapshots=o}}return n}catch(r){return Ns("InvalidPoolObject",r,{[Dt.METHOD_NAME]:"getPoolLiquiditySnapshot",[Dt.REQUEST_PARAMS]:t})}}async getPositionSnapshot(t,e){let r=await this._sdk.FullClient.getDynamicFieldObjects(t,e,"0x2::object::ID","address"),n=[];return r.forEach(i=>{try{let s=Su.parsePositionSnapshot(i);n.push(s)}catch(s){console.log("getPositionSnapshot error: ",s)}}),n}async getAssignPools(t){if(t.length===0)return[];let e=[],r=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of r){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&St("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[Dt.METHOD_NAME]:"getAssignPools"});let i=zy(n);e.push(i);let s=`${i.id}_getPoolObject`;this._sdk.updateCache(s,i,Id)}return e}async getPool(t,e=!0,r=!1){let n=`${t}_getPoolObject`,i=this._sdk.getCache(n,e);if(i!==void 0)return i;let s=await this._sdk.FullClient.getObject({id:t,options:{showType:!0,showContent:!0}});(s.error!=null||s.data?.content?.dataType!=="moveObject")&&St("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[Dt.METHOD_NAME]:"getPool"});let o=zy(s);if(r){let u=await this.getPoolStatus(t);u&&(o.pool_status=u)}return this._sdk.updateCache(n,o),o}async getPoolByCoins(t,e){if(t.length===0)return[];for(let u=0;u<t.length;u++)t[u]==="0x2::sui::SUI"&&(t[u]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let r=this._sdk.sdkOptions.stats_pools_url;r||St("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[Dt.METHOD_NAME]:"getPoolByCoins"}),r+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${t.join(",")}`;let n=await fetch(r),i;try{i=await n.json()}catch(u){Ns("FetchError",u,{[Dt.METHOD_NAME]:"getPoolByCoins",[Dt.REQUEST_PARAMS]:r})}let s=i.data.lp_list,o=[];for(let u of s)t.includes(u.coin_a_address)&&t.includes(u.coin_b_address)&&(e!=null?u.object.feeRate===e&&o.push(u.address):o.push(u.address));return o.length>0?await this.getAssignPools(o):[]}async createPoolPayload(t,e){if(nT($e(t.coin_type_a),$e(t.coin_type_b))){let r=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=r;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidity(t,e)}async createPoolRowPayload(t,e){if(nT($e(t.coin_type_a),$e(t.coin_type_b))){let r=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=r;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidityRow(t,e)}async getClmmConfigs(t=!1){let{package_id:e}=this._sdk.sdkOptions.clmm_pool,r=`${e}_getInitEvent`,n=this._sdk.getCache(r,t);if(n!==void 0)return n;let i=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),s=BW(i),o=(await this._sdk.FullClient.queryEventsByPage({Transaction:s})).data,u={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return o.length>0&&(o.forEach(c=>{let d=c.parsedJson;if(c.type)switch(hu(c.type).full_address){case`${e}::config::InitConfigEvent`:u.global_config_id=d.global_config_id,u.admin_cap_id=d.admin_cap_id;break;case`${e}::factory::InitFactoryEvent`:u.pools_id=d.pools_id;break;case`${e}::rewarder::RewarderInitEvent`:u.global_vault_id=d.global_vault_id;break;case`${e}::partner::InitPartnerEvent`:u.partners_id=d.partners_id;break;default:break}}),this._sdk.updateCache(r,u,Id)),u}async getPoolTransactionList({pool_id:t,pagination_args:e,order:r="descending",full_rpc_url:n}){let{FullClient:i,sdkOptions:s}=this._sdk,o;n?o=NW(new Ps({url:n})):o=i;let u={data:[],has_next_page:!1},c=50,d=e,p=e.limit||10;do{let _=await o.queryTransactionBlocksByPage({ChangedObject:t},{...d,limit:50},r);_.data.forEach((b,O)=>{u.next_cursor=_.next_cursor;let T=PW(b,O,s.clmm_pool.package_id,t);u.data=[...u.data,...T]}),u.has_next_page=_.has_next_page,u.next_cursor=_.next_cursor,d.cursor=_.next_cursor}while(u.data.length<p&&u.has_next_page);return u.data.length>p&&(u.data=u.data.slice(0,p),u.next_cursor=u.data[u.data.length-1].tx),u}async calculateCreatePoolWithPrice(t){let{current_price:e,slippage:r,tick_spacing:n,add_mode_params:i,price_base_coin:s,coin_decimals_a:o,coin_decimals_b:u}=t,c=Ky.priceToSqrtPriceX64(s==="coin_a"?du(e):du(1).div(e),o,u),d=0,p=0;if(i.is_full_range)d=iT.getMinIndex(n),p=iT.getMaxIndex(n);else{let{min_price:H,max_price:J}=i;d=Ky.priceToInitializeTickIndex(s==="coin_a"?du(H):du(1).div(J),o,u,n),p=Ky.priceToInitializeTickIndex(s==="coin_a"?du(J):du(1).div(H),o,u,n)}let{coin_amount:_,fix_amount_a:b}=t,{coin_amount_limit_a:O,coin_amount_limit_b:T,liquidity_amount:x,coin_amount_a:F,coin_amount_b:R}=jW.estLiquidityAndCoinAmountFromOneAmounts(d,p,new uH.default(_),b,!0,r,c);return{coin_amount_a:F,coin_amount_b:R,coin_amount_limit_a:O,coin_amount_limit_b:T,liquidity:x,initialize_sqrt_price:c.toString(),tick_lower:d,tick_upper:p,fix_amount_a:b}}async createPoolAndAddLiquidity(t,e){e=e||new ot,e.setSender(this.sdk.getSenderAddress());let{integrate:r,clmm_pool:n}=this.sdk.sdkOptions,i=Wy(n),s=i.global_config_id,o=i.pools_id,u=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=Td.buildCoinForAmount(e,u,BigInt(t.amount_a),t.coin_type_a,!1,!0),d=Td.buildCoinForAmount(e,u,BigInt(t.amount_b),t.coin_type_b,!1,!0),p=[e.object(s),e.object(o),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number(fu(BigInt(t.tick_lower)).toString())),e.pure.u32(Number(fu(BigInt(t.tick_upper)).toString())),c.target_coin,d.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(rT)];return e.moveCall({target:`${r.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:p}),c_(this._sdk,e,c.target_coin,t.coin_type_a),c_(this._sdk,e,d.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new ot;let{clmm_pool:r}=this.sdk.sdkOptions,n=Wy(r),i=n.global_config_id,s=n.pools_id,o=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),u=Td.buildCoinForAmount(e,o,BigInt(t.amount_a),t.coin_type_a,!1,!0),c=Td.buildCoinForAmount(e,o,BigInt(t.amount_b),t.coin_type_b,!1,!0),d=[e.object(i),e.object(s),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number(fu(BigInt(t.tick_lower)).toString())),e.pure.u32(Number(fu(BigInt(t.tick_upper)).toString())),u.target_coin,c.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(rT)],p=e.moveCall({target:`${r.published_at}::pool_creator::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:d});return{tx:e,pos_id:p[0],remain_coin_a:p[1],remain_coin_b:p[2],remain_coin_type_a:t.coin_type_a,remain_coin_type_b:t.coin_type_b}}async createPoolWithPriceReturnPositionPayload(t,e){let{coin_type_a:r,coin_type_b:n,tick_spacing:i,uri:s,calculate_result:o}=t,{initialize_sqrt_price:u,tick_lower:c,tick_upper:d,liquidity:p,coin_amount_a:_,coin_amount_b:b,fix_amount_a:O,coin_amount_limit_a:T,coin_amount_limit_b:x}=o,F=await this._sdk.FullClient.fetchCoinMetadata(r),R=await this._sdk.FullClient.fetchCoinMetadata(n);if(F===null)return St("FetchError",`fetch coin ${r} metadata failed`,{[Dt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[Dt.REQUEST_PARAMS]:t});if(R===null)return St("FetchError",`fetch coin ${n} metadata failed`,{[Dt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[Dt.REQUEST_PARAMS]:t});let H=F.id,J=R.id;return this.createPoolRowPayload({tick_spacing:i,initialize_sqrt_price:u,uri:s||"",coin_type_a:r,coin_type_b:n,amount_a:O?_:T,amount_b:O?x:b,fix_amount_a:O,tick_lower:c,tick_upper:d,metadata_a:H,metadata_b:J},e)}async createPoolWithPricePayload(t){let{coin_type_a:e,coin_type_b:r,tick_spacing:n,uri:i,calculate_result:s}=t,{initialize_sqrt_price:o,tick_lower:u,tick_upper:c,liquidity:d,coin_amount_a:p,coin_amount_b:_,fix_amount_a:b,coin_amount_limit_a:O,coin_amount_limit_b:T}=s,x=await this._sdk.FullClient.fetchCoinMetadata(e),F=await this._sdk.FullClient.fetchCoinMetadata(r);if(x===null)return St("FetchError",`fetch coin ${e} metadata failed`,{[Dt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[Dt.REQUEST_PARAMS]:t});if(F===null)return St("FetchError",`fetch coin ${r} metadata failed`,{[Dt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[Dt.REQUEST_PARAMS]:t});let R=x.id,H=F.id;return this.createPoolPayload({tick_spacing:n,initialize_sqrt_price:o,uri:i||"",coin_type_a:e,coin_type_b:r,amount_a:b?p:O,amount_b:b?T:_,fix_amount_a:b,tick_lower:u,tick_upper:c,metadata_a:R,metadata_b:H})}async fetchTicks(t){let e=[],r=[];for(;;){let n=await this.getTicks({pool_id:t.pool_id,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,start:r,limit:512});if(e=[...e,...n],n.length<512)break;r=[Number(fu(BigInt(n[n.length-1].index)))]}return e}async getTicks(t){let{integrate:e}=this.sdk.sdkOptions,r=[],n=[t.coin_type_a,t.coin_type_b],i=new ot,s=i.makeMoveVec({elements:t.start.map(c=>i.pure.u32(c)),type:"u32"}),o=[i.object(t.pool_id),s,i.pure.u64(t.limit.toString())];i.moveCall({target:`${e.published_at}::${ku}::fetch_ticks`,arguments:o,typeArguments:n});let u=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:$e("0x0")});return u.error!=null&&St("InvalidTickObjectId",`getTicks error code: ${u.error??"unknown error"}, please check config and tick object ids`,{[Dt.METHOD_NAME]:"getTicks",[Dt.REQUEST_PARAMS]:t}),u.events?.forEach(c=>{hu(c.type).name==="FetchTicksResultEvent"&&c.parsedJson.ticks.forEach(d=>{r.push(TW(d))})}),r}async fetchPoolPositionInfoList(t){let{integrate:e}=this.sdk.sdkOptions,r=[],n=[],i=512;for(;;){let s=[t.coin_type_a,t.coin_type_b],o=new ot,u=o.pure.vector("id",n.map(_=>_)),c=[o.object(t.pool_id),u,o.pure.u64(i)];o.moveCall({target:`${e.published_at}::${ku}::fetch_positions`,arguments:c,typeArguments:s});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:o,sender:$e("0x0")});d.error!=null&&St("InvalidPositionRewardObject",`fetch position info error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[Dt.METHOD_NAME]:"fetchPoolPositionInfoList",[Dt.REQUEST_PARAMS]:t});let p=[];if(d?.events?.forEach(_=>{hu(_.type).name==="FetchPositionsEvent"&&_.parsedJson.positions.forEach(b=>{let O=u_(b);p.push(O)})}),r.push(...p),p.length<i)break;n=[p[p.length-1].pos_object_id]}return r}async fetchTicksByRpc(t){let e=[],r=null,n=50;for(;;){let i=[],s=await this.sdk.FullClient.getDynamicFields({parentId:t,cursor:r,limit:n});if(r=s.nextCursor,s.data.forEach(o=>{hu(o.objectType).module==="skip_list"&&i.push(o.objectId)}),e=[...e,...await this.getTicksByRpc(i)],!s.hasNextPage)break}return e}async getTicksByRpc(t){let e=[],r=await this.sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of r){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&St("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[Dt.METHOD_NAME]:"getTicksByRpc"});let i=Hy(n);i!=null&&e.push(i)}return e}async getTickDataByIndex(t,e){let r={type:"u64",value:fu(BigInt(RW(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:r});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&St("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[Dt.METHOD_NAME]:"getTickDataByIndex"}),Hy(n)}async getTickDataByObjectId(t){let e=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0}});return(e.error!=null||e.data?.content?.dataType!=="moveObject")&&St("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[Dt.METHOD_NAME]:"getTickDataByObjectId"}),Hy(e)}async getPartnerRefFeeAmount(t,e=!0){let r=await this._sdk.FullClient.batchGetObjects([t],{showOwner:!0,showContent:!0,showDisplay:e,showType:!0});r[0].data?.content?.dataType!=="moveObject"&&St("NotFoundPartnerObject",`get partner by object id: ${t} error: ${r[0].error}`,{[Dt.METHOD_NAME]:"getPartnerRefFeeAmount"});let n=r[0].data.content.fields.balances,i=await this._sdk.FullClient.getDynamicFieldsByPage(n.fields.id.id),s=[];i.data.forEach(u=>{u.objectId!=null&&s.push(u.objectId)});let o=[];return(await this._sdk.FullClient.batchGetObjects(s,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(u=>{(u.error!=null||u.data?.content?.dataType!=="moveObject")&&St("InvalidPartnerRefFeeFields",`get coin by object id: ${u.data.objectId} error: ${u.error}`,{[Dt.METHOD_NAME]:"getPartnerRefFeeAmount"});let c={coin_type:u.data.content.fields.name,coin_object_id:u.data.objectId,balance:BigInt(u.data.content.fields.value)};o.push(c)}),o}async claimPartnerRefFeePayload(t,e,r){let n=new ot,{clmm_pool:i}=this.sdk.sdkOptions,{global_config_id:s}=Wy(i),o=[r],u=[n.object(s),n.object(t),n.object(e)];return n.moveCall({target:`${i.published_at}::${bH}::claim_ref_fee`,arguments:u,typeArguments:o}),n}async getPoolStatus(t){try{let e=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:"pool_status"}}),r=DW(e).position.fields.status;if(r)return r}catch(e){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",e)}}},xd=Ds(Bs()),GW=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.clmm_pool.package_id}::position::Position`}async getPositionTransactionList({pos_id:t,origin_pos_id:e,full_rpc_url:r,pagination_args:n="all",order:i="ascending"}){let{FullClient:s}=this._sdk,o=[t];e&&o.push(e);let u;r?u=VW(new Ps({url:r})):u=s;let c={data:[],has_next_page:!1};try{let d=await u.queryTransactionBlocksByPage({ChangedObject:t},n,i);return d.data.forEach((p,_)=>{let b=xW(p,_,o);c.data=[...c.data,...b]}),c.has_next_page=d.has_next_page,c.next_cursor=d.next_cursor,c}catch(d){Ns("FetchError",d,{[Eo.METHOD_NAME]:"getPositionTransactionList"})}return c}async getPositionList(t,e=[],r=!0){let n=[],i=await this._sdk.FullClient.getOwnedObjectsByPage(t,{options:{showType:!0,showContent:!0,showDisplay:r,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),s=e.length>0;for(let o of i.data)if(qW(o.data.type).full_address===this.buildPositionType()){let u=Gy(o),c=`${u.pos_object_id}_getPositionList`;this._sdk.updateCache(c,u),s?e.includes(u.pool)&&n.push(u):n.push(u)}return n}async getPosition(t,e,r=!0,n=!0){let i=await this.getSimplePosition(e,n);return r&&(i=await this.updatePositionInfo(t,i)),i}async getPositionById(t,e=!0,r=!0){let n=await this.getSimplePosition(t,r);if(e){let i=await this._sdk.Pool.getPool(n.pool,!1);return await this.updatePositionInfo(i.position_manager.positions_handle,n)}return n}async getSimplePosition(t,e=!0){let r=`${t}_getPositionList`,n=this.getSimplePositionByCache(t);if(n===void 0){let i=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0,showType:!0,showDisplay:e,showOwner:!0}});n=Gy(i),this._sdk.updateCache(r,n)}return n}getSimplePositionByCache(t){let e=`${t}_getPositionList`;return this._sdk.getCache(e)}async getSimplePositionList(t,e=!0){let r=[],n=[];return t.forEach(i=>{let s=this.getSimplePositionByCache(i);s?r.push(s):n.push(i)}),n.length>0&&(await this._sdk.FullClient.batchGetObjects(n,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(i=>{if(i.error==null){let s=Gy(i);r.push(s);let o=`${s.pos_object_id}_getPositionList`;this._sdk.updateCache(o,s)}}),r}async updatePositionInfo(t,e){let r=await this.getPositionInfo(t,e.pos_object_id);return{...e,...r}}async getPositionInfo(t,e){try{let r=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x2::object::ID",value:e}}),n=cT(r.data).value.fields.value;return u_(n)}catch(r){return Ns("FetchError",r,{[Eo.METHOD_NAME]:"getPositionInfo",[Eo.REQUEST_PARAMS]:{position_handle:t,position_id:e}})}}async getPositionInfoList(t){try{let e=[],r=[];return t.forEach(async n=>{let{position_handle:i,position_ids:s}=n;s.forEach(o=>{let u=zW(i,o,"0x2::object::ID","address");r.push(u)})}),r.length===0?[]:((await this._sdk.FullClient.batchGetObjects(r,{showContent:!0,showType:!0,showOwner:!0})).forEach(n=>{try{let i=cT(n.data).value.fields.value,s=u_(i);e.push(s)}catch(i){console.log("getPositionInfoList error",i)}}),e)}catch(e){return Ns("FetchError",e,{[Eo.METHOD_NAME]:"getPositionInfoList",[Eo.REQUEST_PARAMS]:{options:t}})}}buildFetchPosFee(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,i=[t.coin_type_a,t.coin_type_b],s=[e.object(Cs(r).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${ku}::fetch_position_fees`,arguments:s,typeArguments:i})}parsedPosFeeData(t){let e={},r=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let n=0;n<r.length;n+=1){let{parsedJson:i}=r[n],s={position_id:i.position_id,fee_owned_a:i.fee_owned_a,fee_owned_b:i.fee_owned_b};e[i.position_id]=s}return e}async fetchPosFeeAmount(t){let{clmm_pool:e,integrate:r}=this.sdk.sdkOptions,n=new ot;for(let u of t)this.buildFetchPosFee(u,n);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:$e("0x0")});i.error!=null&&St("InvalidPoolObject",`fetch position fee error code: ${i.error??"unknown error"}, please check config and position and pool object ids`,{[Eo.METHOD_NAME]:"fetchPosFeeAmount"});let s=[],o=this.parsedPosFeeData(i);for(let u=0;u<t.length;u+=1){let c=o[t[u].position_id];if(c){let d={fee_owned_a:c.fee_owned_a,fee_owned_b:c.fee_owned_b,position_id:t[u].position_id};s.push(d)}}return s}async batchFetchPositionFees(t){let e=[];for(let n of t){let i=await this._sdk.Position.getPositionById(n,!1),s=await this._sdk.Pool.getPool(i.pool,!1);e.push({pool_id:s.id,position_id:i.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b})}let r={};if(e.length>0){let n=await this.fetchPosFeeAmount(e);for(let i of n)r[i.position_id]=i;return r}return r}async createAddLiquidityFixTokenPayload(t,e,r,n,i){let s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:o,is_adjust_coin_b:u}=Fd(t);if(t=t,t.fix_amount_a&&o||!t.fix_amount_a&&u)return r=await _a.buildAddLiquidityFixTokenForGas(this._sdk,s,t,e,r,n,i),r}return _a.buildAddLiquidityFixToken(this._sdk,s,t,r,n,i)}async createAddLiquidityPayload(t,e,r,n){let{integrate:i,clmm_pool:s}=this._sdk.sdkOptions,o=pu(BigInt(t.tick_lower)).toString(),u=pu(BigInt(t.tick_upper)).toString(),c=[t.coin_type_a,t.coin_type_b];e=e||new ot;let d=!Fs(t.pos_id),p=BigInt(t.max_amount_a),_=BigInt(t.max_amount_b),b,O;if(r==null||n==null){let T=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());b=Cd.buildCoinForAmount(e,T,p,t.coin_type_a,!1,!0),O=Cd.buildCoinForAmount(e,T,_,t.coin_type_b,!1,!0)}else b={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},O={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(d)e.moveCall({target:`${i.published_at}::${Mu}::open_position_with_liquidity`,typeArguments:c,arguments:[e.object(Cs(s).global_config_id),e.object(t.pool_id),e.pure.u32(Number(o)),e.pure.u32(Number(u)),b.target_coin,O.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(Pd)]});else{let T=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=_a.createCollectRewarderAndFeeParams(this._sdk,e,t,T,b.remain_coins,O.remain_coins),e.moveCall({target:`${i.published_at}::${Mu}::add_liquidity`,typeArguments:c,arguments:[e.object(Cs(s).global_config_id),e.object(t.pool_id),e.object(t.pos_id),b.target_coin,O.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(Pd)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,i="remove_liquidity";e=e||new ot;let s=[t.coin_type_a,t.coin_type_b],o=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=_a.createCollectRewarderAndFeeParams(this._sdk,e,t,o);let u=[e.object(Cs(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u128(t.delta_liquidity),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(Pd)];return e.moveCall({target:`${n.published_at}::${Ad}::${i}`,typeArguments:s,arguments:u}),e}async closePositionPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;e=e||new ot;let i=[t.coin_type_a,t.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=_a.createCollectRewarderAndFeeParams(this._sdk,e,t,s),e.moveCall({target:`${n.published_at}::${Ad}::close_position`,typeArguments:i,arguments:[e.object(Cs(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(Pd)]}),e}openPositionPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;e=e||new ot;let i=[t.coin_type_a,t.coin_type_b],s=pu(BigInt(t.tick_lower)).toString(),o=pu(BigInt(t.tick_upper)).toString(),u=[e.object(Cs(r).global_config_id),e.object(t.pool_id),e.pure.u32(Number(s)),e.pure.u32(Number(o))];return e.moveCall({target:`${n.published_at}::${Ad}::open_position`,typeArguments:i,arguments:u}),e}async openPositionWithPricePayload(t,e){let{pool_id:r}=t,{clmm_pool:n,integrate:i}=this.sdk.sdkOptions;e=e||new ot;let s=await this.sdk.Pool.getPool(r,!1),o=Number(s.tick_spacing),u=0,c=0;if(t.is_full_range)u=jd.getMinIndex(o),c=jd.getMaxIndex(o);else{let{price_base_coin:_,min_price:b,max_price:O}=t;u=mu.priceToInitializeTickIndex(_==="coin_a"?rs(b):rs(1).div(O),t.coin_decimals_a,t.coin_decimals_b,o),c=mu.priceToInitializeTickIndex(_==="coin_a"?rs(O):rs(1).div(b),t.coin_decimals_a,t.coin_decimals_b,o)}let d=[s.coin_type_a,s.coin_type_b],p=[e.object(Cs(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number(pu(BigInt(u)))),e.pure.u32(Number(pu(BigInt(c))))];return e.moveCall({target:`${i.published_at}::${Ad}::open_position`,typeArguments:d,arguments:p}),e}async collectFeePayload(t,e,r,n){e=e||new ot;let i=r||Cd.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),s=n||Cd.buildCoinWithBalance(BigInt(0),t.coin_type_b,e);return this.createCollectFeePayload(t,e,i,s),e}createCollectFeePayload(t,e,r,n){let{clmm_pool:i,integrate:s}=this.sdk.sdkOptions,o=[t.coin_type_a,t.coin_type_b],u=[e.object(Cs(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),r,n];return e.moveCall({target:`${s.published_at}::${Mu}::collect_fee`,typeArguments:o,arguments:u}),e}async calculateAddLiquidityResultWithPrice(t){let{pool_id:e,slippage:r,refresh_pool_price:n,add_mode_params:i}=t,s=await this.sdk.Pool.getPool(e,n),o=Number(s.tick_spacing),u=0,c=0;if(i.is_full_range)u=jd.getMinIndex(o),c=jd.getMaxIndex(o);else{let{price_base_coin:F,min_price:R,max_price:H}=i;u=mu.priceToInitializeTickIndex(F==="coin_a"?rs(R):rs(1).div(H),i.coin_decimals_a,i.coin_decimals_b,o),c=mu.priceToInitializeTickIndex(F==="coin_a"?rs(H):rs(1).div(R),i.coin_decimals_a,i.coin_decimals_b,o)}if("liquidity"in t){let{liquidity:F}=t,R=mu.tickIndexToSqrtPriceX64(u),H=mu.tickIndexToSqrtPriceX64(c),{coin_amount_a:J,coin_amount_b:ee}=uT.getCoinAmountFromLiquidity(new xd.default(F),new xd.default(s.current_sqrt_price),R,H,!1),ae=rs(J).mul(1+r).toFixed(0,Tr.ROUND_UP),te=rs(ee).mul(1+r).toFixed(0,Tr.ROUND_UP);return{coin_amount_a:J,coin_amount_b:ee,coin_amount_limit_a:ae,coin_amount_limit_b:te,liquidity:F,tick_lower:u,tick_upper:c}}let{coin_amount:d,fix_amount_a:p}=t,{coin_amount_limit_a:_,coin_amount_limit_b:b,liquidity_amount:O,coin_amount_a:T,coin_amount_b:x}=uT.estLiquidityAndCoinAmountFromOneAmounts(u,c,new xd.default(d),p,!0,r,new xd.default(s.current_sqrt_price));return{coin_amount_a:T,coin_amount_b:x,coin_amount_limit_a:_,coin_amount_limit_b:b,liquidity:O,tick_lower:u,tick_upper:c,fix_amount_a:p}}async addLiquidityWithPricePayload(t,e,r,n){let{pool_id:i,calculate_result:s}=t,{coin_amount_limit_a:o,coin_amount_limit_b:u,liquidity:c,tick_lower:d,tick_upper:p}=s;e=e||new ot;let _=await this.sdk.Pool.getPool(i,!1);return await this.createAddLiquidityPayload({delta_liquidity:c,max_amount_a:o,max_amount_b:u,tick_lower:d,tick_upper:p,collect_fee:!1,rewarder_coin_types:[],coin_type_a:_.coin_type_a,coin_type_b:_.coin_type_b,pool_id:i,pos_id:""},e,r,n),e}async createAddLiquidityFixCoinWithPricePayload(t,e,r,n){let{pool_id:i,calculate_result:s}=t,{coin_amount_limit_a:o,coin_amount_limit_b:u,liquidity:c,tick_lower:d,tick_upper:p,fix_amount_a:_,coin_amount_a:b,coin_amount_b:O}=s;if(_===void 0)throw St("InvalidParams","fix_amount_a is undefined",{[Eo.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[Eo.REQUEST_PARAMS]:t});e=e||new ot;let T=await this.sdk.Pool.getPool(i,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:_?b:o,amount_b:_?u:O,slippage:0,fix_amount_a:_,is_open:!0,tick_lower:d,tick_upper:p,collect_fee:!1,rewarder_coin_types:[],coin_type_a:T.coin_type_a,coin_type_b:T.coin_type_b,pool_id:i,pos_id:""},void 0,e,r,n),e}createCollectFeeNoSendPayload(t,e,r,n){let{clmm_pool:i,integrate:s}=this.sdk.sdkOptions,o=[t.coin_type_a,t.coin_type_b],u=[e.object(Cs(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),r,n];return e.moveCall({target:`${s.published_at}::${xT}::collect_fee`,typeArguments:o,arguments:u}),e}},lT=Ds(Bs()),WW=class{constructor(t){this._sdk=t,this.growthGlobal=[gu,gu,gu]}get sdk(){return this._sdk}async emissionsEveryDay(t){let e=(await this.sdk.Pool.getPool(t)).rewarder_infos;if(!e)return null;let r=[];for(let n of e){let i=HW.fromX64(new lT.default(n.emissions_per_second));r.push({emissions:Math.floor(i.toNumber()*60*60*24),coin_type:n.coin_type})}return r}async batchFetchPositionRewarders(t){let e=[];for(let n of t){let i=await this._sdk.Position.getPositionById(n,!1),s=await this._sdk.Pool.getPool(i.pool,!1);e.push({pool_id:s.id,position_id:i.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b,rewarder_types:s.rewarder_infos.map(o=>o.coin_type)})}let r={};if(e.length>0){let n=await this.fetchPosRewardersAmount(e);for(let i of n)r[i.position_id]=i.rewarder_amounts;return r}return r}async fetchPositionRewarders(t,e){let r={pool_id:t.id,position_id:e,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,rewarder_types:t.rewarder_infos.map(n=>n.coin_type)};return(await this.fetchPosRewardersAmount([r]))[0].rewarder_amounts}async batchFetchPositionFees(t){return await this._sdk.Position.batchFetchPositionFees(t)}async fetchPosFeeAmount(t){return await this._sdk.Position.fetchPosFeeAmount(t)}buildFetchPosReward(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,i=[t.coin_type_a,t.coin_type_b],s=[e.object(Yy(r).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Jy)];e.moveCall({target:`${n.published_at}::${ku}::fetch_position_rewards`,arguments:s,typeArguments:i})}async fetchPosRewardersAmount(t){let e=new ot;for(let s of t)this.buildFetchPosReward(s,e);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:$e("0x")});r.error!=null&&St("InvalidConfig",`fetch position rewards error code: ${r.error??"unknown error"}, please check config and params`,{[fT.METHOD_NAME]:"fetchPosRewardersAmount",[fT.REQUEST_PARAMS]:{params:t}});let n=this.parsedPosRewardData(r),i=[];for(let s=0;s<t.length;s+=1){let o=n[t[s].position_id];if(o){let u={pool_id:t[s].pool_id,position_id:t[s].position_id,rewarder_amounts:o.rewarder_amount.map((c,d)=>({amount_owned:c,coin_type:t[s].rewarder_types[d]}))};i.push(u)}}return i}parsedPosRewardData(t){let e={},r=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let n=0;n<r.length;n+=1){let{parsedJson:i}=r[n],s={position_id:i.position_id,rewarder_amount:i.data};e[i.position_id]=s}return e}async fetchPoolRewardersAmount(t,e){let r=await this.sdk.Pool.getPool(e),n=await this.sdk.Position.getPositionList(t,[e]),i=[];for(let u of n)i.push({pool_id:r.id,position_id:u.pos_object_id,rewarder_types:r.rewarder_infos.map(c=>c.coin_type),coin_type_a:r.coin_type_a,coin_type_b:r.coin_type_b});let s=await this.fetchPosRewardersAmount(i),o=[gu,gu,gu];if(s!=null)for(let u of s)for(let c=0;c<u.rewarder_amounts.length;c+=1)o[c]=o[c].add(new lT.default(u.rewarder_amounts[c].amount_owned));return o}async getPoolLowerAndUpperTicks(t,e){let r=[],n=[];for(let i of e){let s=await this.sdk.Pool.getTickDataByIndex(t,i.tick_lower_index),o=await this.sdk.Pool.getTickDataByIndex(t,i.tick_upper_index);r.push(s),n.push(o)}return[r,n]}async collectRewarderPayload(t){let e=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),r=new ot;return r=_a.createCollectRewarderAndFeeParams(this._sdk,r,t,e),r}async batchCollectRewardsPayload(t,e,r,n){let i=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);e=e||new ot;let s={};return t.forEach(o=>{let u=Qy(o.coin_type_a),c=Qy(o.coin_type_b);if(o.collect_fee){let p=s[u];p==null&&(r==null?p=Zy.buildCoinForAmount(e,i,BigInt(0),u,!1):p={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[u]=p);let _=s[c];_==null&&(n==null?_=Zy.buildCoinForAmount(e,i,BigInt(0),c,!1):_={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[c]=_),e=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:o.pool_id,pos_id:o.pos_id,coin_type_a:o.coin_type_a,coin_type_b:o.coin_type_b},e,p.target_coin,_.target_coin)}let d=[];o.rewarder_coin_types.forEach(p=>{let _=Qy(p),b=s[p];b===void 0&&(b=Zy.buildCoinForAmount(e,i,BigInt(0),_,!1),s[_]=b),d.push(b.target_coin)}),e=this.createCollectRewarderNoSendPayload(o,e,d)}),Object.keys(s).forEach(o=>{let u=s[o];u.is_mint_zero_coin&&CW(this.sdk,e,u.target_coin,o,this.sdk.getSenderAddress())}),e}createCollectRewarderPayload(t,e,r){let{clmm_pool:n,integrate:i}=this.sdk.sdkOptions,s=Yy(n),o=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((u,c)=>{e&&e.moveCall({target:`${i.published_at}::${Mu}::collect_reward`,typeArguments:[...o,u],arguments:[e.object(s.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(s.global_vault_id),r[c],e.object(Jy)]})}),e}createCollectRewarderNoSendPayload(t,e,r){let{clmm_pool:n,integrate:i}=this.sdk.sdkOptions,s=Yy(n),o=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((u,c)=>{e&&e.moveCall({target:`${i.published_at}::${xT}::collect_reward`,typeArguments:[...o,u],arguments:[e.object(s.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(s.global_vault_id),r[c],e.object(Jy)]})}),e}},yu=Ds(Bs());var JW=class{constructor(t){this.calculateSingleImpact=(e,r)=>r.minus(e).div(r).mul(100),this._sdk=t}get sdk(){return this._sdk}calculateSwapFee(t){let e=_u(0);return t.forEach(r=>{let n=r.base_paths.length;if(n>0){let i=r.base_paths[0],s=i.label==="Cetus"?new Tr(i.fee_rate).div(10**6):new Tr(i.fee_rate).div(10**9),o=_u(i.input_amount).div(10**i.from_decimal).mul(s);if(e=e.add(o),n>1){let u=r.base_paths[1],c=i.direction?i.current_price:new Tr(1).div(i.current_price),d=u.direction?u.current_price:new Tr(1).div(u.current_price),p=u.label==="Cetus"?new Tr(u.fee_rate).div(10**6):new Tr(u.fee_rate).div(10**9),_=_u(u.output_amount).div(10**u.to_decimal).mul(p).div(c.mul(d));e=e.add(_)}}}),e.toString()}calculateSwapPriceImpact(t){let e=_u(0);return t.forEach(r=>{let n=r.base_paths.length;if(n===1){let i=r.base_paths[0],s=_u(i.output_amount).div(10**i.to_decimal),o=_u(i.input_amount).div(10**i.from_decimal),u=s.div(o),c=i.direction?new Tr(i.current_price):new Tr(1).div(i.current_price);e=e.add(this.calculateSingleImpact(u,c))}if(n===2){let i=r.base_paths[0],s=r.base_paths[1],o=i.direction?new Tr(i.current_price):new Tr(1).div(i.current_price),u=s.direction?new Tr(s.current_price):new Tr(1).div(s.current_price),c=o.mul(u),d=new Tr(s.output_amount).div(10**s.to_decimal),p=new Tr(i.input_amount).div(10**i.from_decimal),_=d.div(p);e=e.add(this.calculateSingleImpact(_,c))}}),e.toString()}async preSwapWithMultiPool(t){let{integrate:e}=this.sdk.sdkOptions,r=new ot,n=[t.coin_type_a,t.coin_type_b];for(let c=0;c<t.pool_ids.length;c+=1){let d=[r.object(t.pool_ids[c]),r.pure.bool(t.a2b),r.pure.bool(t.by_amount_in),r.pure.u64(t.amount)];r.moveCall({target:`${e.published_at}::${ku}::calculate_swap_result`,arguments:d,typeArguments:n})}let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:$e("0x0")});i.error!=null&&St("InvalidConfig",`pre swap with multi pools error code: ${i.error??"unknown error"}, please check config and params`,{[Ao.METHOD_NAME]:"preSwapWithMultiPool",[Ao.REQUEST_PARAMS]:{params:t}});let s=i.events?.filter(c=>dT(c.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==t.pool_ids.length&&St("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[Ao.METHOD_NAME]:"preSwapWithMultiPool",[Ao.REQUEST_PARAMS]:{params:t}});let o=t.by_amount_in?XW:KW,u=0;for(let c=0;c<s.length;c+=1)if(!s[c].parsedJson.data.is_exceed)if(t.by_amount_in){let d=new yu.default(s[c].parsedJson.data.amount_out);d.gt(o)&&(u=c,o=d)}else{let d=new yu.default(s[c].parsedJson.data.amount_out);d.lt(o)&&(u=c,o=d)}return this.transformSwapWithMultiPoolData({pool_address:t.pool_ids[u],a2b:t.a2b,by_amount_in:t.by_amount_in,amount:t.amount,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b},s[u].parsedJson)}async preSwap(t){let{integrate:e}=this.sdk.sdkOptions,r=new ot,n=[t.coin_type_a,t.coin_type_b],i=[r.object(t.pool.id),r.pure.bool(t.a2b),r.pure.bool(t.by_amount_in),r.pure.u64(t.amount)];r.moveCall({target:`${e.published_at}::${ku}::calculate_swap_result`,arguments:i,typeArguments:n});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:$e("0x0")});if(s.error!=null)return St("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ao.METHOD_NAME]:"preSwap",[Ao.REQUEST_PARAMS]:{params:t}});let o=s.events?.filter(u=>dT(u.type).name==="CalculatedSwapResultEvent");return o.length===0?St("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ao.METHOD_NAME]:"preSwap",[Ao.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,o[0].parsedJson.data)}transformSwapData(t,e){let r=e.amount_in&&e.fee_amount?new yu.default(e.amount_in).add(new yu.default(e.fee_amount)).toString():"";return{pool_address:t.pool.id,current_sqrt_price:t.current_sqrt_price,estimated_amount_in:r,estimated_amount_out:e.amount_out,estimated_end_sqrt_price:e.after_sqrt_price,estimated_fee_amount:e.fee_amount,is_exceed:e.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}transformSwapWithMultiPoolData(t,e){let{data:r}=e;console.log("json data. ",r);let n=r.amount_in&&r.fee_amount?new yu.default(r.amount_in).add(new yu.default(r.fee_amount)).toString():"";return{pool_address:t.pool_address,estimated_amount_in:n,estimated_amount_out:r.amount_out,estimated_end_sqrt_price:r.after_sqrt_price,estimated_start_sqrt_price:r.step_results[0].current_sqrt_price,estimated_fee_amount:r.fee_amount,is_exceed:r.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}calculateRates(t){let{current_pool:e}=t,r=bW(e),n;t.a2b?n=t.swap_ticks.sort((_,b)=>b.index-_.index):n=t.swap_ticks.sort((_,b)=>_.index-b.index);let i=MW(t.a2b,t.by_amount_in,t.amount,r,n),s=!1;t.by_amount_in?s=i.amount_in.lt(t.amount):s=i.amount_out.lt(t.amount);let o=vu.getDefaultSqrtPriceLimit(t.a2b);t.a2b&&i.next_sqrt_price.lt(o)&&(s=!0),!t.a2b&&i.next_sqrt_price.gt(o)&&(s=!0);let u=0;i.cross_tick_num>6&&i.cross_tick_num<40&&(u=22e3*(i.cross_tick_num-6)),i.cross_tick_num>40&&(s=!0);let c=hT.sqrtPriceX64ToPrice(r.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),d=hT.sqrtPriceX64ToPrice(i.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),p=Math.abs(c-d)/c*100;return{estimated_amount_in:i.amount_in,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.next_sqrt_price,estimated_fee_amount:i.fee_amount,is_exceed:s,extra_compute_limit:u,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in,price_impact_pct:p}}async createSwapPayload(t,e){let r=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:i}=Fd(t);if(t.a2b&&n||!t.a2b&&i)return await vu.buildSwapTransactionForGas(this._sdk,t,r,e)}return vu.buildSwapTransaction(this.sdk,t,r)}async createSwapWithoutTransferCoinsPayload(t,e){let r=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:i}=Fd(t);if(t.a2b&&n||!t.a2b&&i)return await vu.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,r,e)}return vu.buildSwapTransactionWithoutTransferCoins(this.sdk,t,r)}},QW=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getClmmVestInfoList(){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return St("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ga.METHOD_NAME]:"getClmmVestInfo"});let e=[];try{let r=`${t.package_id}::clmm_vester::CreateEvent`,n=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:r})).data.map(i=>i.parsedJson.clmm_vester_id);return n.length>0&&(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0})).forEach(i=>{let s=Su.parseClmmVestInfo(i),o=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(o,s),e.push(s)}),e}catch(r){Ns("ClmmVestFetchError",r,{[ga.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return St("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ga.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:r}=e_(e),n=`${r}-ClmmVestInfo`,i=this._sdk.getCache(n,t);if(i)return i;try{let s=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0,showType:!0}}),o=Su.parseClmmVestInfo(s);return this._sdk.updateCache(n,o),o}catch(s){return Ns("ClmmVestFetchError",s,{[ga.METHOD_NAME]:"getClmmVestInfo",[ga.REQUEST_PARAMS]:{clmm_vest_id:r}})}}async getPositionVesting(t){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return St("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ga.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:r}=e_(e),n=new ot;t.forEach(o=>{let{clmm_pool_id:u,coin_type_a:c,coin_type_b:d,clmm_position_ids:p}=o;n.moveCall({package:e.published_at,module:"clmm_vester",function:"get_positions_vesting",typeArguments:[c,d],arguments:[n.object(r),n.object(u),n.pure.vector("id",p)]})});let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:$e("0x0")}),s=[];return i.events?.forEach(o=>{if(o.type.includes("clmm_vester::GetPositionsVestingEvent")){let{parsedJson:u}=o;s.push(...u.position_vestings.map(c=>Su.parsePositionVesting(c)))}}),s}buildRedeemPayload(t,e){let{clmm_vest:r}=this._sdk.sdkOptions;if(r===void 0)return St("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ga.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:n,clmm_vest_id:i,cetus_coin_type:s}=e_(r);return e=e||new ot,t.forEach(o=>{let{clmm_pool_id:u,clmm_position_id:c,coin_type_a:d,coin_type_b:p,period:_}=o,b=e.moveCall({package:r.published_at,module:"clmm_vester",function:"redeem",arguments:[e.object(n),e.object(i),e.object(u),typeof c=="string"?e.object(c):c,e.pure.u16(_),e.object(ZW)],typeArguments:[d,p]}),O=YW.fromBalance(b,s,e);e.transferObjects([O],this._sdk.getSenderAddress())}),e}},pT={clmmConfig:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"},cetusConfig:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},tK={env:"mainnet",full_rpc_url:eK,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:pT.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:pT.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d",version:12},stats_pools_url:"https://api-sui.cetus.zone/v2/sui/stats_pools",clmm_vest:{package_id:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",published_at:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",version:1,config:{clmm_vest_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",versioned_id:"0x4f6f2f638362505836114f313809b834dafd58e3910df5110f6e54e4e35c929b",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"}}},nK={env:"testnet",full_rpc_url:rK,cetus_config:{package_id:"0x2933975c3f74ef7c31f512edead6c6ce3f58f8e8fdbea78770ec8d5abd8ff700",published_at:"0xb50a626294f743b40ea51c9cb75190f0e38c71f580981b5613aef910b67a2691",config:{coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"0x774656a83f4f625fcc4e4dbf103eb77caf2d8b8f114ad33f55b848be068267b9",global_config_id:"0x95275a022123c66682278e9df6b5bac4da9abcc29ab698b7b2a6213262a592fe",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""}},clmm_pool:{package_id:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",published_at:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",config:{pools_id:"0x20a086e6fa0741b3ca77d033a65faf0871349b986ddbdde6fa1d85d78a5f4222",global_config_id:"0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a",global_vault_id:"0x71e74a999dd7959e483f758ddf573e85fa4c24944db33ff6763c9d85a9c045fe",admin_cap_id:"0xbf4c48590f403c38351de0e8aa13d6d91bf78fd8c04e93ac1d0269c44d70ae02",partners_id:"0xb5ae5ed3f403654ae1307aadc0140f746db41efb7bda92235257c84d90a1397e"}},integrate:{package_id:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",published_at:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",version:1},stats_pools_url:"https://api-sui.devcetus.com/v2/sui/stats_pools",clmm_vest:{package_id:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",published_at:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",config:{clmm_vest_id:"0x308b24963e5992f699e32db2f7088b812566a0cae580317fd3b8bf61de7f5508",versioned_id:"0x1cfb684d8ff581416a56caba2aa419bee45fe98a23cbf28e2c6c1021b14cab7c",cetus_coin_type:"0xc6c51938da9a5cf6d6dca692783ea7bdf4478f7b1fef693f58947848f84bcf89::cetus::CETUS"}}},zT=class Rd extends DG{constructor(e){super(e),this._swap=new JW(this),this._pool=new FW(this),this._position=new GW(this),this._config=new aH(this),this._rewarder=new WW(this),this._vest=new QW(this)}get Pool(){return this._pool}get Position(){return this._position}get CetusConfig(){return this._config}get Rewarder(){return this._rewarder}get Swap(){return this._swap}get Vest(){return this._vest}static createSDK(e){let{env:r="mainnet"}=e;return r==="mainnet"?Rd.createCustomSDK({...tK,...e}):Rd.createCustomSDK({...nK,...e})}static createCustomSDK(e){return new Rd(e)}},Hd=Ds(Bs()),jte=new Hd.default(365),Nte=new Hd.default(24),Dte=new Hd.default(3600),Bte=new Hd.default(.5);import{SuiPriceServiceConnection as sK}from"@pythnetwork/pyth-sui-js";var Wd=class t extends iK{constructor(e,r){super(e),this._suilendModule=new gl(this),this._leverageModules=new Rl(this),this._aggregatorClient=new Gc.AggregatorClient({signer:$e("0x0"),client:e.sui_client||new Ps({url:e.full_rpc_url}),env:e.env==="testnet"?Gc.Env.Testnet:Gc.Env.Mainnet,pythUrls:e.pyth_urls}),this._clmmSDK=r||zT.createSDK({env:e.env,full_rpc_url:e.full_rpc_url}),this._pythConnection=new sK("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(e){return t.createCustomSDK({...g_,...e})}static createCustomSDK(e){return new t(e)}};var sre=Wd;export{Wd as CetusLeverageSDK,sre as default,g_ as leverage_mainnet};
10
22
  /*! Bundled license information:
11
23
 
12
24
  decimal.js/decimal.mjs:
@@ -20,6 +32,14 @@ decimal.js/decimal.mjs:
20
32
  */
21
33
  /*! Bundled license information:
22
34
 
35
+ @scure/base/lib/index.js:
36
+ @scure/base/lib/esm/index.js:
37
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
38
+
39
+ @noble/hashes/utils.js:
40
+ @noble/hashes/esm/utils.js:
41
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42
+
23
43
  @cetusprotocol/aggregator-sdk/dist/index.js:
24
44
  (*! Bundled license information:
25
45