lll-sdk 0.0.0-experimental-20250902142929 → 0.0.0-experimental-20250902143335

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.js CHANGED
@@ -1,24 +1,12 @@
1
- "use strict";var ZI=Object.create;var jc=Object.defineProperty;var YI=Object.getOwnPropertyDescriptor;var QI=Object.getOwnPropertyNames;var eT=Object.getPrototypeOf,tT=Object.prototype.hasOwnProperty;var Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),rT=(t,e)=>{for(var r in e)jc(t,r,{get:e[r],enumerable:!0})},By=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of QI(e))!tT.call(t,i)&&i!==r&&jc(t,i,{get:()=>e[i],enumerable:!(n=YI(e,i))||n.enumerable});return t};var Nc=(t,e,r)=>(r=t!=null?ZI(eT(t)):{},By(e||!t||!t.__esModule?jc(r,"default",{value:t,enumerable:!0}):r,t)),nT=t=>By(jc({},"__esModule",{value:!0}),t);var Z_=Me((J_,Th)=>{"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=require("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,me=h[6]|0,ze=me&8191,be=me>>>13,Pe=h[7]|0,qe=Pe&8191,ge=Pe>>>13,Fe=h[8]|0,Nt=Fe&8191,Te=Fe>>>13,st=h[9]|0,Tt=st&8191,Ie=st>>>13,He=y[0]|0,Et=He&8191,we=He>>>13,mt=y[1]|0,zt=mt&8191,Ce=mt>>>13,gt=y[2]|0,Gt=gt&8191,je=gt>>>13,yt=y[3]|0,Ht=yt&8191,Ne=yt>>>13,_t=y[4]|0,Wt=_t&8191,De=_t>>>13,vt=y[5]|0,Kt=vt&8191,Be=vt>>>13,bt=y[6]|0,Xt=bt&8191,Re=bt>>>13,wt=y[7]|0,Jt=wt&8191,Ue=wt>>>13,Mt=y[8]|0,Zt=Mt&8191,Le=Mt>>>13,St=y[9]|0,Yt=St&8191,$e=St>>>13;l.negative=m.negative^a.negative,l.length=19,w=Math.imul(V,Et),g=Math.imul(V,we),g=g+Math.imul(z,Et)|0,f=Math.imul(z,we);var pt=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(pt>>>26)|0,pt&=67108863,w=Math.imul(ce,Et),g=Math.imul(ce,we),g=g+Math.imul(E,Et)|0,f=Math.imul(E,we),w=w+Math.imul(V,zt)|0,g=g+Math.imul(V,Ce)|0,g=g+Math.imul(z,zt)|0,f=f+Math.imul(z,Ce)|0;var Zn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,w=Math.imul(j,Et),g=Math.imul(j,we),g=g+Math.imul(L,Et)|0,f=Math.imul(L,we),w=w+Math.imul(ce,zt)|0,g=g+Math.imul(ce,Ce)|0,g=g+Math.imul(E,zt)|0,f=f+Math.imul(E,Ce)|0,w=w+Math.imul(V,Gt)|0,g=g+Math.imul(V,je)|0,g=g+Math.imul(z,Gt)|0,f=f+Math.imul(z,je)|0;var Yn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,w=Math.imul(W,Et),g=Math.imul(W,we),g=g+Math.imul(q,Et)|0,f=Math.imul(q,we),w=w+Math.imul(j,zt)|0,g=g+Math.imul(j,Ce)|0,g=g+Math.imul(L,zt)|0,f=f+Math.imul(L,Ce)|0,w=w+Math.imul(ce,Gt)|0,g=g+Math.imul(ce,je)|0,g=g+Math.imul(E,Gt)|0,f=f+Math.imul(E,je)|0,w=w+Math.imul(V,Ht)|0,g=g+Math.imul(V,Ne)|0,g=g+Math.imul(z,Ht)|0,f=f+Math.imul(z,Ne)|0;var Qn=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,w=Math.imul(X,Et),g=Math.imul(X,we),g=g+Math.imul(G,Et)|0,f=Math.imul(G,we),w=w+Math.imul(W,zt)|0,g=g+Math.imul(W,Ce)|0,g=g+Math.imul(q,zt)|0,f=f+Math.imul(q,Ce)|0,w=w+Math.imul(j,Gt)|0,g=g+Math.imul(j,je)|0,g=g+Math.imul(L,Gt)|0,f=f+Math.imul(L,je)|0,w=w+Math.imul(ce,Ht)|0,g=g+Math.imul(ce,Ne)|0,g=g+Math.imul(E,Ht)|0,f=f+Math.imul(E,Ne)|0,w=w+Math.imul(V,Wt)|0,g=g+Math.imul(V,De)|0,g=g+Math.imul(z,Wt)|0,f=f+Math.imul(z,De)|0;var ei=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(ie,Et),g=Math.imul(ie,we),g=g+Math.imul(oe,Et)|0,f=Math.imul(oe,we),w=w+Math.imul(X,zt)|0,g=g+Math.imul(X,Ce)|0,g=g+Math.imul(G,zt)|0,f=f+Math.imul(G,Ce)|0,w=w+Math.imul(W,Gt)|0,g=g+Math.imul(W,je)|0,g=g+Math.imul(q,Gt)|0,f=f+Math.imul(q,je)|0,w=w+Math.imul(j,Ht)|0,g=g+Math.imul(j,Ne)|0,g=g+Math.imul(L,Ht)|0,f=f+Math.imul(L,Ne)|0,w=w+Math.imul(ce,Wt)|0,g=g+Math.imul(ce,De)|0,g=g+Math.imul(E,Wt)|0,f=f+Math.imul(E,De)|0,w=w+Math.imul(V,Kt)|0,g=g+Math.imul(V,Be)|0,g=g+Math.imul(z,Kt)|0,f=f+Math.imul(z,Be)|0;var ti=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(ze,Et),g=Math.imul(ze,we),g=g+Math.imul(be,Et)|0,f=Math.imul(be,we),w=w+Math.imul(ie,zt)|0,g=g+Math.imul(ie,Ce)|0,g=g+Math.imul(oe,zt)|0,f=f+Math.imul(oe,Ce)|0,w=w+Math.imul(X,Gt)|0,g=g+Math.imul(X,je)|0,g=g+Math.imul(G,Gt)|0,f=f+Math.imul(G,je)|0,w=w+Math.imul(W,Ht)|0,g=g+Math.imul(W,Ne)|0,g=g+Math.imul(q,Ht)|0,f=f+Math.imul(q,Ne)|0,w=w+Math.imul(j,Wt)|0,g=g+Math.imul(j,De)|0,g=g+Math.imul(L,Wt)|0,f=f+Math.imul(L,De)|0,w=w+Math.imul(ce,Kt)|0,g=g+Math.imul(ce,Be)|0,g=g+Math.imul(E,Kt)|0,f=f+Math.imul(E,Be)|0,w=w+Math.imul(V,Xt)|0,g=g+Math.imul(V,Re)|0,g=g+Math.imul(z,Xt)|0,f=f+Math.imul(z,Re)|0;var ri=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(qe,Et),g=Math.imul(qe,we),g=g+Math.imul(ge,Et)|0,f=Math.imul(ge,we),w=w+Math.imul(ze,zt)|0,g=g+Math.imul(ze,Ce)|0,g=g+Math.imul(be,zt)|0,f=f+Math.imul(be,Ce)|0,w=w+Math.imul(ie,Gt)|0,g=g+Math.imul(ie,je)|0,g=g+Math.imul(oe,Gt)|0,f=f+Math.imul(oe,je)|0,w=w+Math.imul(X,Ht)|0,g=g+Math.imul(X,Ne)|0,g=g+Math.imul(G,Ht)|0,f=f+Math.imul(G,Ne)|0,w=w+Math.imul(W,Wt)|0,g=g+Math.imul(W,De)|0,g=g+Math.imul(q,Wt)|0,f=f+Math.imul(q,De)|0,w=w+Math.imul(j,Kt)|0,g=g+Math.imul(j,Be)|0,g=g+Math.imul(L,Kt)|0,f=f+Math.imul(L,Be)|0,w=w+Math.imul(ce,Xt)|0,g=g+Math.imul(ce,Re)|0,g=g+Math.imul(E,Xt)|0,f=f+Math.imul(E,Re)|0,w=w+Math.imul(V,Jt)|0,g=g+Math.imul(V,Ue)|0,g=g+Math.imul(z,Jt)|0,f=f+Math.imul(z,Ue)|0;var ni=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(Nt,Et),g=Math.imul(Nt,we),g=g+Math.imul(Te,Et)|0,f=Math.imul(Te,we),w=w+Math.imul(qe,zt)|0,g=g+Math.imul(qe,Ce)|0,g=g+Math.imul(ge,zt)|0,f=f+Math.imul(ge,Ce)|0,w=w+Math.imul(ze,Gt)|0,g=g+Math.imul(ze,je)|0,g=g+Math.imul(be,Gt)|0,f=f+Math.imul(be,je)|0,w=w+Math.imul(ie,Ht)|0,g=g+Math.imul(ie,Ne)|0,g=g+Math.imul(oe,Ht)|0,f=f+Math.imul(oe,Ne)|0,w=w+Math.imul(X,Wt)|0,g=g+Math.imul(X,De)|0,g=g+Math.imul(G,Wt)|0,f=f+Math.imul(G,De)|0,w=w+Math.imul(W,Kt)|0,g=g+Math.imul(W,Be)|0,g=g+Math.imul(q,Kt)|0,f=f+Math.imul(q,Be)|0,w=w+Math.imul(j,Xt)|0,g=g+Math.imul(j,Re)|0,g=g+Math.imul(L,Xt)|0,f=f+Math.imul(L,Re)|0,w=w+Math.imul(ce,Jt)|0,g=g+Math.imul(ce,Ue)|0,g=g+Math.imul(E,Jt)|0,f=f+Math.imul(E,Ue)|0,w=w+Math.imul(V,Zt)|0,g=g+Math.imul(V,Le)|0,g=g+Math.imul(z,Zt)|0,f=f+Math.imul(z,Le)|0;var ii=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(Tt,Et),g=Math.imul(Tt,we),g=g+Math.imul(Ie,Et)|0,f=Math.imul(Ie,we),w=w+Math.imul(Nt,zt)|0,g=g+Math.imul(Nt,Ce)|0,g=g+Math.imul(Te,zt)|0,f=f+Math.imul(Te,Ce)|0,w=w+Math.imul(qe,Gt)|0,g=g+Math.imul(qe,je)|0,g=g+Math.imul(ge,Gt)|0,f=f+Math.imul(ge,je)|0,w=w+Math.imul(ze,Ht)|0,g=g+Math.imul(ze,Ne)|0,g=g+Math.imul(be,Ht)|0,f=f+Math.imul(be,Ne)|0,w=w+Math.imul(ie,Wt)|0,g=g+Math.imul(ie,De)|0,g=g+Math.imul(oe,Wt)|0,f=f+Math.imul(oe,De)|0,w=w+Math.imul(X,Kt)|0,g=g+Math.imul(X,Be)|0,g=g+Math.imul(G,Kt)|0,f=f+Math.imul(G,Be)|0,w=w+Math.imul(W,Xt)|0,g=g+Math.imul(W,Re)|0,g=g+Math.imul(q,Xt)|0,f=f+Math.imul(q,Re)|0,w=w+Math.imul(j,Jt)|0,g=g+Math.imul(j,Ue)|0,g=g+Math.imul(L,Jt)|0,f=f+Math.imul(L,Ue)|0,w=w+Math.imul(ce,Zt)|0,g=g+Math.imul(ce,Le)|0,g=g+Math.imul(E,Zt)|0,f=f+Math.imul(E,Le)|0,w=w+Math.imul(V,Yt)|0,g=g+Math.imul(V,$e)|0,g=g+Math.imul(z,Yt)|0,f=f+Math.imul(z,$e)|0;var si=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(Tt,zt),g=Math.imul(Tt,Ce),g=g+Math.imul(Ie,zt)|0,f=Math.imul(Ie,Ce),w=w+Math.imul(Nt,Gt)|0,g=g+Math.imul(Nt,je)|0,g=g+Math.imul(Te,Gt)|0,f=f+Math.imul(Te,je)|0,w=w+Math.imul(qe,Ht)|0,g=g+Math.imul(qe,Ne)|0,g=g+Math.imul(ge,Ht)|0,f=f+Math.imul(ge,Ne)|0,w=w+Math.imul(ze,Wt)|0,g=g+Math.imul(ze,De)|0,g=g+Math.imul(be,Wt)|0,f=f+Math.imul(be,De)|0,w=w+Math.imul(ie,Kt)|0,g=g+Math.imul(ie,Be)|0,g=g+Math.imul(oe,Kt)|0,f=f+Math.imul(oe,Be)|0,w=w+Math.imul(X,Xt)|0,g=g+Math.imul(X,Re)|0,g=g+Math.imul(G,Xt)|0,f=f+Math.imul(G,Re)|0,w=w+Math.imul(W,Jt)|0,g=g+Math.imul(W,Ue)|0,g=g+Math.imul(q,Jt)|0,f=f+Math.imul(q,Ue)|0,w=w+Math.imul(j,Zt)|0,g=g+Math.imul(j,Le)|0,g=g+Math.imul(L,Zt)|0,f=f+Math.imul(L,Le)|0,w=w+Math.imul(ce,Yt)|0,g=g+Math.imul(ce,$e)|0,g=g+Math.imul(E,Yt)|0,f=f+Math.imul(E,$e)|0;var oi=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(Tt,Gt),g=Math.imul(Tt,je),g=g+Math.imul(Ie,Gt)|0,f=Math.imul(Ie,je),w=w+Math.imul(Nt,Ht)|0,g=g+Math.imul(Nt,Ne)|0,g=g+Math.imul(Te,Ht)|0,f=f+Math.imul(Te,Ne)|0,w=w+Math.imul(qe,Wt)|0,g=g+Math.imul(qe,De)|0,g=g+Math.imul(ge,Wt)|0,f=f+Math.imul(ge,De)|0,w=w+Math.imul(ze,Kt)|0,g=g+Math.imul(ze,Be)|0,g=g+Math.imul(be,Kt)|0,f=f+Math.imul(be,Be)|0,w=w+Math.imul(ie,Xt)|0,g=g+Math.imul(ie,Re)|0,g=g+Math.imul(oe,Xt)|0,f=f+Math.imul(oe,Re)|0,w=w+Math.imul(X,Jt)|0,g=g+Math.imul(X,Ue)|0,g=g+Math.imul(G,Jt)|0,f=f+Math.imul(G,Ue)|0,w=w+Math.imul(W,Zt)|0,g=g+Math.imul(W,Le)|0,g=g+Math.imul(q,Zt)|0,f=f+Math.imul(q,Le)|0,w=w+Math.imul(j,Yt)|0,g=g+Math.imul(j,$e)|0,g=g+Math.imul(L,Yt)|0,f=f+Math.imul(L,$e)|0;var ai=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ai>>>26)|0,ai&=67108863,w=Math.imul(Tt,Ht),g=Math.imul(Tt,Ne),g=g+Math.imul(Ie,Ht)|0,f=Math.imul(Ie,Ne),w=w+Math.imul(Nt,Wt)|0,g=g+Math.imul(Nt,De)|0,g=g+Math.imul(Te,Wt)|0,f=f+Math.imul(Te,De)|0,w=w+Math.imul(qe,Kt)|0,g=g+Math.imul(qe,Be)|0,g=g+Math.imul(ge,Kt)|0,f=f+Math.imul(ge,Be)|0,w=w+Math.imul(ze,Xt)|0,g=g+Math.imul(ze,Re)|0,g=g+Math.imul(be,Xt)|0,f=f+Math.imul(be,Re)|0,w=w+Math.imul(ie,Jt)|0,g=g+Math.imul(ie,Ue)|0,g=g+Math.imul(oe,Jt)|0,f=f+Math.imul(oe,Ue)|0,w=w+Math.imul(X,Zt)|0,g=g+Math.imul(X,Le)|0,g=g+Math.imul(G,Zt)|0,f=f+Math.imul(G,Le)|0,w=w+Math.imul(W,Yt)|0,g=g+Math.imul(W,$e)|0,g=g+Math.imul(q,Yt)|0,f=f+Math.imul(q,$e)|0;var ui=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ui>>>26)|0,ui&=67108863,w=Math.imul(Tt,Wt),g=Math.imul(Tt,De),g=g+Math.imul(Ie,Wt)|0,f=Math.imul(Ie,De),w=w+Math.imul(Nt,Kt)|0,g=g+Math.imul(Nt,Be)|0,g=g+Math.imul(Te,Kt)|0,f=f+Math.imul(Te,Be)|0,w=w+Math.imul(qe,Xt)|0,g=g+Math.imul(qe,Re)|0,g=g+Math.imul(ge,Xt)|0,f=f+Math.imul(ge,Re)|0,w=w+Math.imul(ze,Jt)|0,g=g+Math.imul(ze,Ue)|0,g=g+Math.imul(be,Jt)|0,f=f+Math.imul(be,Ue)|0,w=w+Math.imul(ie,Zt)|0,g=g+Math.imul(ie,Le)|0,g=g+Math.imul(oe,Zt)|0,f=f+Math.imul(oe,Le)|0,w=w+Math.imul(X,Yt)|0,g=g+Math.imul(X,$e)|0,g=g+Math.imul(G,Yt)|0,f=f+Math.imul(G,$e)|0;var ci=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(ci>>>26)|0,ci&=67108863,w=Math.imul(Tt,Kt),g=Math.imul(Tt,Be),g=g+Math.imul(Ie,Kt)|0,f=Math.imul(Ie,Be),w=w+Math.imul(Nt,Xt)|0,g=g+Math.imul(Nt,Re)|0,g=g+Math.imul(Te,Xt)|0,f=f+Math.imul(Te,Re)|0,w=w+Math.imul(qe,Jt)|0,g=g+Math.imul(qe,Ue)|0,g=g+Math.imul(ge,Jt)|0,f=f+Math.imul(ge,Ue)|0,w=w+Math.imul(ze,Zt)|0,g=g+Math.imul(ze,Le)|0,g=g+Math.imul(be,Zt)|0,f=f+Math.imul(be,Le)|0,w=w+Math.imul(ie,Yt)|0,g=g+Math.imul(ie,$e)|0,g=g+Math.imul(oe,Yt)|0,f=f+Math.imul(oe,$e)|0;var li=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(li>>>26)|0,li&=67108863,w=Math.imul(Tt,Xt),g=Math.imul(Tt,Re),g=g+Math.imul(Ie,Xt)|0,f=Math.imul(Ie,Re),w=w+Math.imul(Nt,Jt)|0,g=g+Math.imul(Nt,Ue)|0,g=g+Math.imul(Te,Jt)|0,f=f+Math.imul(Te,Ue)|0,w=w+Math.imul(qe,Zt)|0,g=g+Math.imul(qe,Le)|0,g=g+Math.imul(ge,Zt)|0,f=f+Math.imul(ge,Le)|0,w=w+Math.imul(ze,Yt)|0,g=g+Math.imul(ze,$e)|0,g=g+Math.imul(be,Yt)|0,f=f+Math.imul(be,$e)|0;var fi=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(fi>>>26)|0,fi&=67108863,w=Math.imul(Tt,Jt),g=Math.imul(Tt,Ue),g=g+Math.imul(Ie,Jt)|0,f=Math.imul(Ie,Ue),w=w+Math.imul(Nt,Zt)|0,g=g+Math.imul(Nt,Le)|0,g=g+Math.imul(Te,Zt)|0,f=f+Math.imul(Te,Le)|0,w=w+Math.imul(qe,Yt)|0,g=g+Math.imul(qe,$e)|0,g=g+Math.imul(ge,Yt)|0,f=f+Math.imul(ge,$e)|0;var di=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(di>>>26)|0,di&=67108863,w=Math.imul(Tt,Zt),g=Math.imul(Tt,Le),g=g+Math.imul(Ie,Zt)|0,f=Math.imul(Ie,Le),w=w+Math.imul(Nt,Yt)|0,g=g+Math.imul(Nt,$e)|0,g=g+Math.imul(Te,Yt)|0,f=f+Math.imul(Te,$e)|0;var hi=(M+w|0)+((g&8191)<<13)|0;M=(f+(g>>>13)|0)+(hi>>>26)|0,hi&=67108863,w=Math.imul(Tt,Yt),g=Math.imul(Tt,$e),g=g+Math.imul(Ie,Yt)|0,f=Math.imul(Ie,$e);var pi=(M+w|0)+((g&8191)<<13)|0;return M=(f+(g>>>13)|0)+(pi>>>26)|0,pi&=67108863,v[0]=pt,v[1]=Zn,v[2]=Yn,v[3]=Qn,v[4]=ei,v[5]=ti,v[6]=ri,v[7]=ni,v[8]=ii,v[9]=si,v[10]=oi,v[11]=ai,v[12]=ui,v[13]=ci,v[14]=li,v[15]=fi,v[16]=di,v[17]=hi,v[18]=pi,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 pe(){te.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(pe,te),pe.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},pe.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 pe;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 Th>"u"||Th,J_)});var Yv=Me(xe=>{"use strict";Object.defineProperty(xe,"__esModule",{value:!0});xe.bytes=xe.stringToBytes=xe.str=xe.bytesToString=xe.hex=xe.utf8=xe.bech32m=xe.bech32=xe.base58check=xe.createBase58check=xe.base58xmr=xe.base58xrp=xe.base58flickr=xe.base58=xe.base64urlnopad=xe.base64url=xe.base64nopad=xe.base64=xe.base32crockford=xe.base32hexnopad=xe.base32hex=xe.base32nopad=xe.base32=xe.base16=xe.utils=void 0;function Wo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function ip(t,...e){if(!Wo(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 Vv(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 sp(t){if(typeof t!="function")throw new Error("function expected");return!0}function no(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Aa(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Tl(t){if(!Array.isArray(t))throw new Error("array expected")}function xl(t,e){if(!Vv(!0,e))throw new Error(`${t}: array of strings expected`)}function op(t,e){if(!Vv(!1,e))throw new Error(`${t}: array of numbers expected`)}function hn(...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 wn(t){let e=typeof t=="string"?t.split(""):t,r=e.length;xl("alphabet",e);let n=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Tl(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=>(Tl(i),i.map(s=>{no("alphabet.decode",s);let o=n.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function Mn(t=""){return no("join",t),{encode:e=>(xl("join.decode",e),e.join(t)),decode:e=>(no("join.decode",e),e.split(t))}}function ju(t,e="="){return Aa(t),no("padding",e),{encode(r){for(xl("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){xl("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 zv(t){return sp(t),{encode:e=>e,decode:e=>t(e)}}function rp(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(Tl(t),!t.length)return[];let n=0,i=[],s=Array.from(t,u=>{if(Aa(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 Gv=(t,e)=>e===0?t:Gv(e,t%e),Pl=(t,e)=>t+(e-Gv(t,e)),Il=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Cl(t,e,r,n){if(Tl(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(Pl(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Pl(e,r)}`);let i=0,s=0,o=Il[e],u=Il[r]-1,c=[];for(let d of t){if(Aa(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=Il[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 Hv(t){Aa(t);let e=2**8;return{encode:r=>{if(!Wo(r))throw new Error("radix.encode input should be Uint8Array");return rp(Array.from(r),e,t)},decode:r=>(op("radix.decode",r),Uint8Array.from(rp(r,t,e)))}}function Tn(t,e=!1){if(Aa(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Pl(8,t)>32||Pl(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Wo(r))throw new Error("radix2.encode input should be Uint8Array");return Cl(Array.from(r),8,t,!e)},decode:r=>(op("radix2.decode",r),Uint8Array.from(Cl(r,t,8,e)))}}function Lv(t){return sp(t),function(...e){try{return t.apply(null,e)}catch{}}}function Wv(t,e){return Aa(t),sp(e),{encode(r){if(!Wo(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(!Wo(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}}}xe.utils={alphabet:wn,chain:hn,checksum:Wv,convertRadix:rp,convertRadix2:Cl,radix:Hv,radix2:Tn,join:Mn,padding:ju};xe.base16=hn(Tn(4),wn("0123456789ABCDEF"),Mn(""));xe.base32=hn(Tn(5),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ju(5),Mn(""));xe.base32nopad=hn(Tn(5),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Mn(""));xe.base32hex=hn(Tn(5),wn("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ju(5),Mn(""));xe.base32hexnopad=hn(Tn(5),wn("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Mn(""));xe.base32crockford=hn(Tn(5),wn("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Mn(""),zv(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));var Kv=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Xv=(t,e)=>{no("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"})};xe.base64=Kv?{encode(t){return ip(t),t.toBase64()},decode(t){return Xv(t,!1)}}:hn(Tn(6),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ju(6),Mn(""));xe.base64nopad=hn(Tn(6),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Mn(""));xe.base64url=Kv?{encode(t){return ip(t),t.toBase64({alphabet:"base64url"})},decode(t){return Xv(t,!0)}}:hn(Tn(6),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ju(6),Mn(""));xe.base64urlnopad=hn(Tn(6),wn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Mn(""));var ap=t=>hn(Hv(58),wn(t),Mn(""));xe.base58=ap("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");xe.base58flickr=ap("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");xe.base58xrp=ap("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");var $v=[0,2,3,5,6,7,9,10,11];xe.base58xmr={encode(t){let e="";for(let r=0;r<t.length;r+=8){let n=t.subarray(r,r+8);e+=xe.base58.encode(n).padStart($v[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=$v.indexOf(n.length),s=xe.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 rP=t=>hn(Wv(4,e=>t(t(e))),xe.base58);xe.createBase58check=rP;xe.base58check=xe.createBase58check;var np=hn(wn("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Mn("")),Fv=[996825010,642813549,513874426,1027748829,705979059];function Cu(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<Fv.length;n++)(e>>n&1)===1&&(r^=Fv[n]);return r}function qv(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=Cu(i)^o>>5}i=Cu(i);for(let s=0;s<n;s++)i=Cu(i)^t.charCodeAt(s)&31;for(let s of e)i=Cu(i)^s;for(let s=0;s<6;s++)i=Cu(i);return i^=r,np.encode(Cl([i%Il[30]],30,5,!1))}function Jv(t){let e=t==="bech32"?1:734539939,r=Tn(5),n=r.decode,i=r.encode,s=Lv(n);function o(_,b,O=90){no("bech32.encode prefix",_),Wo(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=qv(F,b,e);return`${F}1${np.encode(b)}${R}`}function u(_,b=90){no("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=np.decode(R).slice(0,-6),J=qv(F,H,e);if(!R.endsWith(J))throw new Error(`Invalid checksum in ${_}: expected "${J}"`);return{prefix:F,words:H}}let c=Lv(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}}xe.bech32=Jv("bech32");xe.bech32m=Jv("bech32m");xe.utf8={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)};var nP=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",iP={encode(t){return ip(t),t.toHex()},decode(t){return no("hex",t),Uint8Array.fromHex(t)}};xe.hex=nP?iP:hn(Tn(4),wn("0123456789abcdef"),Mn(""),zv(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 jl={utf8:xe.utf8,hex:xe.hex,base16:xe.base16,base32:xe.base32,base64:xe.base64,base64url:xe.base64url,base58:xe.base58,base58xmr:xe.base58xmr},Zv="Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr",sP=(t,e)=>{if(typeof t!="string"||!jl.hasOwnProperty(t))throw new TypeError(Zv);if(!Wo(e))throw new TypeError("bytesToString() expects Uint8Array");return jl[t].encode(e)};xe.bytesToString=sP;xe.str=xe.bytesToString;var oP=(t,e)=>{if(!jl.hasOwnProperty(t))throw new TypeError(Zv);if(typeof e!="string")throw new TypeError("stringToBytes() expects string");return jl[t].decode(e)};xe.stringToBytes=oP;xe.bytes=xe.stringToBytes});var rb=Me((KX,tb)=>{"use strict";var up=Object.defineProperty,aP=Object.getOwnPropertyDescriptor,uP=Object.getOwnPropertyNames,cP=Object.prototype.hasOwnProperty,lP=(t,e)=>{for(var r in e)up(t,r,{get:e[r],enumerable:!0})},fP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of uP(e))!cP.call(t,i)&&i!==r&&up(t,i,{get:()=>e[i],enumerable:!(n=aP(e,i))||n.enumerable});return t},dP=t=>fP(up({},"__esModule",{value:!0}),t),Qv={};lP(Qv,{fromBase58:()=>pP,toBase58:()=>hP});tb.exports=dP(Qv);var eb=Yv(),hP=t=>eb.base58.encode(t),pP=t=>eb.base58.decode(t)});var sb=Me((XX,ib)=>{"use strict";var lp=Object.defineProperty,mP=Object.getOwnPropertyDescriptor,gP=Object.getOwnPropertyNames,yP=Object.prototype.hasOwnProperty,_P=(t,e)=>{for(var r in e)lp(t,r,{get:e[r],enumerable:!0})},vP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of gP(e))!yP.call(t,i)&&i!==r&&lp(t,i,{get:()=>e[i],enumerable:!(n=mP(e,i))||n.enumerable});return t},bP=t=>vP(lp({},"__esModule",{value:!0}),t),nb={};_P(nb,{fromBase64:()=>wP,toBase64:()=>MP});ib.exports=bP(nb);function wP(t){return Uint8Array.from(atob(t),e=>e.charCodeAt(0))}var cp=8192;function MP(t){if(t.length<cp)return btoa(String.fromCharCode(...t));let e="";for(var r=0;r<t.length;r+=cp){let n=t.slice(r,r+cp);e+=String.fromCharCode(...n)}return btoa(e)}});var ub=Me((JX,ab)=>{"use strict";var fp=Object.defineProperty,SP=Object.getOwnPropertyDescriptor,kP=Object.getOwnPropertyNames,OP=Object.prototype.hasOwnProperty,EP=(t,e)=>{for(var r in e)fp(t,r,{get:e[r],enumerable:!0})},AP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of kP(e))!OP.call(t,i)&&i!==r&&fp(t,i,{get:()=>e[i],enumerable:!(n=SP(e,i))||n.enumerable});return t},IP=t=>AP(fp({},"__esModule",{value:!0}),t),ob={};EP(ob,{fromHex:()=>TP,toHex:()=>xP});ab.exports=IP(ob);function TP(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 xP(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}});var fb=Me((ZX,lb)=>{"use strict";var dp=Object.defineProperty,PP=Object.getOwnPropertyDescriptor,CP=Object.getOwnPropertyNames,jP=Object.prototype.hasOwnProperty,NP=(t,e)=>{for(var r in e)dp(t,r,{get:e[r],enumerable:!0})},DP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of CP(e))!jP.call(t,i)&&i!==r&&dp(t,i,{get:()=>e[i],enumerable:!(n=PP(e,i))||n.enumerable});return t},BP=t=>DP(dp({},"__esModule",{value:!0}),t),cb={};NP(cb,{chunk:()=>RP});lb.exports=BP(cb);function RP(t,e){return Array.from({length:Math.ceil(t.length/e)},(r,n)=>t.slice(n*e,(n+1)*e))}});var pb=Me((YX,hb)=>{"use strict";var hp=Object.defineProperty,UP=Object.getOwnPropertyDescriptor,LP=Object.getOwnPropertyNames,$P=Object.prototype.hasOwnProperty,FP=(t,e)=>{for(var r in e)hp(t,r,{get:e[r],enumerable:!0})},qP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of LP(e))!$P.call(t,i)&&i!==r&&hp(t,i,{get:()=>e[i],enumerable:!(n=UP(e,i))||n.enumerable});return t},VP=t=>qP(hp({},"__esModule",{value:!0}),t),db={};FP(db,{promiseWithResolvers:()=>zP});hb.exports=VP(db);function zP(){let t,e;return{promise:new Promise((n,i)=>{t=n,e=i}),resolve:t,reject:e}}});var _b=Me((QX,yb)=>{"use strict";var _p=Object.defineProperty,GP=Object.getOwnPropertyDescriptor,HP=Object.getOwnPropertyNames,WP=Object.prototype.hasOwnProperty,KP=(t,e)=>{for(var r in e)_p(t,r,{get:e[r],enumerable:!0})},XP=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of HP(e))!WP.call(t,i)&&i!==r&&_p(t,i,{get:()=>e[i],enumerable:!(n=GP(e,i))||n.enumerable});return t},JP=t=>XP(_p({},"__esModule",{value:!0}),t),mb={};KP(mb,{DataLoader:()=>gp});yb.exports=JP(mb);var gp=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=eC(r),this._batchScheduleFn=tC(r),this._cacheKeyFn=rC(r),this._cacheMap=nC(r),this._batch=null,this.name=iC(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=YP(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(!gb(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}},ZP=typeof process=="object"&&typeof process.nextTick=="function"?function(t){pp||(pp=Promise.resolve()),pp.then(()=>{process.nextTick(t)})}:typeof setImmediate=="function"?function(t){setImmediate(t)}:function(t){setTimeout(t)},pp;function YP(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(()=>{QP(t,r)}),r}function QP(t,e){if(e.hasDispatched=!0,e.keys.length===0){yp(e);return}let r;try{r=t._batchLoadFn(e.keys)}catch(n){return mp(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 mp(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(!gb(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)}`);yp(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=>{mp(t,e,n)})}function mp(t,e,r){yp(e);for(let n=0;n<e.keys.length;n++)t.clear(e.keys[n]),e.callbacks[n].reject(r)}function yp(t){if(t.cacheHits)for(let e=0;e<t.cacheHits.length;e++)t.cacheHits[e]()}function eC(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 tC(t){let e=t&&t.batchScheduleFn;if(e===void 0)return ZP;if(typeof e!="function")throw new TypeError(`batchScheduleFn must be a function: ${e}`);return e}function rC(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 nC(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 iC(t){return t&&t.name?t.name:null}function gb(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 io=Me((eJ,Sb)=>{"use strict";var vp=Object.defineProperty,sC=Object.getOwnPropertyDescriptor,oC=Object.getOwnPropertyNames,aC=Object.prototype.hasOwnProperty,uC=(t,e)=>{for(var r in e)vp(t,r,{get:e[r],enumerable:!0})},cC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of oC(e))!aC.call(t,i)&&i!==r&&vp(t,i,{get:()=>e[i],enumerable:!(n=sC(e,i))||n.enumerable});return t},lC=t=>cC(vp({},"__esModule",{value:!0}),t),Mb={};uC(Mb,{DataLoader:()=>hC.DataLoader,chunk:()=>fC.chunk,fromBase58:()=>vb.fromBase58,fromBase64:()=>bb.fromBase64,fromHex:()=>wb.fromHex,promiseWithResolvers:()=>dC.promiseWithResolvers,toBase58:()=>vb.toBase58,toBase64:()=>bb.toBase64,toHex:()=>wb.toHex});Sb.exports=lC(Mb);var vb=rb(),bb=sb(),wb=ub(),fC=fb(),dC=pb(),hC=_b()});var Nu=Me((tJ,Ob)=>{"use strict";var bp=Object.defineProperty,pC=Object.getOwnPropertyDescriptor,mC=Object.getOwnPropertyNames,gC=Object.prototype.hasOwnProperty,yC=(t,e)=>{for(var r in e)bp(t,r,{get:e[r],enumerable:!0})},_C=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mC(e))!gC.call(t,i)&&i!==r&&bp(t,i,{get:()=>e[i],enumerable:!(n=pC(e,i))||n.enumerable});return t},vC=t=>_C(bp({},"__esModule",{value:!0}),t),kb={};yC(kb,{ulebDecode:()=>wC,ulebEncode:()=>bC});Ob.exports=vC(kb);function bC(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 wC(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 Sp=Me((rJ,Ab)=>{"use strict";var Mp=Object.defineProperty,MC=Object.getOwnPropertyDescriptor,SC=Object.getOwnPropertyNames,kC=Object.prototype.hasOwnProperty,OC=(t,e)=>{for(var r in e)Mp(t,r,{get:e[r],enumerable:!0})},EC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of SC(e))!kC.call(t,i)&&i!==r&&Mp(t,i,{get:()=>e[i],enumerable:!(n=MC(e,i))||n.enumerable});return t},AC=t=>EC(Mp({},"__esModule",{value:!0}),t),Eb={};OC(Eb,{BcsReader:()=>wp});Ab.exports=AC(Eb);var IC=Nu(),wp=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,IC.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 Op=Me((nJ,Tb)=>{"use strict";var kp=Object.defineProperty,TC=Object.getOwnPropertyDescriptor,xC=Object.getOwnPropertyNames,PC=Object.prototype.hasOwnProperty,CC=(t,e)=>{for(var r in e)kp(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&&kp(t,i,{get:()=>e[i],enumerable:!(n=TC(e,i))||n.enumerable});return t},NC=t=>jC(kp({},"__esModule",{value:!0}),t),Ib={};CC(Ib,{decodeStr:()=>BC,encodeStr:()=>DC,splitGenericParameters:()=>RC});Tb.exports=NC(Ib);var Ia=io();function DC(t,e){switch(e){case"base58":return(0,Ia.toBase58)(t);case"base64":return(0,Ia.toBase64)(t);case"hex":return(0,Ia.toHex)(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function BC(t,e){switch(e){case"base58":return(0,Ia.fromBase58)(t);case"base64":return(0,Ia.fromBase64)(t);case"hex":return(0,Ia.fromHex)(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function RC(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 Tp=Me((iJ,Pb)=>{"use strict";var Ip=Object.defineProperty,UC=Object.getOwnPropertyDescriptor,LC=Object.getOwnPropertyNames,$C=Object.prototype.hasOwnProperty,FC=(t,e)=>{for(var r in e)Ip(t,r,{get:e[r],enumerable:!0})},qC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of LC(e))!$C.call(t,i)&&i!==r&&Ip(t,i,{get:()=>e[i],enumerable:!(n=UC(e,i))||n.enumerable});return t},VC=t=>qC(Ip({},"__esModule",{value:!0}),t),xb={};FC(xb,{BcsWriter:()=>Ap});Pb.exports=VC(xb);var zC=Nu(),GC=Op(),Ap=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 Ep(BigInt(e),8).forEach(r=>this.write8(r)),this}write128(e){return Ep(BigInt(e),16).forEach(r=>this.write8(r)),this}write256(e){return Ep(BigInt(e),32).forEach(r=>this.write8(r)),this}writeULEB(e){return(0,zC.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,GC.encodeStr)(this.toBytes(),e)}};function Ep(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 Cp=Me((sJ,Rb)=>{"use strict";var xp=Object.defineProperty,HC=Object.getOwnPropertyDescriptor,WC=Object.getOwnPropertyNames,KC=Object.prototype.hasOwnProperty,Cb=t=>{throw TypeError(t)},XC=(t,e)=>{for(var r in e)xp(t,r,{get:e[r],enumerable:!0})},JC=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of WC(e))!KC.call(t,i)&&i!==r&&xp(t,i,{get:()=>e[i],enumerable:!(n=HC(e,i))||n.enumerable});return t},ZC=t=>JC(xp({},"__esModule",{value:!0}),t),jb=(t,e,r)=>e.has(t)||Cb("Cannot "+r),ki=(t,e,r)=>(jb(t,e,"read from private field"),r?r.call(t):e.get(t)),Dl=(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),Bl=(t,e,r,n)=>(jb(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Nb={};XC(Nb,{BcsType:()=>Bu,SerializedBcs:()=>Rl,bigUIntBcsType:()=>i8,dynamicSizeBcsType:()=>s8,fixedSizeBcsType:()=>Pp,isSerializedBcs:()=>r8,lazyBcsType:()=>a8,stringLikeBcsType:()=>o8,uIntBcsType:()=>n8});Rb.exports=ZC(Nb);var xa=io(),YC=Sp(),QC=Nu(),e8=Tp(),Ta,Du,Nl,so,t8=class Db{constructor(e){Dl(this,Ta),Dl(this,Du),this.name=e.name,this.read=e.read,this.serializedSize=e.serializedSize??(()=>null),Bl(this,Ta,e.write),Bl(this,Du,e.serialize??((r,n)=>{let i=new e8.BcsWriter({initialSize:this.serializedSize(r)??void 0,...n});return ki(this,Ta).call(this,r,i),i.toBytes()})),this.validate=e.validate??(()=>{})}write(e,r){this.validate(e),ki(this,Ta).call(this,e,r)}serialize(e,r){return this.validate(e),new Rl(this,ki(this,Du).call(this,e,r))}parse(e){let r=new YC.BcsReader(e);return this.read(r)}fromHex(e){return this.parse((0,xa.fromHex)(e))}fromBase58(e){return this.parse((0,xa.fromBase58)(e))}fromBase64(e){return this.parse((0,xa.fromBase64)(e))}transform({name:e,input:r,output:n,validate:i}){return new Db({name:e??this.name,read:s=>n?n(this.read(s)):this.read(s),write:(s,o)=>ki(this,Ta).call(this,r?r(s):s,o),serializedSize:s=>this.serializedSize(r?r(s):s),serialize:(s,o)=>ki(this,Du).call(this,r?r(s):s,o),validate:s=>{i?.(s),this.validate(r?r(s):s)}})}};Ta=new WeakMap;Du=new WeakMap;var Bu=t8,Bb=Symbol.for("@mysten/serialized-bcs");function r8(t){return!!t&&typeof t=="object"&&t[Bb]===!0}var Rl=class{constructor(e,r){Dl(this,Nl),Dl(this,so),Bl(this,Nl,e),Bl(this,so,r)}get[Bb](){return!0}toBytes(){return ki(this,so)}toHex(){return(0,xa.toHex)(ki(this,so))}toBase64(){return(0,xa.toBase64)(ki(this,so))}toBase58(){return(0,xa.toBase58)(ki(this,so))}parse(){return ki(this,Nl).parse(ki(this,so))}};Nl=new WeakMap;so=new WeakMap;function Pp({size:t,...e}){return new Bu({...e,serializedSize:()=>t})}function n8({readMethod:t,writeMethod:e,...r}){return Pp({...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 i8({readMethod:t,writeMethod:e,...r}){return Pp({...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 s8({serialize:t,...e}){let r=new Bu({...e,serialize:t,write:(n,i)=>{for(let s of r.serialize(n).toBytes())i.write8(s)}});return r}function o8({toBytes:t,fromBytes:e,...r}){return new Bu({...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,QC.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 a8(t){let e=null;function r(){return e||(e=t()),e}return new Bu({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 Fb=Me((oJ,$b)=>{"use strict";var jp=Object.defineProperty,u8=Object.getOwnPropertyDescriptor,c8=Object.getOwnPropertyNames,l8=Object.prototype.hasOwnProperty,f8=(t,e)=>{for(var r in e)jp(t,r,{get:e[r],enumerable:!0})},d8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of c8(e))!l8.call(t,i)&&i!==r&&jp(t,i,{get:()=>e[i],enumerable:!(n=u8(e,i))||n.enumerable});return t},h8=t=>d8(jp({},"__esModule",{value:!0}),t),Lb={};f8(Lb,{bcs:()=>Ul});$b.exports=h8(Lb);var Lr=Cp(),Ub=Nu(),Ul={u8(t){return(0,Lr.uIntBcsType)({name:"u8",readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...t})},u16(t){return(0,Lr.uIntBcsType)({name:"u16",readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...t})},u32(t){return(0,Lr.uIntBcsType)({name:"u32",readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...t})},u64(t){return(0,Lr.bigUIntBcsType)({name:"u64",readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...t})},u128(t){return(0,Lr.bigUIntBcsType)({name:"u128",readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...t})},u256(t){return(0,Lr.bigUIntBcsType)({name:"u256",readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...t})},bool(t){return(0,Lr.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,Lr.dynamicSizeBcsType)({name:"uleb128",read:e=>e.readULEB(),serialize:e=>Uint8Array.from((0,Ub.ulebEncode)(e)),...t})},bytes(t,e){return(0,Lr.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 Lr.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,Ub.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,Lr.stringLikeBcsType)({name:"string",toBytes:e=>new TextEncoder().encode(e),fromBytes:e=>new TextDecoder().decode(e),...t})},fixedArray(t,e,r){return new Lr.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 Ul.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 Lr.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 Lr.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 Lr.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 Lr.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 Ul.vector(Ul.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,Lr.lazyBcsType)(t)}}});var br=Me((aJ,Vb)=>{"use strict";var Bp=Object.defineProperty,p8=Object.getOwnPropertyDescriptor,m8=Object.getOwnPropertyNames,g8=Object.prototype.hasOwnProperty,y8=(t,e)=>{for(var r in e)Bp(t,r,{get:e[r],enumerable:!0})},_8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of m8(e))!g8.call(t,i)&&i!==r&&Bp(t,i,{get:()=>e[i],enumerable:!(n=p8(e,i))||n.enumerable});return t},v8=t=>_8(Bp({},"__esModule",{value:!0}),t),qb={};y8(qb,{BcsReader:()=>w8.BcsReader,BcsType:()=>Np.BcsType,BcsWriter:()=>M8.BcsWriter,SerializedBcs:()=>Np.SerializedBcs,bcs:()=>b8.bcs,decodeStr:()=>Dp.decodeStr,encodeStr:()=>Dp.encodeStr,fromB58:()=>k8,fromB64:()=>E8,fromBase58:()=>Vn.fromBase58,fromBase64:()=>Vn.fromBase64,fromHEX:()=>I8,fromHex:()=>Vn.fromHex,isSerializedBcs:()=>Np.isSerializedBcs,splitGenericParameters:()=>Dp.splitGenericParameters,toB58:()=>S8,toB64:()=>O8,toBase58:()=>Vn.toBase58,toBase64:()=>Vn.toBase64,toHEX:()=>A8,toHex:()=>Vn.toHex});Vb.exports=v8(qb);var Vn=io(),Np=Cp(),b8=Fb(),w8=Sp(),Dp=Op(),M8=Tp(),S8=Vn.toBase58,k8=Vn.fromBase58,O8=Vn.toBase64,E8=Vn.fromBase64,A8=Vn.toHex,I8=Vn.fromHex});var Ll=Me((uJ,Wb)=>{"use strict";var Rp=Object.defineProperty,T8=Object.getOwnPropertyDescriptor,x8=Object.getOwnPropertyNames,P8=Object.prototype.hasOwnProperty,C8=(t,e)=>{for(var r in e)Rp(t,r,{get:e[r],enumerable:!0})},j8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of x8(e))!P8.call(t,i)&&i!==r&&Rp(t,i,{get:()=>e[i],enumerable:!(n=T8(e,i))||n.enumerable});return t},N8=t=>j8(Rp({},"__esModule",{value:!0}),t),zb={};C8(zb,{isValidSuiNSName:()=>B8,normalizeSuiNSName:()=>R8});Wb.exports=N8(zb);var Gb=/^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i,Hb=/^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i,D8=235;function B8(t){return t.length>D8?!1:t.includes("@")?Gb.test(t):Hb.test(t)}function R8(t,e="at"){let r=t.toLowerCase(),n;if(r.includes("@")){if(!Gb.test(r))throw new Error(`Invalid SuiNS name ${t}`);let[i,s]=r.split("@");n=[...i?i.split("."):[],s]}else{if(!Hb.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 Ru=Me((cJ,Zb)=>{"use strict";var Up=Object.defineProperty,U8=Object.getOwnPropertyDescriptor,L8=Object.getOwnPropertyNames,$8=Object.prototype.hasOwnProperty,F8=(t,e)=>{for(var r in e)Up(t,r,{get:e[r],enumerable:!0})},q8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L8(e))!$8.call(t,i)&&i!==r&&Up(t,i,{get:()=>e[i],enumerable:!(n=U8(e,i))||n.enumerable});return t},V8=t=>q8(Up({},"__esModule",{value:!0}),t),Kb={};F8(Kb,{isValidNamedPackage:()=>Jb,isValidNamedType:()=>K8});Zb.exports=V8(Kb);var z8=Ll(),G8=/^([a-z0-9]+(?:-[a-z0-9]+)*)$/,H8=/^\d+$/,W8=64,Xb="/",Jb=t=>{let e=t.split(Xb);if(e.length<2||e.length>3)return!1;let[r,n,i]=e;return i!==void 0&&!H8.test(i)||!(0,z8.isValidSuiNSName)(r)?!1:G8.test(n)&&n.length<W8},K8=t=>{let e=t.split(/::|<|>|,/);for(let r of e)if(r.includes(Xb)&&!Jb(r))return!1;return!0}});var $r=Me((lJ,rw)=>{"use strict";var Lp=Object.defineProperty,X8=Object.getOwnPropertyDescriptor,J8=Object.getOwnPropertyNames,Z8=Object.prototype.hasOwnProperty,Y8=(t,e)=>{for(var r in e)Lp(t,r,{get:e[r],enumerable:!0})},Q8=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of J8(e))!Z8.call(t,i)&&i!==r&&Lp(t,i,{get:()=>e[i],enumerable:!(n=X8(e,i))||n.enumerable});return t},e4=t=>Q8(Lp({},"__esModule",{value:!0}),t),Yb={};Y8(Yb,{SUI_ADDRESS_LENGTH:()=>$p,isValidSuiAddress:()=>ew,isValidSuiObjectId:()=>i4,isValidTransactionDigest:()=>n4,normalizeStructTag:()=>tw,normalizeSuiAddress:()=>qp,normalizeSuiObjectId:()=>o4,parseStructTag:()=>Fp});rw.exports=e4(Yb);var Qb=br(),t4=Ru(),r4=32;function n4(t){try{return(0,Qb.fromBase58)(t).length===r4}catch{return!1}}var $p=32;function ew(t){return a4(t)&&u4(t)===$p}function i4(t){return ew(t)}function s4(t){return t.includes("::")?Fp(t):t}function Fp(t){let[e,r]=t.split("::"),n=(0,t4.isValidNamedPackage)(e),i=t.slice(e.length+r.length+4),s=i.includes("<")?i.slice(0,i.indexOf("<")):i,o=i.includes("<")?(0,Qb.splitGenericParameters)(i.slice(i.indexOf("<")+1,i.lastIndexOf(">"))).map(u=>s4(u.trim())):[];return{address:n?e:qp(e),module:r,name:s,typeParams:o}}function tw(t){let{address:e,module:r,name:n,typeParams:i}=typeof t=="string"?Fp(t):t,s=i?.length>0?`<${i.map(o=>typeof o=="string"?o:tw(o)).join(",")}>`:"";return`${e}::${r}::${n}${s}`}function qp(t,e=!1){let r=t.toLowerCase();return!e&&r.startsWith("0x")&&(r=r.slice(2)),`0x${r.padStart($p*2,"0")}`}function o4(t,e=!1){return qp(t,e)}function a4(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2===0}function u4(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}});var $l=Me((fJ,iw)=>{"use strict";var zp=Object.defineProperty,c4=Object.getOwnPropertyDescriptor,l4=Object.getOwnPropertyNames,f4=Object.prototype.hasOwnProperty,d4=(t,e)=>{for(var r in e)zp(t,r,{get:e[r],enumerable:!0})},h4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of l4(e))!f4.call(t,i)&&i!==r&&zp(t,i,{get:()=>e[i],enumerable:!(n=c4(e,i))||n.enumerable});return t},p4=t=>h4(zp({},"__esModule",{value:!0}),t),nw={};d4(nw,{TypeTagSerializer:()=>Vp});iw.exports=p4(nw);var m4=br(),g4=$r(),y4=/^vector<(.+)>$/,_4=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/,Vp=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(y4);if(n)return{vector:t.parseFromStr(n[1],r)};let i=e.match(_4);if(i)return{struct:{address:r?(0,g4.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,m4.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 ql=Me((dJ,Pw)=>{"use strict";var Gp=Object.defineProperty,v4=Object.getOwnPropertyDescriptor,b4=Object.getOwnPropertyNames,w4=Object.prototype.hasOwnProperty,M4=(t,e)=>{for(var r in e)Gp(t,r,{get:e[r],enumerable:!0})},S4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of b4(e))!w4.call(t,i)&&i!==r&&Gp(t,i,{get:()=>e[i],enumerable:!(n=v4(e,i))||n.enumerable});return t},k4=t=>S4(Gp({},"__esModule",{value:!0}),t),ow={};M4(ow,{Address:()=>xn,AppId:()=>Mw,Argument:()=>Ki,CallArg:()=>lw,Command:()=>dw,CompressedSignature:()=>Ow,GasData:()=>yw,Intent:()=>Sw,IntentMessage:()=>kw,IntentScope:()=>bw,IntentVersion:()=>ww,MultiSig:()=>I4,MultiSigPkMap:()=>Aw,MultiSigPublicKey:()=>Iw,ObjectArg:()=>cw,ObjectDigest:()=>aw,Owner:()=>A4,PasskeyAuthenticator:()=>x4,ProgrammableMoveCall:()=>fw,ProgrammableTransaction:()=>hw,PublicKey:()=>Ew,SenderSignedData:()=>T4,SenderSignedTransaction:()=>xw,SharedObjectRef:()=>uw,StructTag:()=>gw,SuiObjectRef:()=>Fl,TransactionData:()=>vw,TransactionDataV1:()=>_w,TransactionExpiration:()=>mw,TransactionKind:()=>pw,TypeTag:()=>Wp,base64String:()=>Tw});Pw.exports=k4(ow);var se=br(),Uu=$r(),sw=$l();function O4(t){return se.bcs.u64({name:"unsafe_u64",...t}).transform({input:e=>e,output:e=>Number(e)})}function E4(t){return se.bcs.enum("Option",{None:null,Some:t})}var xn=se.bcs.bytes(Uu.SUI_ADDRESS_LENGTH).transform({validate:t=>{let e=typeof t=="string"?t:(0,se.toHex)(t);if(!e||!(0,Uu.isValidSuiAddress)((0,Uu.normalizeSuiAddress)(e)))throw new Error(`Invalid Sui address ${e}`)},input:t=>typeof t=="string"?(0,se.fromHex)((0,Uu.normalizeSuiAddress)(t)):t,output:t=>(0,Uu.normalizeSuiAddress)((0,se.toHex)(t))}),aw=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")}}),Fl=se.bcs.struct("SuiObjectRef",{objectId:xn,version:se.bcs.u64(),digest:aw}),uw=se.bcs.struct("SharedObjectRef",{objectId:xn,initialSharedVersion:se.bcs.u64(),mutable:se.bcs.bool()}),cw=se.bcs.enum("ObjectArg",{ImmOrOwnedObject:Fl,SharedObject:uw,Receiving:Fl}),A4=se.bcs.enum("Owner",{AddressOwner:xn,ObjectOwner:xn,Shared:se.bcs.struct("Shared",{initialSharedVersion:se.bcs.u64()}),Immutable:null,ConsensusV2:se.bcs.struct("ConsensusV2",{authenticator:se.bcs.enum("Authenticator",{SingleOwner:xn}),startVersion:se.bcs.u64()})}),lw=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:cw}),Hp=se.bcs.enum("TypeTag",{bool:null,u8:null,u64:null,u128:null,address:null,signer:null,vector:se.bcs.lazy(()=>Hp),struct:se.bcs.lazy(()=>gw),u16:null,u32:null,u256:null}),Wp=Hp.transform({input:t=>typeof t=="string"?sw.TypeTagSerializer.parseFromStr(t,!0):t,output:t=>sw.TypeTagSerializer.tagToString(t)}),Ki=se.bcs.enum("Argument",{GasCoin:null,Input:se.bcs.u16(),Result:se.bcs.u16(),NestedResult:se.bcs.tuple([se.bcs.u16(),se.bcs.u16()])}),fw=se.bcs.struct("ProgrammableMoveCall",{package:xn,module:se.bcs.string(),function:se.bcs.string(),typeArguments:se.bcs.vector(Wp),arguments:se.bcs.vector(Ki)}),dw=se.bcs.enum("Command",{MoveCall:fw,TransferObjects:se.bcs.struct("TransferObjects",{objects:se.bcs.vector(Ki),address:Ki}),SplitCoins:se.bcs.struct("SplitCoins",{coin:Ki,amounts:se.bcs.vector(Ki)}),MergeCoins:se.bcs.struct("MergeCoins",{destination:Ki,sources:se.bcs.vector(Ki)}),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(xn)}),MakeMoveVec:se.bcs.struct("MakeMoveVec",{type:E4(Wp).transform({input:t=>t===null?{None:!0}:{Some:t},output:t=>t.Some??null}),elements:se.bcs.vector(Ki)}),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(xn),package:xn,ticket:Ki})}),hw=se.bcs.struct("ProgrammableTransaction",{inputs:se.bcs.vector(lw),commands:se.bcs.vector(dw)}),pw=se.bcs.enum("TransactionKind",{ProgrammableTransaction:hw,ChangeEpoch:null,Genesis:null,ConsensusCommitPrologue:null}),mw=se.bcs.enum("TransactionExpiration",{None:null,Epoch:O4()}),gw=se.bcs.struct("StructTag",{address:xn,module:se.bcs.string(),name:se.bcs.string(),typeParams:se.bcs.vector(Hp)}),yw=se.bcs.struct("GasData",{payment:se.bcs.vector(Fl),owner:xn,price:se.bcs.u64(),budget:se.bcs.u64()}),_w=se.bcs.struct("TransactionDataV1",{kind:pw,sender:xn,gasData:yw,expiration:mw}),vw=se.bcs.enum("TransactionData",{V1:_w}),bw=se.bcs.enum("IntentScope",{TransactionData:null,TransactionEffects:null,CheckpointSummary:null,PersonalMessage:null}),ww=se.bcs.enum("IntentVersion",{V0:null}),Mw=se.bcs.enum("AppId",{Sui:null}),Sw=se.bcs.struct("Intent",{scope:bw,version:ww,appId:Mw});function kw(t){return se.bcs.struct(`IntentMessage<${t.name}>`,{intent:Sw,value:t})}var Ow=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())}),Ew=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())}),Aw=se.bcs.struct("MultiSigPkMap",{pubKey:Ew,weight:se.bcs.u8()}),Iw=se.bcs.struct("MultiSigPublicKey",{pk_map:se.bcs.vector(Aw),threshold:se.bcs.u16()}),I4=se.bcs.struct("MultiSig",{sigs:se.bcs.vector(Ow),bitmap:se.bcs.u16(),multisig_pk:Iw}),Tw=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))}),xw=se.bcs.struct("SenderSignedTransaction",{intentMessage:kw(vw),txSignatures:se.bcs.vector(Tw)}),T4=se.bcs.vector(xw,{name:"SenderSignedData"}),x4=se.bcs.struct("PasskeyAuthenticator",{authenticatorData:se.bcs.vector(se.bcs.u8()),clientDataJson:se.bcs.string(),userSignature:se.bcs.vector(se.bcs.u8())})});var Rw=Me((hJ,Bw)=>{"use strict";var Kp=Object.defineProperty,P4=Object.getOwnPropertyDescriptor,C4=Object.getOwnPropertyNames,j4=Object.prototype.hasOwnProperty,N4=(t,e)=>{for(var r in e)Kp(t,r,{get:e[r],enumerable:!0})},D4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C4(e))!j4.call(t,i)&&i!==r&&Kp(t,i,{get:()=>e[i],enumerable:!(n=P4(e,i))||n.enumerable});return t},B4=t=>D4(Kp({},"__esModule",{value:!0}),t),jw={};N4(jw,{TransactionEffects:()=>X4});Bw.exports=B4(jw);var ue=br(),Pt=ql(),R4=ue.bcs.enum("PackageUpgradeError",{UnableToFetchPackage:ue.bcs.struct("UnableToFetchPackage",{packageId:Pt.Address}),NotAPackage:ue.bcs.struct("NotAPackage",{objectId:Pt.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:Pt.Address,ticketId:Pt.Address})}),U4=ue.bcs.struct("ModuleId",{address:Pt.Address,name:ue.bcs.string()}),Cw=ue.bcs.struct("MoveLocation",{module:U4,function:ue.bcs.u16(),instruction:ue.bcs.u16(),functionName:ue.bcs.option(ue.bcs.string())}),L4=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}),$4=ue.bcs.enum("TypeArgumentError",{TypeNotFound:null,ConstraintNotSatisfied:null}),F4=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:Pt.Address}),InsufficientCoinBalance:null,CoinBalanceOverflow:null,PublishErrorNonZeroAddress:null,SuiMoveVerificationError:null,MovePrimitiveRuntimeError:ue.bcs.option(Cw),MoveAbort:ue.bcs.tuple([Cw,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:L4}),TypeArgumentError:ue.bcs.struct("TypeArgumentError",{argumentIdx:ue.bcs.u16(),kind:$4}),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:R4}),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(Pt.Address)}),AddressDeniedForCoin:ue.bcs.struct("AddressDeniedForCoin",{address:Pt.Address,coinType:ue.bcs.string()}),CoinTypeGlobalPause:ue.bcs.struct("CoinTypeGlobalPause",{coinType:ue.bcs.string()}),ExecutionCancelledDueToRandomnessUnavailable:null}),Nw=ue.bcs.enum("ExecutionStatus",{Success:null,Failed:ue.bcs.struct("ExecutionFailed",{error:F4,command:ue.bcs.option(ue.bcs.u64())})}),Dw=ue.bcs.struct("GasCostSummary",{computationCost:ue.bcs.u64(),storageCost:ue.bcs.u64(),storageRebate:ue.bcs.u64(),nonRefundableStorageFee:ue.bcs.u64()}),q4=ue.bcs.struct("TransactionEffectsV1",{status:Nw,executedEpoch:ue.bcs.u64(),gasUsed:Dw,modifiedAtVersions:ue.bcs.vector(ue.bcs.tuple([Pt.Address,ue.bcs.u64()])),sharedObjects:ue.bcs.vector(Pt.SuiObjectRef),transactionDigest:Pt.ObjectDigest,created:ue.bcs.vector(ue.bcs.tuple([Pt.SuiObjectRef,Pt.Owner])),mutated:ue.bcs.vector(ue.bcs.tuple([Pt.SuiObjectRef,Pt.Owner])),unwrapped:ue.bcs.vector(ue.bcs.tuple([Pt.SuiObjectRef,Pt.Owner])),deleted:ue.bcs.vector(Pt.SuiObjectRef),unwrappedThenDeleted:ue.bcs.vector(Pt.SuiObjectRef),wrapped:ue.bcs.vector(Pt.SuiObjectRef),gasObject:ue.bcs.tuple([Pt.SuiObjectRef,Pt.Owner]),eventsDigest:ue.bcs.option(Pt.ObjectDigest),dependencies:ue.bcs.vector(Pt.ObjectDigest)}),Xp=ue.bcs.tuple([ue.bcs.u64(),Pt.ObjectDigest]),V4=ue.bcs.enum("ObjectIn",{NotExist:null,Exist:ue.bcs.tuple([Xp,Pt.Owner])}),z4=ue.bcs.enum("ObjectOut",{NotExist:null,ObjectWrite:ue.bcs.tuple([Pt.ObjectDigest,Pt.Owner]),PackageWrite:Xp}),G4=ue.bcs.enum("IDOperation",{None:null,Created:null,Deleted:null}),H4=ue.bcs.struct("EffectsObjectChange",{inputState:V4,outputState:z4,idOperation:G4}),W4=ue.bcs.enum("UnchangedSharedKind",{ReadOnlyRoot:Xp,MutateDeleted:ue.bcs.u64(),ReadDeleted:ue.bcs.u64(),Cancelled:ue.bcs.u64(),PerEpochConfig:null}),K4=ue.bcs.struct("TransactionEffectsV2",{status:Nw,executedEpoch:ue.bcs.u64(),gasUsed:Dw,transactionDigest:Pt.ObjectDigest,gasObjectIndex:ue.bcs.option(ue.bcs.u32()),eventsDigest:ue.bcs.option(Pt.ObjectDigest),dependencies:ue.bcs.vector(Pt.ObjectDigest),lamportVersion:ue.bcs.u64(),changedObjects:ue.bcs.vector(ue.bcs.tuple([Pt.Address,H4])),unchangedSharedObjects:ue.bcs.vector(ue.bcs.tuple([Pt.Address,W4])),auxDataDigest:ue.bcs.option(Pt.ObjectDigest)}),X4=ue.bcs.enum("TransactionEffects",{V1:q4,V2:K4})});var Yp=Me((pJ,Lw)=>{"use strict";var Zp=Object.defineProperty,J4=Object.getOwnPropertyDescriptor,Z4=Object.getOwnPropertyNames,Y4=Object.prototype.hasOwnProperty,Q4=(t,e)=>{for(var r in e)Zp(t,r,{get:e[r],enumerable:!0})},ej=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Z4(e))!Y4.call(t,i)&&i!==r&&Zp(t,i,{get:()=>e[i],enumerable:!(n=J4(e,i))||n.enumerable});return t},tj=t=>ej(Zp({},"__esModule",{value:!0}),t),Uw={};Q4(Uw,{pureBcsSchemaFromTypeName:()=>Jp});Lw.exports=tj(Uw);var Xi=br(),rj=ql();function Jp(t){switch(t){case"u8":return Xi.bcs.u8();case"u16":return Xi.bcs.u16();case"u32":return Xi.bcs.u32();case"u64":return Xi.bcs.u64();case"u128":return Xi.bcs.u128();case"u256":return Xi.bcs.u256();case"bool":return Xi.bcs.bool();case"string":return Xi.bcs.string();case"id":case"address":return rj.Address}let e=t.match(/^(vector|option)<(.+)>$/);if(e){let[r,n]=e.slice(1);return r==="vector"?Xi.bcs.vector(Jp(n)):Xi.bcs.option(Jp(n))}throw new Error(`Invalid Pure type name: ${t}`)}});var zn=Me((mJ,Fw)=>{"use strict";var Qp=Object.defineProperty,nj=Object.getOwnPropertyDescriptor,ij=Object.getOwnPropertyNames,sj=Object.prototype.hasOwnProperty,oj=(t,e)=>{for(var r in e)Qp(t,r,{get:e[r],enumerable:!0})},aj=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ij(e))!sj.call(t,i)&&i!==r&&Qp(t,i,{get:()=>e[i],enumerable:!(n=nj(e,i))||n.enumerable});return t},uj=t=>aj(Qp({},"__esModule",{value:!0}),t),$w={};oj($w,{BcsType:()=>fj.BcsType,TypeTagSerializer:()=>lj.TypeTagSerializer,bcs:()=>hj,pureBcsSchemaFromTypeName:()=>dj.pureBcsSchemaFromTypeName});Fw.exports=uj($w);var Ji=br(),Dt=ql(),cj=Rw(),lj=$l(),fj=br(),dj=Yp(),hj={...Ji.bcs,U8:Ji.bcs.u8(),U16:Ji.bcs.u16(),U32:Ji.bcs.u32(),U64:Ji.bcs.u64(),U128:Ji.bcs.u128(),U256:Ji.bcs.u256(),ULEB128:Ji.bcs.uleb128(),Bool:Ji.bcs.bool(),String:Ji.bcs.string(),Address:Dt.Address,AppId:Dt.AppId,Argument:Dt.Argument,CallArg:Dt.CallArg,Command:Dt.Command,CompressedSignature:Dt.CompressedSignature,GasData:Dt.GasData,Intent:Dt.Intent,IntentMessage:Dt.IntentMessage,IntentScope:Dt.IntentScope,IntentVersion:Dt.IntentVersion,MultiSig:Dt.MultiSig,MultiSigPkMap:Dt.MultiSigPkMap,MultiSigPublicKey:Dt.MultiSigPublicKey,ObjectArg:Dt.ObjectArg,ObjectDigest:Dt.ObjectDigest,Owner:Dt.Owner,PasskeyAuthenticator:Dt.PasskeyAuthenticator,ProgrammableMoveCall:Dt.ProgrammableMoveCall,ProgrammableTransaction:Dt.ProgrammableTransaction,PublicKey:Dt.PublicKey,SenderSignedData:Dt.SenderSignedData,SenderSignedTransaction:Dt.SenderSignedTransaction,SharedObjectRef:Dt.SharedObjectRef,StructTag:Dt.StructTag,SuiObjectRef:Dt.SuiObjectRef,TransactionData:Dt.TransactionData,TransactionDataV1:Dt.TransactionDataV1,TransactionEffects:cj.TransactionEffects,TransactionExpiration:Dt.TransactionExpiration,TransactionKind:Dt.TransactionKind,TypeTag:Dt.TypeTag}});var Gw=Me((gJ,zw)=>{"use strict";var e0=Object.defineProperty,pj=Object.getOwnPropertyDescriptor,mj=Object.getOwnPropertyNames,gj=Object.prototype.hasOwnProperty,yj=(t,e)=>{for(var r in e)e0(t,r,{get:e[r],enumerable:!0})},_j=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mj(e))!gj.call(t,i)&&i!==r&&e0(t,i,{get:()=>e[i],enumerable:!(n=pj(e,i))||n.enumerable});return t},vj=t=>_j(e0({},"__esModule",{value:!0}),t),qw={};yj(qw,{formatAddress:()=>bj,formatDigest:()=>wj});zw.exports=vj(qw);var Vw="\u2026";function bj(t){if(t.length<=6)return t;let e=t.startsWith("0x")?2:0;return`0x${t.slice(e,e+4)}${Vw}${t.slice(-4)}`}function wj(t){return`${t.slice(0,10)}${Vw}`}});var Jw=Me((yJ,Xw)=>{"use strict";var t0=Object.defineProperty,Mj=Object.getOwnPropertyDescriptor,Sj=Object.getOwnPropertyNames,kj=Object.prototype.hasOwnProperty,Oj=(t,e)=>{for(var r in e)t0(t,r,{get:e[r],enumerable:!0})},Ej=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Sj(e))!kj.call(t,i)&&i!==r&&t0(t,i,{get:()=>e[i],enumerable:!(n=Mj(e,i))||n.enumerable});return t},Aj=t=>Ej(t0({},"__esModule",{value:!0}),t),Hw={};Oj(Hw,{MIST_PER_SUI:()=>Tj,MOVE_STDLIB_ADDRESS:()=>xj,SUI_CLOCK_OBJECT_ID:()=>Cj,SUI_DECIMALS:()=>Ij,SUI_FRAMEWORK_ADDRESS:()=>Kw,SUI_SYSTEM_ADDRESS:()=>Pj,SUI_SYSTEM_MODULE_NAME:()=>jj,SUI_SYSTEM_STATE_OBJECT_ID:()=>Dj,SUI_TYPE_ARG:()=>Nj});Xw.exports=Aj(Hw);var Ww=$r(),Ij=9,Tj=BigInt(1e9),xj="0x1",Kw="0x2",Pj="0x3",Cj=(0,Ww.normalizeSuiObjectId)("0x6"),jj="sui_system",Nj=`${Kw}::sui::SUI`,Dj=(0,Ww.normalizeSuiObjectId)("0x5")});var Zw=Me(Vl=>{"use strict";Object.defineProperty(Vl,"__esModule",{value:!0});Vl.crypto=void 0;var oo=require("crypto");Vl.crypto=oo&&typeof oo=="object"&&"webcrypto"in oo?oo.webcrypto:oo&&typeof oo=="object"&&"randomBytes"in oo?oo:void 0});var Gl=Me(tt=>{"use strict";Object.defineProperty(tt,"__esModule",{value:!0});tt.wrapXOFConstructorWithOpts=tt.wrapConstructorWithOpts=tt.wrapConstructor=tt.Hash=tt.nextTick=tt.swap32IfBE=tt.byteSwapIfBE=tt.swap8IfBE=tt.isLE=void 0;tt.isBytes=Qw;tt.anumber=r0;tt.abytes=Ca;tt.ahash=Bj;tt.aexists=Rj;tt.aoutput=Uj;tt.u8=Lj;tt.u32=$j;tt.clean=Fj;tt.createView=qj;tt.rotr=Vj;tt.rotl=zj;tt.byteSwap=i0;tt.byteSwap32=e1;tt.bytesToHex=Hj;tt.hexToBytes=Wj;tt.asyncLoop=Xj;tt.utf8ToBytes=s0;tt.bytesToUtf8=Jj;tt.toBytes=zl;tt.kdfInputToBytes=Zj;tt.concatBytes=Yj;tt.checkOpts=Qj;tt.createHasher=r1;tt.createOptHasher=n1;tt.createXOFer=i1;tt.randomBytes=e5;var Pa=Zw();function Qw(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function r0(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Ca(t,...e){if(!Qw(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 Bj(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r0(t.outputLen),r0(t.blockLen)}function Rj(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 Uj(t,e){Ca(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Lj(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function $j(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Fj(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function qj(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Vj(t,e){return t<<32-e|t>>>e}function zj(t,e){return t<<e|t>>>32-e>>>0}tt.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function i0(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}tt.swap8IfBE=tt.isLE?t=>t:t=>i0(t);tt.byteSwapIfBE=tt.swap8IfBE;function e1(t){for(let e=0;e<t.length;e++)t[e]=i0(t[e]);return t}tt.swap32IfBE=tt.isLE?t=>t:e1;var t1=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Gj=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Hj(t){if(Ca(t),t1)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Gj[t[r]];return e}var ws={_0:48,_9:57,A:65,F:70,a:97,f:102};function Yw(t){if(t>=ws._0&&t<=ws._9)return t-ws._0;if(t>=ws.A&&t<=ws.F)return t-(ws.A-10);if(t>=ws.a&&t<=ws.f)return t-(ws.a-10)}function Wj(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(t1)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=Yw(t.charCodeAt(s)),u=Yw(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 Kj=async()=>{};tt.nextTick=Kj;async function Xj(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,tt.nextTick)(),n+=s)}}function s0(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Jj(t){return new TextDecoder().decode(t)}function zl(t){return typeof t=="string"&&(t=s0(t)),Ca(t),t}function Zj(t){return typeof t=="string"&&(t=s0(t)),Ca(t),t}function Yj(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Ca(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 Qj(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 n0=class{};tt.Hash=n0;function r1(t){let e=n=>t().update(zl(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function n1(t){let e=(n,i)=>t(i).update(zl(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}function i1(t){let e=(n,i)=>t(i).update(zl(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}tt.wrapConstructor=r1;tt.wrapConstructorWithOpts=n1;tt.wrapXOFConstructorWithOpts=i1;function e5(t=32){if(Pa.crypto&&typeof Pa.crypto.getRandomValues=="function")return Pa.crypto.getRandomValues(new Uint8Array(t));if(Pa.crypto&&typeof Pa.crypto.randomBytes=="function")return Uint8Array.from(Pa.crypto.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}});var s1=Me(ja=>{"use strict";Object.defineProperty(ja,"__esModule",{value:!0});ja.BSIGMA=void 0;ja.G1s=t5;ja.G2s=r5;var Hl=Gl();ja.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 t5(t,e,r,n,i){return t=t+e+i|0,n=(0,Hl.rotr)(n^t,16),r=r+n|0,e=(0,Hl.rotr)(e^r,12),{a:t,b:e,c:r,d:n}}function r5(t,e,r,n,i){return t=t+e+i|0,n=(0,Hl.rotr)(n^t,8),r=r+n|0,e=(0,Hl.rotr)(e^r,7),{a:t,b:e,c:r,d:n}}});var a1=Me(pn=>{"use strict";Object.defineProperty(pn,"__esModule",{value:!0});pn.SHA512_IV=pn.SHA384_IV=pn.SHA224_IV=pn.SHA256_IV=pn.HashMD=void 0;pn.setBigUint64=o1;pn.Chi=n5;pn.Maj=i5;var Zi=Gl();function o1(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 n5(t,e,r){return t&e^~t&r}function i5(t,e,r){return t&e^t&r^e&r}var o0=class extends Zi.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,Zi.createView)(this.buffer)}update(e){(0,Zi.aexists)(this),e=(0,Zi.toBytes)(e),(0,Zi.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,Zi.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,Zi.aexists)(this),(0,Zi.aoutput)(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,(0,Zi.clean)(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let _=o;_<i;_++)r[_]=0;o1(n,i-8,BigInt(this.length*8),s),this.process(n,0);let u=(0,Zi.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()}};pn.HashMD=o0;pn.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);pn.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);pn.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);pn.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var T1=Me(kt=>{"use strict";Object.defineProperty(kt,"__esModule",{value:!0});kt.toBig=kt.shrSL=kt.shrSH=kt.rotrSL=kt.rotrSH=kt.rotrBL=kt.rotrBH=kt.rotr32L=kt.rotr32H=kt.rotlSL=kt.rotlSH=kt.rotlBL=kt.rotlBH=kt.add5L=kt.add5H=kt.add4L=kt.add4H=kt.add3L=kt.add3H=void 0;kt.add=M1;kt.fromBig=u0;kt.split=u1;var Wl=BigInt(2**32-1),a0=BigInt(32);function u0(t,e=!1){return e?{h:Number(t&Wl),l:Number(t>>a0&Wl)}:{h:Number(t>>a0&Wl)|0,l:Number(t&Wl)|0}}function u1(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}=u0(t[s],e);[n[s],i[s]]=[o,u]}return[n,i]}var c1=(t,e)=>BigInt(t>>>0)<<a0|BigInt(e>>>0);kt.toBig=c1;var l1=(t,e,r)=>t>>>r;kt.shrSH=l1;var f1=(t,e,r)=>t<<32-r|e>>>r;kt.shrSL=f1;var d1=(t,e,r)=>t>>>r|e<<32-r;kt.rotrSH=d1;var h1=(t,e,r)=>t<<32-r|e>>>r;kt.rotrSL=h1;var p1=(t,e,r)=>t<<64-r|e>>>r-32;kt.rotrBH=p1;var m1=(t,e,r)=>t>>>r-32|e<<64-r;kt.rotrBL=m1;var g1=(t,e)=>e;kt.rotr32H=g1;var y1=(t,e)=>t;kt.rotr32L=y1;var _1=(t,e,r)=>t<<r|e>>>32-r;kt.rotlSH=_1;var v1=(t,e,r)=>e<<r|t>>>32-r;kt.rotlSL=v1;var b1=(t,e,r)=>e<<r-32|t>>>64-r;kt.rotlBH=b1;var w1=(t,e,r)=>t<<r-32|e>>>64-r;kt.rotlBL=w1;function M1(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var S1=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0);kt.add3L=S1;var k1=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;kt.add3H=k1;var O1=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0);kt.add4L=O1;var E1=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0;kt.add4H=E1;var A1=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0);kt.add5L=A1;var I1=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0;kt.add5H=I1;var s5={fromBig:u0,split:u1,toBig:c1,shrSH:l1,shrSL:f1,rotrSH:d1,rotrSL:h1,rotrBH:p1,rotrBL:m1,rotr32H:g1,rotr32L:y1,rotlSH:_1,rotlSL:v1,rotlBH:b1,rotlBL:w1,add:M1,add3L:S1,add3H:k1,add4L:O1,add4H:E1,add5H:I1,add5L:A1};kt.default=s5});var C1=Me(Pn=>{"use strict";Object.defineProperty(Pn,"__esModule",{value:!0});Pn.blake2s=Pn.BLAKE2s=Pn.blake2b=Pn.BLAKE2b=Pn.BLAKE2=void 0;Pn.compress=P1;var Dr=s1(),o5=a1(),Qr=T1(),at=Gl(),Er=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Ee=new Uint32Array(32);function ao(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Ee[2*t],d=Ee[2*t+1],p=Ee[2*e],_=Ee[2*e+1],b=Ee[2*r],O=Ee[2*r+1],T=Ee[2*n],x=Ee[2*n+1],F=Qr.add3L(c,p,o);d=Qr.add3H(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:Qr.rotr32H(x,T),Dl:Qr.rotr32L(x,T)},{h:O,l:b}=Qr.add(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Qr.rotrSH(_,p,24),Bl:Qr.rotrSL(_,p,24)},Ee[2*t]=c,Ee[2*t+1]=d,Ee[2*e]=p,Ee[2*e+1]=_,Ee[2*r]=b,Ee[2*r+1]=O,Ee[2*n]=T,Ee[2*n+1]=x}function uo(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Ee[2*t],d=Ee[2*t+1],p=Ee[2*e],_=Ee[2*e+1],b=Ee[2*r],O=Ee[2*r+1],T=Ee[2*n],x=Ee[2*n+1],F=Qr.add3L(c,p,o);d=Qr.add3H(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:Qr.rotrSH(x,T,16),Dl:Qr.rotrSL(x,T,16)},{h:O,l:b}=Qr.add(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Qr.rotrBH(_,p,63),Bl:Qr.rotrBL(_,p,63)},Ee[2*t]=c,Ee[2*t+1]=d,Ee[2*e]=p,Ee[2*e+1]=_,Ee[2*r]=b,Ee[2*r+1]=O,Ee[2*n]=T,Ee[2*n+1]=x}function x1(t,e={},r,n,i){if((0,at.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 Lu=class extends at.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,(0,at.anumber)(e),(0,at.anumber)(r),this.blockLen=e,this.outputLen=r,this.buffer=new Uint8Array(e),this.buffer32=(0,at.u32)(this.buffer)}update(e){(0,at.aexists)(this),e=(0,at.toBytes)(e),(0,at.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,at.swap32IfBE)(i),this.compress(i,0,!1),(0,at.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,at.swap32IfBE)(_);for(let b=0;c+r<s;b+=i.length,c+=r)this.length+=r,this.compress(_,b,!1);(0,at.swap32IfBE)(_);continue}n.set(e.subarray(c,c+d),this.pos),this.pos+=d,this.length+=d,c+=d}return this}digestInto(e){(0,at.aexists)(this),(0,at.aoutput)(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,(0,at.clean)(this.buffer.subarray(r)),(0,at.swap32IfBE)(n),this.compress(n,0,!0),(0,at.swap32IfBE)(n);let i=(0,at.u32)(e);this.get().forEach((s,o)=>i[o]=(0,at.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()}};Pn.BLAKE2=Lu;var Kl=class extends Lu{constructor(e={}){let r=e.dkLen===void 0?64:e.dkLen;super(128,r),this.v0l=Er[0]|0,this.v0h=Er[1]|0,this.v1l=Er[2]|0,this.v1h=Er[3]|0,this.v2l=Er[4]|0,this.v2h=Er[5]|0,this.v3l=Er[6]|0,this.v3h=Er[7]|0,this.v4l=Er[8]|0,this.v4h=Er[9]|0,this.v5l=Er[10]|0,this.v5h=Er[11]|0,this.v6l=Er[12]|0,this.v6h=Er[13]|0,this.v7l=Er[14]|0,this.v7h=Er[15]|0,x1(r,e,64,16,16);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=(0,at.toBytes)(n),o=n.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=(0,at.toBytes)(s);let u=(0,at.u32)(s);this.v4l^=(0,at.swap8IfBE)(u[0]),this.v4h^=(0,at.swap8IfBE)(u[1]),this.v5l^=(0,at.swap8IfBE)(u[2]),this.v5h^=(0,at.swap8IfBE)(u[3])}if(i!==void 0){i=(0,at.toBytes)(i);let u=(0,at.u32)(i);this.v6l^=(0,at.swap8IfBE)(u[0]),this.v6h^=(0,at.swap8IfBE)(u[1]),this.v7l^=(0,at.swap8IfBE)(u[2]),this.v7h^=(0,at.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)=>Ee[d]=c),Ee.set(Er,16);let{h:i,l:s}=Qr.fromBig(BigInt(this.length));Ee[24]=Er[8]^s,Ee[25]=Er[9]^i,n&&(Ee[28]=~Ee[28],Ee[29]=~Ee[29]);let o=0,u=Dr.BSIGMA;for(let c=0;c<12;c++)ao(0,4,8,12,e,r+2*u[o++]),uo(0,4,8,12,e,r+2*u[o++]),ao(1,5,9,13,e,r+2*u[o++]),uo(1,5,9,13,e,r+2*u[o++]),ao(2,6,10,14,e,r+2*u[o++]),uo(2,6,10,14,e,r+2*u[o++]),ao(3,7,11,15,e,r+2*u[o++]),uo(3,7,11,15,e,r+2*u[o++]),ao(0,5,10,15,e,r+2*u[o++]),uo(0,5,10,15,e,r+2*u[o++]),ao(1,6,11,12,e,r+2*u[o++]),uo(1,6,11,12,e,r+2*u[o++]),ao(2,7,8,13,e,r+2*u[o++]),uo(2,7,8,13,e,r+2*u[o++]),ao(3,4,9,14,e,r+2*u[o++]),uo(3,4,9,14,e,r+2*u[o++]);this.v0l^=Ee[0]^Ee[16],this.v0h^=Ee[1]^Ee[17],this.v1l^=Ee[2]^Ee[18],this.v1h^=Ee[3]^Ee[19],this.v2l^=Ee[4]^Ee[20],this.v2h^=Ee[5]^Ee[21],this.v3l^=Ee[6]^Ee[22],this.v3h^=Ee[7]^Ee[23],this.v4l^=Ee[8]^Ee[24],this.v4h^=Ee[9]^Ee[25],this.v5l^=Ee[10]^Ee[26],this.v5h^=Ee[11]^Ee[27],this.v6l^=Ee[12]^Ee[28],this.v6h^=Ee[13]^Ee[29],this.v7l^=Ee[14]^Ee[30],this.v7h^=Ee[15]^Ee[31],(0,at.clean)(Ee)}destroy(){this.destroyed=!0,(0,at.clean)(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Pn.BLAKE2b=Kl;Pn.blake2b=(0,at.createOptHasher)(t=>new Kl(t));function P1(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,Dr.G1s)(i,c,b,F,r[e+t[ee++]])),{a:i,b:c,c:b,d:F}=(0,Dr.G2s)(i,c,b,F,r[e+t[ee++]]),{a:s,b:d,c:O,d:R}=(0,Dr.G1s)(s,d,O,R,r[e+t[ee++]]),{a:s,b:d,c:O,d:R}=(0,Dr.G2s)(s,d,O,R,r[e+t[ee++]]),{a:o,b:p,c:T,d:H}=(0,Dr.G1s)(o,p,T,H,r[e+t[ee++]]),{a:o,b:p,c:T,d:H}=(0,Dr.G2s)(o,p,T,H,r[e+t[ee++]]),{a:u,b:_,c:x,d:J}=(0,Dr.G1s)(u,_,x,J,r[e+t[ee++]]),{a:u,b:_,c:x,d:J}=(0,Dr.G2s)(u,_,x,J,r[e+t[ee++]]),{a:i,b:d,c:T,d:J}=(0,Dr.G1s)(i,d,T,J,r[e+t[ee++]]),{a:i,b:d,c:T,d:J}=(0,Dr.G2s)(i,d,T,J,r[e+t[ee++]]),{a:s,b:p,c:x,d:F}=(0,Dr.G1s)(s,p,x,F,r[e+t[ee++]]),{a:s,b:p,c:x,d:F}=(0,Dr.G2s)(s,p,x,F,r[e+t[ee++]]),{a:o,b:_,c:b,d:R}=(0,Dr.G1s)(o,_,b,R,r[e+t[ee++]]),{a:o,b:_,c:b,d:R}=(0,Dr.G2s)(o,_,b,R,r[e+t[ee++]]),{a:u,b:c,c:O,d:H}=(0,Dr.G1s)(u,c,O,H,r[e+t[ee++]]),{a:u,b:c,c:O,d:H}=(0,Dr.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 Fr=o5.SHA256_IV,Xl=class extends Lu{constructor(e={}){let r=e.dkLen===void 0?32:e.dkLen;super(64,r),this.v0=Fr[0]|0,this.v1=Fr[1]|0,this.v2=Fr[2]|0,this.v3=Fr[3]|0,this.v4=Fr[4]|0,this.v5=Fr[5]|0,this.v6=Fr[6]|0,this.v7=Fr[7]|0,x1(r,e,32,8,8);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=(0,at.toBytes)(n),o=n.length),this.v0^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=(0,at.toBytes)(s);let u=(0,at.u32)(s);this.v4^=(0,at.swap8IfBE)(u[0]),this.v5^=(0,at.swap8IfBE)(u[1])}if(i!==void 0){i=(0,at.toBytes)(i);let u=(0,at.u32)(i);this.v6^=(0,at.swap8IfBE)(u[0]),this.v7^=(0,at.swap8IfBE)(u[1])}if(n!==void 0){(0,at.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}=Qr.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}=P1(Dr.BSIGMA,r,e,10,this.v0,this.v1,this.v2,this.v3,this.v4,this.v5,this.v6,this.v7,Fr[0],Fr[1],Fr[2],Fr[3],s^Fr[4],i^Fr[5],n?~Fr[6]:Fr[6],Fr[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,at.clean)(this.buffer32),this.set(0,0,0,0,0,0,0,0)}};Pn.BLAKE2s=Xl;Pn.blake2s=(0,at.createOptHasher)(t=>new Xl(t))});var c0=Me(Na=>{"use strict";Object.defineProperty(Na,"__esModule",{value:!0});Na.blake2b=Na.BLAKE2b=void 0;var j1=C1();Na.BLAKE2b=j1.BLAKE2b;Na.blake2b=j1.blake2b});var d0=Me((OJ,D1)=>{"use strict";var f0=Object.defineProperty,a5=Object.getOwnPropertyDescriptor,u5=Object.getOwnPropertyNames,c5=Object.prototype.hasOwnProperty,l5=(t,e)=>{for(var r in e)f0(t,r,{get:e[r],enumerable:!0})},f5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of u5(e))!c5.call(t,i)&&i!==r&&f0(t,i,{get:()=>e[i],enumerable:!(n=a5(e,i))||n.enumerable});return t},d5=t=>f5(f0({},"__esModule",{value:!0}),t),N1={};l5(N1,{deriveDynamicFieldID:()=>m5});D1.exports=d5(N1);var h5=br(),p5=c0(),l0=zn();function m5(t,e,r){let n=l0.bcs.Address.serialize(t).toBytes(),i=l0.bcs.TypeTag.serialize(e).toBytes(),s=l0.bcs.u64().serialize(r.length).toBytes(),o=p5.blake2b.create({dkLen:32});return o.update(new Uint8Array([240])),o.update(n),o.update(s),o.update(r),o.update(i),`0x${(0,h5.toHex)(o.digest().slice(0,32))}`}});var Jl=Me((EJ,$1)=>{"use strict";var h0=Object.defineProperty,g5=Object.getOwnPropertyDescriptor,y5=Object.getOwnPropertyNames,_5=Object.prototype.hasOwnProperty,v5=(t,e)=>{for(var r in e)h0(t,r,{get:e[r],enumerable:!0})},b5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of y5(e))!_5.call(t,i)&&i!==r&&h0(t,i,{get:()=>e[i],enumerable:!(n=g5(e,i))||n.enumerable});return t},w5=t=>b5(h0({},"__esModule",{value:!0}),t),L1={};v5(L1,{MIST_PER_SUI:()=>Ms.MIST_PER_SUI,MOVE_STDLIB_ADDRESS:()=>Ms.MOVE_STDLIB_ADDRESS,SUI_ADDRESS_LENGTH:()=>co.SUI_ADDRESS_LENGTH,SUI_CLOCK_OBJECT_ID:()=>Ms.SUI_CLOCK_OBJECT_ID,SUI_DECIMALS:()=>Ms.SUI_DECIMALS,SUI_FRAMEWORK_ADDRESS:()=>Ms.SUI_FRAMEWORK_ADDRESS,SUI_SYSTEM_ADDRESS:()=>Ms.SUI_SYSTEM_ADDRESS,SUI_SYSTEM_MODULE_NAME:()=>Ms.SUI_SYSTEM_MODULE_NAME,SUI_SYSTEM_STATE_OBJECT_ID:()=>Ms.SUI_SYSTEM_STATE_OBJECT_ID,SUI_TYPE_ARG:()=>Ms.SUI_TYPE_ARG,deriveDynamicFieldID:()=>M5.deriveDynamicFieldID,formatAddress:()=>B1.formatAddress,formatDigest:()=>B1.formatDigest,fromB64:()=>Yi.fromB64,fromBase58:()=>Yi.fromBase58,fromBase64:()=>Yi.fromBase64,fromHEX:()=>Yi.fromHEX,fromHex:()=>Yi.fromHex,isValidNamedPackage:()=>U1.isValidNamedPackage,isValidNamedType:()=>U1.isValidNamedType,isValidSuiAddress:()=>co.isValidSuiAddress,isValidSuiNSName:()=>R1.isValidSuiNSName,isValidSuiObjectId:()=>co.isValidSuiObjectId,isValidTransactionDigest:()=>co.isValidTransactionDigest,normalizeStructTag:()=>co.normalizeStructTag,normalizeSuiAddress:()=>co.normalizeSuiAddress,normalizeSuiNSName:()=>R1.normalizeSuiNSName,normalizeSuiObjectId:()=>co.normalizeSuiObjectId,parseStructTag:()=>co.parseStructTag,toB64:()=>Yi.toB64,toBase58:()=>Yi.toBase58,toBase64:()=>Yi.toBase64,toHEX:()=>Yi.toHEX,toHex:()=>Yi.toHex});$1.exports=w5(L1);var B1=Gw(),co=$r(),Yi=br(),R1=Ll(),Ms=Jw(),U1=Ru(),M5=d0()});var g0=Me((AJ,z1)=>{"use strict";var m0=Object.defineProperty,S5=Object.getOwnPropertyDescriptor,k5=Object.getOwnPropertyNames,O5=Object.prototype.hasOwnProperty,E5=(t,e)=>{for(var r in e)m0(t,r,{get:e[r],enumerable:!0})},A5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k5(e))!O5.call(t,i)&&i!==r&&m0(t,i,{get:()=>e[i],enumerable:!(n=S5(e,i))||n.enumerable});return t},I5=t=>A5(m0({},"__esModule",{value:!0}),t),q1={};E5(q1,{getPureBcsSchema:()=>p0,isTxContext:()=>R5,normalizedTypeToMoveTypeSignature:()=>U5,pureBcsSchemaFromOpenMoveTypeSignatureBody:()=>V1});z1.exports=I5(q1);var ur=zn(),F1=Jl(),$u=$r(),T5="object",x5="ID",P5="ascii",C5="String",j5="string",N5="String",D5="option",B5="Option";function R5(t){let e=typeof t.body=="object"&&"datatype"in t.body?t.body.datatype:null;return!!e&&(0,$u.normalizeSuiAddress)(e.package)===(0,$u.normalizeSuiAddress)("0x2")&&e.module==="tx_context"&&e.type==="TxContext"}function p0(t){if(typeof t=="string")switch(t){case"address":return ur.bcs.Address;case"bool":return ur.bcs.Bool;case"u8":return ur.bcs.U8;case"u16":return ur.bcs.U16;case"u32":return ur.bcs.U32;case"u64":return ur.bcs.U64;case"u128":return ur.bcs.U128;case"u256":return ur.bcs.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t){if(t.vector==="u8")return ur.bcs.vector(ur.bcs.U8).transform({input:r=>typeof r=="string"?new TextEncoder().encode(r):r,output:r=>r});let e=p0(t.vector);return e?ur.bcs.vector(e):null}if("datatype"in t){let e=(0,$u.normalizeSuiAddress)(t.datatype.package);if(e===(0,$u.normalizeSuiAddress)(F1.MOVE_STDLIB_ADDRESS)){if(t.datatype.module===P5&&t.datatype.type===C5||t.datatype.module===j5&&t.datatype.type===N5)return ur.bcs.String;if(t.datatype.module===D5&&t.datatype.type===B5){let r=p0(t.datatype.typeParameters[0]);return r?ur.bcs.vector(r):null}}if(e===(0,$u.normalizeSuiAddress)(F1.SUI_FRAMEWORK_ADDRESS)&&t.datatype.module===T5&&t.datatype.type===x5)return ur.bcs.Address}return null}function U5(t){return typeof t=="object"&&"Reference"in t?{ref:"&",body:Fu(t.Reference)}:typeof t=="object"&&"MutableReference"in t?{ref:"&mut",body:Fu(t.MutableReference)}:{ref:null,body:Fu(t)}}function Fu(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:Fu(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(Fu)}};if("TypeParameter"in t)return{typeParameter:t.TypeParameter};throw new Error(`Unexpected type ${JSON.stringify(t)}`)}function V1(t){if(typeof t=="string")switch(t){case"address":return ur.bcs.Address;case"bool":return ur.bcs.Bool;case"u8":return ur.bcs.U8;case"u16":return ur.bcs.U16;case"u32":return ur.bcs.U32;case"u64":return ur.bcs.U64;case"u128":return ur.bcs.U128;case"u256":return ur.bcs.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t)return ur.bcs.vector(V1(t.vector));throw new Error(`Expected pure typeSignature, but got ${JSON.stringify(t)}`)}});var Da=Me((IJ,H1)=>{"use strict";var _0=Object.defineProperty,L5=Object.getOwnPropertyDescriptor,$5=Object.getOwnPropertyNames,F5=Object.prototype.hasOwnProperty,q5=(t,e)=>{for(var r in e)_0(t,r,{get:e[r],enumerable:!0})},V5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $5(e))!F5.call(t,i)&&i!==r&&_0(t,i,{get:()=>e[i],enumerable:!(n=L5(e,i))||n.enumerable});return t},z5=t=>V5(_0({},"__esModule",{value:!0}),t),G1={};q5(G1,{Inputs:()=>W5});H1.exports=z5(G1);var G5=br(),y0=$r();function H5(t){return{$kind:"Pure",Pure:{bytes:t instanceof Uint8Array?(0,G5.toBase64)(t):t.toBase64()}}}var W5={Pure:H5,ObjectRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{digest:e,version:r,objectId:(0,y0.normalizeSuiAddress)(t)}}}},SharedObjectRef({objectId:t,mutable:e,initialSharedVersion:r}){return{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{mutable:e,initialSharedVersion:r,objectId:(0,y0.normalizeSuiAddress)(t)}}}},ReceivingRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"Receiving",Receiving:{digest:e,version:r,objectId:(0,y0.normalizeSuiAddress)(t)}}}}}});var Qi=Me((TJ,ik)=>{"use strict";var I0=Object.defineProperty,K5=Object.getOwnPropertyDescriptor,X5=Object.getOwnPropertyNames,J5=Object.prototype.hasOwnProperty,Z5=(t,e)=>{for(var r in e)I0(t,r,{get:e[r],enumerable:!0})},Y5=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of X5(e))!J5.call(t,i)&&i!==r&&I0(t,i,{get:()=>e[i],enumerable:!(n=K5(e,i))||n.enumerable});return t},Q5=t=>Y5(I0({},"__esModule",{value:!0}),t),W1={};Z5(W1,{BIC_REGEX:()=>X1,CUID2_REGEX:()=>J1,DECIMAL_REGEX:()=>Z1,EMAIL_REGEX:()=>Y1,EMOJI_REGEX:()=>Q1,HEXADECIMAL_REGEX:()=>e2,HEX_COLOR_REGEX:()=>t2,IMEI_REGEX:()=>r2,IPV4_REGEX:()=>n2,IPV6_REGEX:()=>i2,IP_REGEX:()=>s2,ISO_DATE_REGEX:()=>o2,ISO_DATE_TIME_REGEX:()=>a2,ISO_TIMESTAMP_REGEX:()=>l2,ISO_TIME_REGEX:()=>u2,ISO_TIME_SECOND_REGEX:()=>c2,ISO_WEEK_REGEX:()=>f2,MAC48_REGEX:()=>d2,MAC64_REGEX:()=>h2,MAC_REGEX:()=>p2,OCTAL_REGEX:()=>m2,ULID_REGEX:()=>g2,UUID_REGEX:()=>y2,ValiError:()=>Ql,_addIssue:()=>ne,_isLuhnAlgo:()=>T0,_isValidObjectKey:()=>Xo,_stringify:()=>mn,any:()=>ZM,array:()=>YM,arrayAsync:()=>QM,awaitAsync:()=>K1,bic:()=>M2,bigint:()=>eS,blob:()=>tS,boolean:()=>rS,brand:()=>S2,bytes:()=>k2,check:()=>O2,checkAsync:()=>E2,checkItems:()=>A2,config:()=>y7,creditCard:()=>I2,cuid2:()=>T2,custom:()=>nS,customAsync:()=>iS,date:()=>sS,decimal:()=>x2,deleteGlobalConfig:()=>t7,deleteGlobalMessage:()=>n7,deleteSchemaMessage:()=>s7,deleteSpecificMessage:()=>a7,email:()=>P2,emoji:()=>C2,empty:()=>j2,endsWith:()=>N2,entriesFromList:()=>c7,enum:()=>S0,enum_:()=>S0,everyItem:()=>D2,excludes:()=>B2,fallback:()=>_7,fallbackAsync:()=>v7,file:()=>oS,filterItems:()=>R2,findItem:()=>U2,finite:()=>L2,flatten:()=>b7,forward:()=>w7,forwardAsync:()=>M7,function:()=>k0,function_:()=>k0,getDefault:()=>Ss,getDefaults:()=>v0,getDefaultsAsync:()=>b0,getDotPath:()=>w2,getFallback:()=>Gu,getFallbacks:()=>w0,getFallbacksAsync:()=>M0,getGlobalConfig:()=>zu,getGlobalMessage:()=>_2,getSchemaMessage:()=>v2,getSpecificMessage:()=>b2,hash:()=>$2,hexColor:()=>q2,hexadecimal:()=>F2,imei:()=>V2,includes:()=>z2,instance:()=>aS,integer:()=>G2,intersect:()=>uS,intersectAsync:()=>cS,ip:()=>H2,ipv4:()=>W2,ipv6:()=>K2,is:()=>S7,isOfKind:()=>l7,isOfType:()=>f7,isValiError:()=>d7,isoDate:()=>X2,isoDateTime:()=>J2,isoTime:()=>Z2,isoTimeSecond:()=>Y2,isoTimestamp:()=>Q2,isoWeek:()=>eM,keyof:()=>k7,lazy:()=>lS,lazyAsync:()=>fS,length:()=>tM,literal:()=>dS,looseObject:()=>hS,looseObjectAsync:()=>pS,looseTuple:()=>mS,looseTupleAsync:()=>gS,mac:()=>rM,mac48:()=>nM,mac64:()=>iM,map:()=>yS,mapAsync:()=>_S,mapItems:()=>sM,maxBytes:()=>oM,maxLength:()=>aM,maxSize:()=>uM,maxValue:()=>cM,mimeType:()=>lM,minBytes:()=>fM,minLength:()=>dM,minSize:()=>hM,minValue:()=>pM,multipleOf:()=>mM,nan:()=>vS,never:()=>bS,nonEmpty:()=>gM,nonNullable:()=>wS,nonNullableAsync:()=>MS,nonNullish:()=>SS,nonNullishAsync:()=>kS,nonOptional:()=>x0,nonOptionalAsync:()=>P0,normalize:()=>yM,notBytes:()=>_M,notLength:()=>vM,notSize:()=>bM,notValue:()=>wM,null:()=>O0,null_:()=>O0,nullable:()=>OS,nullableAsync:()=>ES,nullish:()=>AS,nullishAsync:()=>IS,number:()=>TS,object:()=>xS,objectAsync:()=>PS,objectWithRest:()=>CS,objectWithRestAsync:()=>jS,octal:()=>MM,omit:()=>O7,optional:()=>C0,optionalAsync:()=>j0,parse:()=>ek,parseAsync:()=>tk,parser:()=>E7,parserAsync:()=>A7,partial:()=>I7,partialAsync:()=>T7,partialCheck:()=>kM,partialCheckAsync:()=>OM,pick:()=>x7,picklist:()=>N0,pipe:()=>P7,pipeAsync:()=>C7,promise:()=>NS,rawCheck:()=>EM,rawCheckAsync:()=>AM,rawTransform:()=>IM,rawTransformAsync:()=>TM,readonly:()=>xM,record:()=>DS,recordAsync:()=>BS,reduceItems:()=>PM,regex:()=>CM,required:()=>j7,requiredAsync:()=>N7,safeInteger:()=>jM,safeParse:()=>rk,safeParseAsync:()=>nk,safeParser:()=>D7,safeParserAsync:()=>B7,set:()=>RS,setAsync:()=>US,setGlobalConfig:()=>e7,setGlobalMessage:()=>r7,setSchemaMessage:()=>i7,setSpecificMessage:()=>o7,size:()=>NM,someItem:()=>DM,sortItems:()=>BM,startsWith:()=>RM,strictObject:()=>LS,strictObjectAsync:()=>$S,strictTuple:()=>FS,strictTupleAsync:()=>qS,string:()=>VS,symbol:()=>zS,toLowerCase:()=>UM,toMaxValue:()=>LM,toMinValue:()=>$M,toUpperCase:()=>FM,transform:()=>qM,transformAsync:()=>VM,trim:()=>zM,trimEnd:()=>GM,trimStart:()=>HM,tuple:()=>GS,tupleAsync:()=>HS,tupleWithRest:()=>WS,tupleWithRestAsync:()=>KS,ulid:()=>WM,undefined:()=>E0,undefined_:()=>E0,union:()=>XS,unionAsync:()=>JS,unknown:()=>ZS,unwrap:()=>R7,url:()=>KM,uuid:()=>XM,value:()=>JM,variant:()=>YS,variantAsync:()=>QS,void:()=>A0,void_:()=>A0});ik.exports=Q5(W1);function K1(){return{kind:"transformation",type:"await",reference:K1,async:!0,async _run(t){return t.value=await t.value,t}}}var X1=/^[A-Z]{6}(?!00)[A-Z\d]{2}(?:[A-Z\d]{3})?$/u,J1=/^[a-z][\da-z]*$/u,Z1=/^\d+$/u,Y1=/^[\w+-]+(?:\.[\w+-]+)*@[\da-z]+(?:[.-][\da-z]+)*\.[a-z]{2,}$/iu,Q1=/^[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u,e2=/^(?:0h|0x)?[\da-f]+$/iu,t2=/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/iu,r2=/^\d{15}$|^\d{2}-\d{6}-\d{6}-\d$/u,n2=/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$/u,i2=/^(?:(?:[\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,s2=/^(?:(?:[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,o2=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])$/u,a2=/^\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,u2=/^(?:0\d|1\d|2[0-3]):[0-5]\d$/u,c2=/^(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}$/u,l2=/^\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,f2=/^\d{4}-W(?:0[1-9]|[1-4]\d|5[0-3])$/u,d2=/^(?:[\da-f]{2}:){5}[\da-f]{2}$|^(?:[\da-f]{2}-){5}[\da-f]{2}$|^(?:[\da-f]{4}\.){2}[\da-f]{4}$/iu,h2=/^(?:[\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,p2=/^(?:[\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,m2=/^(?:0o)?[0-7]+$/iu,g2=/^[\da-hjkmnp-tv-z]{26}$/iu,y2=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu,Ba;function e7(t){Ba={...Ba,...t}}function zu(t){return{lang:t?.lang??Ba?.lang,message:t?.message,abortEarly:t?.abortEarly??Ba?.abortEarly,abortPipeEarly:t?.abortPipeEarly??Ba?.abortPipeEarly}}function t7(){Ba=void 0}var qu;function r7(t,e){qu||(qu=new Map),qu.set(e,t)}function _2(t){return qu?.get(t)}function n7(t){qu?.delete(t)}var Vu;function i7(t,e){Vu||(Vu=new Map),Vu.set(e,t)}function v2(t){return Vu?.get(t)}function s7(t){Vu?.delete(t)}var Ko;function o7(t,e,r){Ko||(Ko=new Map),Ko.get(t)||Ko.set(t,new Map),Ko.get(t).set(r,e)}function b2(t,e){return Ko?.get(t)?.get(e)}function a7(t,e){Ko?.get(t)?.delete(e)}function mn(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??mn(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??b2(t.reference,c.lang)??(d?v2(c.lang):null)??n.message??_2(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 u7=/\D/gu;function T0(t){let e=t.replace(u7,""),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 Xo(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function c7(t,e){let r={};for(let n of t)r[n]=e;return r}function w2(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 l7(t,e){return e.kind===t}function f7(t,e){return e.type===t}function d7(t){return t instanceof Ql}var Ql=class extends Error{issues;constructor(t){super(t[0].message),this.name="ValiError",this.issues=t}};function M2(t){return{kind:"validation",type:"bic",reference:M2,async:!1,expects:null,requirement:X1,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"BIC",e,r),e}}}function S2(t){return{kind:"transformation",type:"brand",reference:S2,async:!1,name:t,_run(e){return e}}}function k2(t,e){return{kind:"validation",type:"bytes",reference:k2,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 O2(t,e){return{kind:"validation",type:"check",reference:O2,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 E2(t,e){return{kind:"validation",type:"check",reference:E2,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 A2(t,e){return{kind:"validation",type:"check_items",reference:A2,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 h7=/^(?:\d{14,19}|\d{4}(?: \d{3,6}){2,4}|\d{4}(?:-\d{3,6}){2,4})$/u,p7=/[- ]/gu,m7=[/^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 I2(t){return{kind:"validation",type:"credit_card",reference:I2,async:!1,expects:null,requirement(e){let r;return h7.test(e)&&(r=e.replace(p7,""))&&m7.some(n=>n.test(r))&&T0(r)},message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"credit card",e,r),e}}}function T2(t){return{kind:"validation",type:"cuid2",reference:T2,async:!1,expects:null,requirement:J1,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"Cuid2",e,r),e}}}function x2(t){return{kind:"validation",type:"decimal",reference:x2,async:!1,expects:null,requirement:Z1,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"decimal",e,r),e}}}function P2(t){return{kind:"validation",type:"email",reference:P2,expects:null,async:!1,requirement:Y1,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"email",e,r),e}}}function C2(t){return{kind:"validation",type:"emoji",reference:C2,async:!1,expects:null,requirement:Q1,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"emoji",e,r),e}}}function j2(t){return{kind:"validation",type:"empty",reference:j2,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 N2(t,e){return{kind:"validation",type:"ends_with",reference:N2,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 D2(t,e){return{kind:"validation",type:"every_item",reference:D2,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 B2(t,e){let r=mn(t);return{kind:"validation",type:"excludes",reference:B2,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 R2(t){return{kind:"transformation",type:"filter_items",reference:R2,async:!1,operation:t,_run(e){return e.value=e.value.filter(this.operation),e}}}function U2(t){return{kind:"transformation",type:"find_item",reference:U2,async:!1,operation:t,_run(e){return e.value=e.value.find(this.operation),e}}}function L2(t){return{kind:"validation",type:"finite",reference:L2,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 g7={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 $2(t,e){return{kind:"validation",type:"hash",reference:$2,expects:null,async:!1,requirement:RegExp(t.map(r=>`^[a-f0-9]{${g7[r]}}$`).join("|"),"iu"),message:e,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&ne(this,"hash",r,n),r}}}function F2(t){return{kind:"validation",type:"hexadecimal",reference:F2,async:!1,expects:null,requirement:e2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"hexadecimal",e,r),e}}}function q2(t){return{kind:"validation",type:"hex_color",reference:q2,async:!1,expects:null,requirement:t2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"hex color",e,r),e}}}function V2(t){return{kind:"validation",type:"imei",reference:V2,async:!1,expects:null,requirement(e){return r2.test(e)&&T0(e)},message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&ne(this,"IMEI",e,r),e}}}function z2(t,e){let r=mn(t);return{kind:"validation",type:"includes",reference:z2,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 G2(t){return{kind:"validation",type:"integer",reference:G2,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 H2(t){return{kind:"validation",type:"ip",reference:H2,async:!1,expects:null,requirement:s2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IP",e,r),e}}}function W2(t){return{kind:"validation",type:"ipv4",reference:W2,async:!1,expects:null,requirement:n2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IPv4",e,r),e}}}function K2(t){return{kind:"validation",type:"ipv6",reference:K2,async:!1,expects:null,requirement:i2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"IPv6",e,r),e}}}function X2(t){return{kind:"validation",type:"iso_date",reference:X2,async:!1,expects:null,requirement:o2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"date",e,r),e}}}function J2(t){return{kind:"validation",type:"iso_date_time",reference:J2,async:!1,expects:null,requirement:a2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"date-time",e,r),e}}}function Z2(t){return{kind:"validation",type:"iso_time",reference:Z2,async:!1,expects:null,requirement:u2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"time",e,r),e}}}function Y2(t){return{kind:"validation",type:"iso_time_second",reference:Y2,async:!1,expects:null,requirement:c2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"time-second",e,r),e}}}function Q2(t){return{kind:"validation",type:"iso_timestamp",reference:Q2,async:!1,expects:null,requirement:l2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"timestamp",e,r),e}}}function eM(t){return{kind:"validation",type:"iso_week",reference:eM,async:!1,expects:null,requirement:f2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"week",e,r),e}}}function tM(t,e){return{kind:"validation",type:"length",reference:tM,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:p2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"MAC",e,r),e}}}function nM(t){return{kind:"validation",type:"mac48",reference:nM,async:!1,expects:null,requirement:d2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"48-bit MAC",e,r),e}}}function iM(t){return{kind:"validation",type:"mac64",reference:iM,async:!1,expects:null,requirement:h2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"64-bit MAC",e,r),e}}}function sM(t){return{kind:"transformation",type:"map_items",reference:sM,async:!1,operation:t,_run(e){return e.value=e.value.map(this.operation),e}}}function oM(t,e){return{kind:"validation",type:"max_bytes",reference:oM,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 aM(t,e){return{kind:"validation",type:"max_length",reference:aM,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 uM(t,e){return{kind:"validation",type:"max_size",reference:uM,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 cM(t,e){return{kind:"validation",type:"max_value",reference:cM,async:!1,expects:`<=${t instanceof Date?t.toJSON():mn(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():mn(r.value)}),r}}}function lM(t,e){return{kind:"validation",type:"mime_type",reference:lM,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 fM(t,e){return{kind:"validation",type:"min_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 dM(t,e){return{kind:"validation",type:"min_length",reference:dM,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 hM(t,e){return{kind:"validation",type:"min_size",reference:hM,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 pM(t,e){return{kind:"validation",type:"min_value",reference:pM,async:!1,expects:`>=${t instanceof Date?t.toJSON():mn(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():mn(r.value)}),r}}}function mM(t,e){return{kind:"validation",type:"multiple_of",reference:mM,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 gM(t){return{kind:"validation",type:"non_empty",reference:gM,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 _M(t,e){return{kind:"validation",type:"not_bytes",reference:_M,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 vM(t,e){return{kind:"validation",type:"not_length",reference:vM,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 bM(t,e){return{kind:"validation",type:"not_size",reference:bM,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 wM(t,e){return{kind:"validation",type:"not_value",reference:wM,async:!1,expects:t instanceof Date?`!${t.toJSON()}`:`!${mn(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():mn(r.value)}),r}}}function MM(t){return{kind:"validation",type:"octal",reference:MM,async:!1,expects:null,requirement:m2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"octal",e,r),e}}}function SM(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 kM(t,e,r){return{kind:"validation",type:"partial_check",reference:kM,async:!1,expects:null,requirement:e,message:r,_run(n,i){return SM(n,t)&&!this.requirement(n.value)&&ne(this,"input",n,i),n}}}function OM(t,e,r){return{kind:"validation",type:"partial_check",reference:OM,async:!0,expects:null,requirement:e,message:r,async _run(n,i){return SM(n,t)&&!await this.requirement(n.value)&&ne(this,"input",n,i),n}}}function EM(t){return{kind:"validation",type:"raw_check",reference:EM,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 AM(t){return{kind:"validation",type:"raw_check",reference:AM,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 IM(t){return{kind:"transformation",type:"raw_transform",reference:IM,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 TM(t){return{kind:"transformation",type:"raw_transform",reference:TM,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 xM(){return{kind:"transformation",type:"readonly",reference:xM,async:!1,_run(t){return t}}}function PM(t,e){return{kind:"transformation",type:"reduce_items",reference:PM,async:!1,operation:t,initial:e,_run(r){return r.value=r.value.reduce(this.operation,this.initial),r}}}function CM(t,e){return{kind:"validation",type:"regex",reference:CM,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 jM(t){return{kind:"validation",type:"safe_integer",reference:jM,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 NM(t,e){return{kind:"validation",type:"size",reference:NM,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 DM(t,e){return{kind:"validation",type:"some_item",reference:DM,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 BM(t){return{kind:"transformation",type:"sort_items",reference:BM,async:!1,operation:t,_run(e){return e.value=e.value.sort(this.operation),e}}}function RM(t,e){return{kind:"validation",type:"starts_with",reference:RM,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 UM(){return{kind:"transformation",type:"to_lower_case",reference:UM,async:!1,_run(t){return t.value=t.value.toLowerCase(),t}}}function LM(t){return{kind:"transformation",type:"to_max_value",reference:LM,async:!1,requirement:t,_run(e){return e.value=e.value>this.requirement?this.requirement:e.value,e}}}function $M(t){return{kind:"transformation",type:"to_min_value",reference:$M,async:!1,requirement:t,_run(e){return e.value=e.value<this.requirement?this.requirement:e.value,e}}}function FM(){return{kind:"transformation",type:"to_upper_case",reference:FM,async:!1,_run(t){return t.value=t.value.toUpperCase(),t}}}function qM(t){return{kind:"transformation",type:"transform",reference:qM,async:!1,operation:t,_run(e){return e.value=this.operation(e.value),e}}}function VM(t){return{kind:"transformation",type:"transform",reference:VM,async:!0,operation:t,async _run(e){return e.value=await this.operation(e.value),e}}}function zM(){return{kind:"transformation",type:"trim",reference:zM,async:!1,_run(t){return t.value=t.value.trim(),t}}}function GM(){return{kind:"transformation",type:"trim_end",reference:GM,async:!1,_run(t){return t.value=t.value.trimEnd(),t}}}function HM(){return{kind:"transformation",type:"trim_start",reference:HM,async:!1,_run(t){return t.value=t.value.trimStart(),t}}}function WM(t){return{kind:"validation",type:"ulid",reference:WM,async:!1,expects:null,requirement:g2,message:t,_run(e,r){return e.typed&&!this.requirement.test(e.value)&&ne(this,"ULID",e,r),e}}}function KM(t){return{kind:"validation",type:"url",reference:KM,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 XM(t){return{kind:"validation",type:"uuid",reference:XM,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 JM(t,e){return{kind:"validation",type:"value",reference:JM,async:!1,expects:t instanceof Date?t.toJSON():mn(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():mn(r.value)}),r}}}function y7(t,e){return{...t,_run(r,n){return t._run(r,{...n,...e})}}}function Gu(t,e,r){return typeof t.fallback=="function"?t.fallback(e,r):t.fallback}function _7(t,e){return{...t,fallback:e,_run(r,n){return t._run(r,n),r.issues?{typed:!0,value:Gu(this,r,n)}:r}}}function v7(t,e){return{...t,fallback:e,async:!0,async _run(r,n){return t._run(r,n),r.issues?{typed:!0,value:await Gu(this,r,n)}:r}}}function b7(t){let e={};for(let r of t)if(r.path){let n=w2(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 w7(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 M7(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 Ss(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function v0(t){if("entries"in t){let e={};for(let r in t.entries)e[r]=v0(t.entries[r]);return e}return"items"in t?t.items.map(v0):Ss(t)}async function b0(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([e,r])=>[e,await b0(r)]))):"items"in t?Promise.all(t.items.map(b0)):Ss(t)}function w0(t){if("entries"in t){let e={};for(let r in t.entries)e[r]=w0(t.entries[r]);return e}return"items"in t?t.items.map(w0):Gu(t)}async function M0(t){return"entries"in t?Object.fromEntries(await Promise.all(Object.entries(t.entries).map(async([e,r])=>[e,await M0(r)]))):"items"in t?Promise.all(t.items.map(M0)):Gu(t)}function S7(t,e){return!t._run({typed:!1,value:e},{abortEarly:!0}).issues}function ZM(){return{kind:"schema",type:"any",reference:ZM,expects:"any",async:!1,_run(t){return t.typed=!0,t}}}function YM(t,e){return{kind:"schema",type:"array",reference:YM,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 QM(t,e){return{kind:"schema",type:"array",reference:QM,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 eS(t){return{kind:"schema",type:"bigint",reference:eS,expects:"bigint",async:!1,message:t,_run(e,r){return typeof e.value=="bigint"?e.typed=!0:ne(this,"type",e,r),e}}}function tS(t){return{kind:"schema",type:"blob",reference:tS,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 nS(t,e){return{kind:"schema",type:"custom",reference:nS,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 iS(t,e){return{kind:"schema",type:"custom",reference:iS,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 sS(t){return{kind:"schema",type:"date",reference:sS,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 S0(t,e){let r=Object.entries(t).filter(([n])=>isNaN(+n)).map(([,n])=>n);return{kind:"schema",type:"enum",reference:S0,expects:r.map(mn).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 oS(t){return{kind:"schema",type:"file",reference:oS,expects:"File",async:!1,message:t,_run(e,r){return e.value instanceof File?e.typed=!0:ne(this,"type",e,r),e}}}function k0(t){return{kind:"schema",type:"function",reference:k0,expects:"Function",async:!1,message:t,_run(e,r){return typeof e.value=="function"?e.typed=!0:ne(this,"type",e,r),e}}}function aS(t,e){return{kind:"schema",type:"instance",reference:aS,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 Zl(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=Zl(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=Zl(t[r],e[r]);if(n.issue)return n;t[r]=n.value}return{value:t}}}return{issue:!0}}function uS(t,e){return{kind:"schema",type:"intersect",reference:uS,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=Zl(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 cS(t,e){return{kind:"schema",type:"intersect",reference:cS,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=Zl(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 lS(t){return{kind:"schema",type:"lazy",reference:lS,expects:"unknown",async:!1,getter:t,_run(e,r){return this.getter(e.value)._run(e,r)}}}function fS(t){return{kind:"schema",type:"lazy",reference:fS,expects:"unknown",async:!0,getter:t,async _run(e,r){return(await this.getter(e.value))._run(e,r)}}}function dS(t,e){return{kind:"schema",type:"literal",reference:dS,expects:mn(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 hS(t,e){return{kind:"schema",type:"loose_object",reference:hS,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)Xo(i,s)&&!(s in this.entries)&&(r.value[s]=i[s])}else ne(this,"type",r,n);return r}}}function pS(t,e){return{kind:"schema",type:"loose_object",reference:pS,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)Xo(i,o)&&!(o in this.entries)&&(r.value[o]=i[o])}else ne(this,"type",r,n);return r}}}function mS(t,e){return{kind:"schema",type:"loose_tuple",reference:mS,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 gS(t,e){return{kind:"schema",type:"loose_tuple",reference:gS,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 _S(t,e,r){return{kind:"schema",type:"map",reference:_S,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 vS(t){return{kind:"schema",type:"nan",reference:vS,expects:"NaN",async:!1,message:t,_run(e,r){return Number.isNaN(e.value)?e.typed=!0:ne(this,"type",e,r),e}}}function bS(t){return{kind:"schema",type:"never",reference:bS,expects:"never",async:!1,message:t,_run(e,r){return ne(this,"type",e,r),e}}}function wS(t,e){return{kind:"schema",type:"non_nullable",reference:wS,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 MS(t,e){return{kind:"schema",type:"non_nullable",reference:MS,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 SS(t,e){return{kind:"schema",type:"non_nullish",reference:SS,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 kS(t,e){return{kind:"schema",type:"non_nullish",reference:kS,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 P0(t,e){return{kind:"schema",type:"non_optional",reference:P0,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 O0(t){return{kind:"schema",type:"null",reference:O0,expects:"null",async:!1,message:t,_run(e,r){return e.value===null?e.typed=!0:ne(this,"type",e,r),e}}}function OS(t,...e){let r={kind:"schema",type:"nullable",reference:OS,expects:`${t.expects} | null`,async:!1,wrapped:t,_run(n,i){return n.value===null&&("default"in this&&(n.value=Ss(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 ES(t,...e){let r={kind:"schema",type:"nullable",reference:ES,expects:`${t.expects} | null`,async:!0,wrapped:t,async _run(n,i){return n.value===null&&("default"in this&&(n.value=await Ss(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 AS(t,...e){let r={kind:"schema",type:"nullish",reference:AS,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=Ss(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 IS(t,...e){let r={kind:"schema",type:"nullish",reference:IS,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 Ss(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 TS(t){return{kind:"schema",type:"number",reference:TS,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 xS(t,e){return{kind:"schema",type:"object",reference:xS,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 PS(t,e){return{kind:"schema",type:"object",reference:PS,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 CS(t,e,r){return{kind:"schema",type:"object_with_rest",reference:CS,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(Xo(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 jS(t,e,r){return{kind:"schema",type:"object_with_rest",reference:jS,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])=>Xo(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 C0(t,...e){let r={kind:"schema",type:"optional",reference:C0,expects:`${t.expects} | undefined`,async:!1,wrapped:t,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=Ss(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 j0(t,...e){let r={kind:"schema",type:"optional",reference:j0,expects:`${t.expects} | undefined`,async:!0,wrapped:t,async _run(n,i){return n.value===void 0&&("default"in this&&(n.value=await Ss(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 N0(t,e){return{kind:"schema",type:"picklist",reference:N0,expects:t.map(mn).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 NS(t){return{kind:"schema",type:"promise",reference:NS,expects:"Promise",async:!1,message:t,_run(e,r){return e.value instanceof Promise?e.typed=!0:ne(this,"type",e,r),e}}}function DS(t,e,r){return{kind:"schema",type:"record",reference:DS,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(Xo(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 BS(t,e,r){return{kind:"schema",type:"record",reference:BS,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])=>Xo(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 RS(t,e){return{kind:"schema",type:"set",reference:RS,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 US(t,e){return{kind:"schema",type:"set",reference:US,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 LS(t,e){return{kind:"schema",type:"strict_object",reference:LS,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 $S(t,e){return{kind:"schema",type:"strict_object",reference:$S,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 FS(t,e){return{kind:"schema",type:"strict_tuple",reference:FS,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 qS(t,e){return{kind:"schema",type:"strict_tuple",reference:qS,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 VS(t){return{kind:"schema",type:"string",reference:VS,expects:"string",async:!1,message:t,_run(e,r){return typeof e.value=="string"?e.typed=!0:ne(this,"type",e,r),e}}}function zS(t){return{kind:"schema",type:"symbol",reference:zS,expects:"symbol",async:!1,message:t,_run(e,r){return typeof e.value=="symbol"?e.typed=!0:ne(this,"type",e,r),e}}}function GS(t,e){return{kind:"schema",type:"tuple",reference:GS,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 HS(t,e){return{kind:"schema",type:"tuple",reference:HS,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 WS(t,e,r){return{kind:"schema",type:"tuple_with_rest",reference:WS,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 KS(t,e,r){return{kind:"schema",type:"tuple_with_rest",reference:KS,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 E0(t){return{kind:"schema",type:"undefined",reference:E0,expects:"undefined",async:!1,message:t,_run(e,r){return e.value===void 0?e.typed=!0:ne(this,"type",e,r),e}}}function Yl(t){let e;if(t)for(let r of t)e?e.push(...r.issues):e=r.issues;return e}function XS(t,e){return{kind:"schema",type:"union",reference:XS,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:Yl(s)}),r.typed=!0}else{if(o?.length===1)return o[0];ne(this,"type",r,n,{issues:Yl(o)})}return r}}}function JS(t,e){return{kind:"schema",type:"union",reference:JS,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:Yl(s)}),r.typed=!0}else{if(o?.length===1)return o[0];ne(this,"type",r,n,{issues:Yl(o)})}return r}}}function ZS(){return{kind:"schema",type:"unknown",reference:ZS,expects:"unknown",async:!1,_run(t){return t.typed=!0,t}}}function D0(t,e,r=new Set){for(let n of e)n.type==="variant"?D0(t,n.options,r):r.add(n.entries[t].expects);return r}function YS(t,e,r){let n;return{kind:"schema",type:"variant",reference:YS,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=[...D0(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 QS(t,e,r){let n;return{kind:"schema",type:"variant",reference:QS,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=[...D0(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 A0(t){return{kind:"schema",type:"void",reference:A0,expects:"void",async:!1,message:t,_run(e,r){return e.value===void 0?e.typed=!0:ne(this,"type",e,r),e}}}function k7(t,e){return N0(Object.keys(t.entries),e)}function O7(t,e){let r={...t.entries};for(let n of e)delete r[n];return{...t,entries:r}}function ek(t,e,r){let n=t._run({typed:!1,value:e},zu(r));if(n.issues)throw new Ql(n.issues);return n.value}async function tk(t,e,r){let n=await t._run({typed:!1,value:e},zu(r));if(n.issues)throw new Ql(n.issues);return n.value}function E7(t,e){let r=n=>ek(t,n,e);return r.schema=t,r.config=e,r}function A7(t,e){let r=n=>tk(t,n,e);return r.schema=t,r.config=e,r}function I7(t,e){let r={};for(let n in t.entries)r[n]=!e||e.includes(n)?C0(t.entries[n]):t.entries[n];return{...t,entries:r}}function T7(t,e){let r={};for(let n in t.entries)r[n]=!e||e.includes(n)?j0(t.entries[n]):t.entries[n];return{...t,entries:r}}function x7(t,e){let r={};for(let n of e)r[n]=t.entries[n];return{...t,entries:r}}function P7(...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 C7(...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 j7(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 N7(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)?P0(t.entries[o],i):t.entries[o];return{...t,entries:s}}function rk(t,e,r){let n=t._run({typed:!1,value:e},zu(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}async function nk(t,e,r){let n=await t._run({typed:!1,value:e},zu(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}function D7(t,e){let r=n=>rk(t,n,e);return r.schema=t,r.config=e,r}function B7(t,e){let r=n=>nk(t,n,e);return r.schema=t,r.config=e,r}function R7(t){return t.wrapped}});var fo=Me((PJ,dk)=>{"use strict";var B0=Object.defineProperty,U7=Object.getOwnPropertyDescriptor,L7=Object.getOwnPropertyNames,$7=Object.prototype.hasOwnProperty,F7=(t,e)=>{for(var r in e)B0(t,r,{get:e[r],enumerable:!0})},q7=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L7(e))!$7.call(t,i)&&i!==r&&B0(t,i,{get:()=>e[i],enumerable:!(n=U7(e,i))||n.enumerable});return t},V7=t=>q7(B0({},"__esModule",{value:!0}),t),ok={};F7(ok,{$Intent:()=>ck,Argument:()=>Gn,BCSBytes:()=>Hu,Command:()=>lk,GasData:()=>ak,JsonU64:()=>lo,NormalizedCallArg:()=>W7,ObjectArg:()=>R0,ObjectID:()=>Jo,ObjectRef:()=>ef,OpenMoveTypeSignature:()=>uk,OpenMoveTypeSignatureBody:()=>tf,StructTag:()=>z7,SuiAddress:()=>Wu,TransactionData:()=>K7,TransactionExpiration:()=>fk,safeEnum:()=>Ra});dk.exports=V7(ok);var re=Qi(),sk=$r();function Ra(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 Wu=(0,re.pipe)((0,re.string)(),(0,re.transform)(t=>(0,sk.normalizeSuiAddress)(t)),(0,re.check)(sk.isValidSuiAddress)),Jo=Wu,Hu=(0,re.string)(),lo=(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")),ef=(0,re.object)({objectId:Wu,version:lo,digest:(0,re.string)()}),Gn=(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]}))),ak=(0,re.object)({budget:(0,re.nullable)(lo),price:(0,re.nullable)(lo),owner:(0,re.nullable)(Wu),payment:(0,re.nullable)((0,re.array)(ef))}),z7=(0,re.object)({address:(0,re.string)(),module:(0,re.string)(),name:(0,re.string)(),typeParams:(0,re.array)((0,re.string)())}),tf=(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)(()=>tf)}),(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)(()=>tf))})}),(0,re.object)({typeParameter:(0,re.pipe)((0,re.number)(),(0,re.integer)())})]),uk=(0,re.object)({ref:(0,re.nullable)((0,re.union)([(0,re.literal)("&"),(0,re.literal)("&mut")])),body:tf}),G7=(0,re.object)({package:Jo,module:(0,re.string)(),function:(0,re.string)(),typeArguments:(0,re.array)((0,re.string)()),arguments:(0,re.array)(Gn),_argumentTypes:(0,re.optional)((0,re.nullable)((0,re.array)(uk)))}),ck=(0,re.object)({name:(0,re.string)(),inputs:(0,re.record)((0,re.string)(),(0,re.union)([Gn,(0,re.array)(Gn)])),data:(0,re.record)((0,re.string)(),(0,re.unknown)())}),lk=Ra({MoveCall:G7,TransferObjects:(0,re.object)({objects:(0,re.array)(Gn),address:Gn}),SplitCoins:(0,re.object)({coin:Gn,amounts:(0,re.array)(Gn)}),MergeCoins:(0,re.object)({destination:Gn,sources:(0,re.array)(Gn)}),Publish:(0,re.object)({modules:(0,re.array)(Hu),dependencies:(0,re.array)(Jo)}),MakeMoveVec:(0,re.object)({type:(0,re.nullable)((0,re.string)()),elements:(0,re.array)(Gn)}),Upgrade:(0,re.object)({modules:(0,re.array)(Hu),dependencies:(0,re.array)(Jo),package:Jo,ticket:Gn}),$Intent:ck}),R0=Ra({ImmOrOwnedObject:ef,SharedObject:(0,re.object)({objectId:Jo,initialSharedVersion:lo,mutable:(0,re.boolean)()}),Receiving:ef}),H7=Ra({Object:R0,Pure:(0,re.object)({bytes:Hu}),UnresolvedPure:(0,re.object)({value:(0,re.unknown)()}),UnresolvedObject:(0,re.object)({objectId:Jo,version:(0,re.optional)((0,re.nullable)(lo)),digest:(0,re.optional)((0,re.nullable)((0,re.string)())),initialSharedVersion:(0,re.optional)((0,re.nullable)(lo))})}),W7=Ra({Object:R0,Pure:(0,re.object)({bytes:Hu})}),fk=Ra({None:(0,re.literal)(!0),Epoch:lo}),K7=(0,re.object)({version:(0,re.literal)(2),sender:(0,re.nullish)(Wu),expiration:(0,re.nullish)(fk),gasData:ak,inputs:(0,re.array)(H7),commands:(0,re.array)(lk)})});var rf=Me((CJ,yk)=>{"use strict";var U0=Object.defineProperty,X7=Object.getOwnPropertyDescriptor,J7=Object.getOwnPropertyNames,Z7=Object.prototype.hasOwnProperty,Y7=(t,e)=>{for(var r in e)U0(t,r,{get:e[r],enumerable:!0})},Q7=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of J7(e))!Z7.call(t,i)&&i!==r&&U0(t,i,{get:()=>e[i],enumerable:!(n=X7(e,i))||n.enumerable});return t},eN=t=>Q7(U0({},"__esModule",{value:!0}),t),mk={};Y7(mk,{Commands:()=>tN,UpgradePolicy:()=>gk});yk.exports=eN(mk);var hk=br(),es=Qi(),pk=$r(),ts=fo(),gk=(t=>(t[t.COMPATIBLE=0]="COMPATIBLE",t[t.ADDITIVE=128]="ADDITIVE",t[t.DEP_ONLY=192]="DEP_ONLY",t))(gk||{}),tN={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,es.parse)(ts.Argument,r)),address:(0,es.parse)(ts.Argument,e)}}},SplitCoins(t,e){return{$kind:"SplitCoins",SplitCoins:{coin:(0,es.parse)(ts.Argument,t),amounts:e.map(r=>(0,es.parse)(ts.Argument,r))}}},MergeCoins(t,e){return{$kind:"MergeCoins",MergeCoins:{destination:(0,es.parse)(ts.Argument,t),sources:e.map(r=>(0,es.parse)(ts.Argument,r))}}},Publish({modules:t,dependencies:e}){return{$kind:"Publish",Publish:{modules:t.map(r=>typeof r=="string"?r:(0,hk.toBase64)(new Uint8Array(r))),dependencies:e.map(r=>(0,pk.normalizeSuiObjectId)(r))}}},Upgrade({modules:t,dependencies:e,package:r,ticket:n}){return{$kind:"Upgrade",Upgrade:{modules:t.map(i=>typeof i=="string"?i:(0,hk.toBase64)(new Uint8Array(i))),dependencies:e.map(i=>(0,pk.normalizeSuiObjectId)(i)),package:r,ticket:(0,es.parse)(ts.Argument,n)}}},MakeMoveVec({type:t,elements:e}){return{$kind:"MakeMoveVec",MakeMoveVec:{type:t??null,elements:e.map(r=>(0,es.parse)(ts.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,es.parse)(ts.Argument,s)):(0,es.parse)(ts.Argument,i)])),data:r}}}}});var F0=Me((jJ,Sk)=>{"use strict";var $0=Object.defineProperty,rN=Object.getOwnPropertyDescriptor,nN=Object.getOwnPropertyNames,iN=Object.prototype.hasOwnProperty,sN=(t,e)=>{for(var r in e)$0(t,r,{get:e[r],enumerable:!0})},oN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nN(e))!iN.call(t,i)&&i!==r&&$0(t,i,{get:()=>e[i],enumerable:!(n=rN(e,i))||n.enumerable});return t},aN=t=>oN($0({},"__esModule",{value:!0}),t),vk={};sN(vk,{NormalizedCallArg:()=>L0,ObjectRef:()=>nf,SerializedTransactionDataV1:()=>wN,StructTag:()=>Mk,TransactionArgument:()=>rs,TypeTag:()=>sf,serializeV1TransactionData:()=>MN,transactionDataFromV1:()=>SN});Sk.exports=aN(vk);var Ua=br(),Q=Qi(),bk=zn(),Ku=fo(),nf=(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)()])}),uN=(0,Ku.safeEnum)({ImmOrOwned:nf,Shared:(0,Q.object)({objectId:Ku.ObjectID,initialSharedVersion:Ku.JsonU64,mutable:(0,Q.boolean)()}),Receiving:nf}),L0=(0,Ku.safeEnum)({Object:uN,Pure:(0,Q.array)((0,Q.pipe)((0,Q.number)(),(0,Q.integer)()))}),wk=(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")})]),cN=(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))})]),_k=(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}})),sf=(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)(()=>sf)}),(0,Q.object)({struct:(0,Q.lazy)(()=>Mk)}),(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))})]),Mk=(0,Q.object)({address:(0,Q.string)(),module:(0,Q.string)(),name:(0,Q.string)(),typeParams:(0,Q.array)(sf)}),lN=(0,Q.object)({budget:(0,Q.optional)(_k),price:(0,Q.optional)(_k),payment:(0,Q.optional)((0,Q.array)(nf)),owner:(0,Q.optional)((0,Q.string)())}),fN=[wk,(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)())})],rs=(0,Q.union)([...fN]),dN=(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)(rs)}),hN=(0,Q.object)({kind:(0,Q.literal)("TransferObjects"),objects:(0,Q.array)(rs),address:rs}),pN=(0,Q.object)({kind:(0,Q.literal)("SplitCoins"),coin:rs,amounts:(0,Q.array)(rs)}),mN=(0,Q.object)({kind:(0,Q.literal)("MergeCoins"),destination:rs,sources:(0,Q.array)(rs)}),gN=(0,Q.object)({kind:(0,Q.literal)("MakeMoveVec"),type:(0,Q.union)([(0,Q.object)({Some:sf}),(0,Q.object)({None:(0,Q.nullable)((0,Q.literal)(!0))})]),objects:(0,Q.array)(rs)}),yN=(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)())}),_N=(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:rs}),vN=[dN,hN,pN,mN,yN,_N,gN],bN=(0,Q.union)([...vN]),wN=(0,Q.object)({version:(0,Q.literal)(1),sender:(0,Q.optional)((0,Q.string)()),expiration:(0,Q.nullish)(cN),gasConfig:lN,inputs:(0,Q.array)(wk),transactions:(0,Q.array)(bN)});function MN(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,Ua.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:bk.TypeTagSerializer.parseFromStr(r.MakeMoveVec.type)},objects:r.MakeMoveVec.elements.map(n=>ks(n,e))};if(r.MergeCoins)return{kind:"MergeCoins",destination:ks(r.MergeCoins.destination,e),sources:r.MergeCoins.sources.map(n=>ks(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=>ks(n,e))};if(r.Publish)return{kind:"Publish",modules:r.Publish.modules.map(n=>Array.from((0,Ua.fromBase64)(n))),dependencies:r.Publish.dependencies};if(r.SplitCoins)return{kind:"SplitCoins",coin:ks(r.SplitCoins.coin,e),amounts:r.SplitCoins.amounts.map(n=>ks(n,e))};if(r.TransferObjects)return{kind:"TransferObjects",objects:r.TransferObjects.objects.map(n=>ks(n,e)),address:ks(r.TransferObjects.address,e)};if(r.Upgrade)return{kind:"Upgrade",modules:r.Upgrade.modules.map(n=>Array.from((0,Ua.fromBase64)(n))),dependencies:r.Upgrade.dependencies,packageId:r.Upgrade.package,ticket:ks(r.Upgrade.ticket,e)};throw new Error(`Unknown transaction ${Object.keys(r)}`)})}}function ks(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 SN(t){return(0,Q.parse)(Ku.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)(L0,e.value)){let r=(0,Q.parse)(L0,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,Ua.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?bk.TypeTagSerializer.tagToString(e.type.Some):null,elements:e.objects.map(r=>Os(r))}};case"MergeCoins":return{MergeCoins:{destination:Os(e.destination),sources:e.sources.map(r=>Os(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=>Os(s))}}}case"Publish":return{Publish:{modules:e.modules.map(r=>(0,Ua.toBase64)(Uint8Array.from(r))),dependencies:e.dependencies}};case"SplitCoins":return{SplitCoins:{coin:Os(e.coin),amounts:e.amounts.map(r=>Os(r))}};case"TransferObjects":return{TransferObjects:{objects:e.objects.map(r=>Os(r)),address:Os(e.address)}};case"Upgrade":return{Upgrade:{modules:e.modules.map(r=>(0,Ua.toBase64)(Uint8Array.from(r))),dependencies:e.dependencies,package:e.packageId,ticket:Os(e.ticket)}}}throw new Error(`Unknown transaction ${Object.keys(e)}`)})})}function Os(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 Ek=Me((NJ,Ok)=>{"use strict";var q0=Object.defineProperty,kN=Object.getOwnPropertyDescriptor,ON=Object.getOwnPropertyNames,EN=Object.prototype.hasOwnProperty,AN=(t,e)=>{for(var r in e)q0(t,r,{get:e[r],enumerable:!0})},IN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ON(e))!EN.call(t,i)&&i!==r&&q0(t,i,{get:()=>e[i],enumerable:!(n=kN(e,i))||n.enumerable});return t},TN=t=>IN(q0({},"__esModule",{value:!0}),t),kk={};AN(kk,{SerializedTransactionDataV2:()=>RN});Ok.exports=TN(kk);var ke=Qi(),wr=fo();function Xu(t){return(0,ke.union)(Object.entries(t).map(([e,r])=>(0,ke.object)({[e]:r})))}var Oi=Xu({GasCoin:(0,ke.literal)(!0),Input:(0,ke.pipe)((0,ke.number)(),(0,ke.integer)()),Result:(0,ke.pipe)((0,ke.number)(),(0,ke.integer)()),NestedResult:(0,ke.tuple)([(0,ke.pipe)((0,ke.number)(),(0,ke.integer)()),(0,ke.pipe)((0,ke.number)(),(0,ke.integer)())])}),xN=(0,ke.object)({budget:(0,ke.nullable)(wr.JsonU64),price:(0,ke.nullable)(wr.JsonU64),owner:(0,ke.nullable)(wr.SuiAddress),payment:(0,ke.nullable)((0,ke.array)(wr.ObjectRef))}),PN=(0,ke.object)({package:wr.ObjectID,module:(0,ke.string)(),function:(0,ke.string)(),typeArguments:(0,ke.array)((0,ke.string)()),arguments:(0,ke.array)(Oi)}),CN=(0,ke.object)({name:(0,ke.string)(),inputs:(0,ke.record)((0,ke.string)(),(0,ke.union)([Oi,(0,ke.array)(Oi)])),data:(0,ke.record)((0,ke.string)(),(0,ke.unknown)())}),jN=Xu({MoveCall:PN,TransferObjects:(0,ke.object)({objects:(0,ke.array)(Oi),address:Oi}),SplitCoins:(0,ke.object)({coin:Oi,amounts:(0,ke.array)(Oi)}),MergeCoins:(0,ke.object)({destination:Oi,sources:(0,ke.array)(Oi)}),Publish:(0,ke.object)({modules:(0,ke.array)(wr.BCSBytes),dependencies:(0,ke.array)(wr.ObjectID)}),MakeMoveVec:(0,ke.object)({type:(0,ke.nullable)((0,ke.string)()),elements:(0,ke.array)(Oi)}),Upgrade:(0,ke.object)({modules:(0,ke.array)(wr.BCSBytes),dependencies:(0,ke.array)(wr.ObjectID),package:wr.ObjectID,ticket:Oi}),$Intent:CN}),NN=Xu({ImmOrOwnedObject:wr.ObjectRef,SharedObject:(0,ke.object)({objectId:wr.ObjectID,initialSharedVersion:wr.JsonU64,mutable:(0,ke.boolean)()}),Receiving:wr.ObjectRef}),DN=Xu({Object:NN,Pure:(0,ke.object)({bytes:wr.BCSBytes}),UnresolvedPure:(0,ke.object)({value:(0,ke.unknown)()}),UnresolvedObject:(0,ke.object)({objectId:wr.ObjectID,version:(0,ke.optional)((0,ke.nullable)(wr.JsonU64)),digest:(0,ke.optional)((0,ke.nullable)((0,ke.string)())),initialSharedVersion:(0,ke.optional)((0,ke.nullable)(wr.JsonU64))})}),BN=Xu({None:(0,ke.literal)(!0),Epoch:wr.JsonU64}),RN=(0,ke.object)({version:(0,ke.literal)(2),sender:(0,ke.nullish)(wr.SuiAddress),expiration:(0,ke.nullish)(BN),gasData:xN,inputs:(0,ke.array)(DN),commands:(0,ke.array)(jN),digest:(0,ke.optional)((0,ke.nullable)((0,ke.string)()))})});var z0=Me((DJ,jk)=>{"use strict";var V0=Object.defineProperty,UN=Object.getOwnPropertyDescriptor,LN=Object.getOwnPropertyNames,$N=Object.prototype.hasOwnProperty,Tk=t=>{throw TypeError(t)},FN=(t,e)=>{for(var r in e)V0(t,r,{get:e[r],enumerable:!0})},qN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of LN(e))!$N.call(t,i)&&i!==r&&V0(t,i,{get:()=>e[i],enumerable:!(n=UN(e,i))||n.enumerable});return t},VN=t=>qN(V0({},"__esModule",{value:!0}),t),xk=(t,e,r)=>e.has(t)||Tk("Cannot "+r),en=(t,e,r)=>(xk(t,e,"read from private field"),r?r.call(t):e.get(t)),Ak=(t,e,r)=>e.has(t)?Tk("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Ik=(t,e,r,n)=>(xk(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Pk={};FN(Pk,{ClientCache:()=>GN});jk.exports=VN(Pk);var Zo,gn,zN=class Ck{constructor({prefix:e,cache:r}={}){Ak(this,Zo),Ak(this,gn),Ik(this,Zo,e??[]),Ik(this,gn,r??new Map)}read(e,r){let n=[en(this,Zo),...e].join(":");if(en(this,gn).has(n))return en(this,gn).get(n);let i=r();return en(this,gn).set(n,i),typeof i=="object"&&i!==null&&"then"in i?Promise.resolve(i).then(s=>(en(this,gn).set(n,s),s)).catch(s=>{throw en(this,gn).delete(n),s}):i}readSync(e,r){let n=[en(this,Zo),...e].join(":");if(en(this,gn).has(n))return en(this,gn).get(n);let i=r();return en(this,gn).set(n,i),i}clear(e){let r=[...en(this,Zo),...e??[]].join(":");if(!r){en(this,gn).clear();return}for(let n of en(this,gn).keys())n.startsWith(r)&&en(this,gn).delete(n)}scope(e){return new Ck({prefix:[...en(this,Zo),...Array.isArray(e)?e:[e]],cache:en(this,gn)})}};Zo=new WeakMap;gn=new WeakMap;var GN=zN});var H0=Me((BJ,Dk)=>{"use strict";var G0=Object.defineProperty,HN=Object.getOwnPropertyDescriptor,WN=Object.getOwnPropertyNames,KN=Object.prototype.hasOwnProperty,XN=(t,e)=>{for(var r in e)G0(t,r,{get:e[r],enumerable:!0})},JN=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of WN(e))!KN.call(t,i)&&i!==r&&G0(t,i,{get:()=>e[i],enumerable:!(n=HN(e,i))||n.enumerable});return t},ZN=t=>JN(G0({},"__esModule",{value:!0}),t),Nk={};XN(Nk,{PACKAGE_VERSION:()=>YN,TARGETED_RPC_VERSION:()=>QN});Dk.exports=ZN(Nk);var YN="1.34.0",QN="1.51.0"});var Qu=Me((RJ,qk)=>{"use strict";var Z0=Object.defineProperty,eD=Object.getOwnPropertyDescriptor,tD=Object.getOwnPropertyNames,rD=Object.prototype.hasOwnProperty,Rk=t=>{throw TypeError(t)},nD=(t,e)=>{for(var r in e)Z0(t,r,{get:e[r],enumerable:!0})},iD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tD(e))!rD.call(t,i)&&i!==r&&Z0(t,i,{get:()=>e[i],enumerable:!(n=eD(e,i))||n.enumerable});return t},sD=t=>iD(Z0({},"__esModule",{value:!0}),t),Y0=(t,e,r)=>e.has(t)||Rk("Cannot "+r),Ar=(t,e,r)=>(Y0(t,e,"read from private field"),r?r.call(t):e.get(t)),Ju=(t,e,r)=>e.has(t)?Rk("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),of=(t,e,r,n)=>(Y0(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),uf=(t,e,r)=>(Y0(t,e,"access private method"),r),Uk={};nD(Uk,{MvrClient:()=>X0,extractMvrTypes:()=>af,findNamesInTransaction:()=>lD,hasMvrName:()=>Es,replaceNames:()=>fD});qk.exports=sD(Uk);var cf=io(),Q0=Ru(),ho=$r(),oD=H0(),Zu,As,Yu,po,ns,W0,K0,Lk,$k,em,aD="/",uD={"Mvr-Source":`@mysten/sui@${oD.PACKAGE_VERSION}`},X0=class{constructor({cache:e,url:r,pageSize:n=50,overrides:i}){Ju(this,ns),Ju(this,Zu),Ju(this,As),Ju(this,Yu),Ju(this,po),of(this,Zu,e),of(this,As,r),of(this,Yu,n),of(this,po,{packages:i?.packages,types:i?.types}),cD(Ar(this,po))}async resolvePackage({package:e}){return{package:await Ar(this,ns,W0).load(e)}}async resolveType({type:e}){let r=[...af(e)],n=await Ar(this,ns,K0).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:J0(e,i)}}async resolve({types:e=[],packages:r=[]}){let n=new Set;for(let p of e??[])af(p,n);let i=[...n],[s,o]=await Promise.all([i.length>0?Ar(this,ns,K0).loadMany(i):[],r.length>0?Ar(this,ns,W0).loadMany(r):[]]),u={...Ar(this,po)?.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 _=J0(p,u);c[p]={type:_}}let d={};for(let[p,_]of(r??[]).entries()){let b=Ar(this,po)?.packages?.[_]??o[p];if(b instanceof Error)throw b;d[_]={package:b}}return{types:c,packages:d}}};Zu=new WeakMap;As=new WeakMap;Yu=new WeakMap;po=new WeakMap;ns=new WeakSet;W0=function(){return Ar(this,Zu).readSync(["#mvrPackageDataLoader",Ar(this,As)??""],()=>{let t=new cf.DataLoader(async r=>{if(!Ar(this,As))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await uf(this,ns,Lk).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve package: ${i}`))}),e=Ar(this,po)?.packages;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};K0=function(){return Ar(this,Zu).readSync(["#mvrTypeDataLoader",Ar(this,As)??""],()=>{let t=new cf.DataLoader(async r=>{if(!Ar(this,As))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await uf(this,ns,$k).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve type: ${i}`))}),e=Ar(this,po)?.types;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};Lk=async function(t){if(t.length===0)return{};let e=(0,cf.chunk)(t,Ar(this,Yu)),r={};return await Promise.all(e.map(async n=>{let i=await uf(this,ns,em).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};$k=async function(t){if(t.length===0)return{};let e=(0,cf.chunk)(t,Ar(this,Yu)),r={};return await Promise.all(e.map(async n=>{let i=await uf(this,ns,em).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};em=async function(t,e){if(!Ar(this,As))throw new Error("MVR Api URL is not set for the current client");let r=await fetch(`${Ar(this,As)}${t}`,{method:"POST",headers:{"Content-Type":"application/json",...uD},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 cD(t){if(t?.packages)for(let[e,r]of Object.entries(t.packages)){if(!(0,Q0.isValidNamedPackage)(e))throw new Error(`Invalid package name: ${e}`);if(!(0,ho.isValidSuiAddress)((0,ho.normalizeSuiAddress)(r)))throw new Error(`Invalid package ID: ${r}`)}if(t?.types)for(let[e,r]of Object.entries(t.types)){if((0,ho.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,ho.parseStructTag)(r);if(!(0,ho.isValidSuiAddress)(n.address))throw new Error(`Invalid type: ${r}`)}}function af(t,e=new Set){if(typeof t=="string"&&!Es(t))return e;let r=Fk(t)?t:(0,ho.parseStructTag)(t);Es(r.address)&&e.add(`${r.address}::${r.module}::${r.name}`);for(let n of r.typeParams)af(n,e);return e}function J0(t,e){let r=Fk(t)?t:(0,ho.parseStructTag)(t),n=`${r.address}::${r.module}::${r.name}`,i=e[n];return(0,ho.normalizeStructTag)({...r,address:i?i.split("::")[0]:r.address,typeParams:r.typeParams.map(s=>J0(s,e))})}function Es(t){return t.includes(aD)||t.includes("@")||t.includes(".sui")}function Fk(t){return typeof t=="object"&&"address"in t&&"module"in t&&"name"in t&&"typeParams"in t}function lD(t){let e=new Set,r=new Set;for(let n of t.commands)switch(n.$kind){case"MakeMoveVec":n.MakeMoveVec.type&&Bk([n.MakeMoveVec.type]).forEach(o=>{r.add(o)});break;case"MoveCall":let i=n.MoveCall,s=i.package.split("::")[0];if(Es(s)){if(!(0,Q0.isValidNamedPackage)(s))throw new Error(`Invalid package name: ${s}`);e.add(s)}Bk(i.typeArguments??[]).forEach(o=>{r.add(o)});break;default:break}return{packages:[...e],types:[...r]}}function fD(t,e){for(let r of t.commands){if(r.MakeMoveVec?.type){if(!Es(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(Es(s)&&!e.packages[s])throw new Error(`No address found for package: ${s}`);Es(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(Es(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 Bk(t){let e=new Set;for(let r of t)if(Es(r)){if(!(0,Q0.isValidNamedType)(r))throw new Error(`Invalid type with names: ${r}`);e.add(r)}return e}});var nm=Me((UJ,Hk)=>{"use strict";var rm=Object.defineProperty,dD=Object.getOwnPropertyDescriptor,hD=Object.getOwnPropertyNames,pD=Object.prototype.hasOwnProperty,mD=(t,e)=>{for(var r in e)rm(t,r,{get:e[r],enumerable:!0})},gD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of hD(e))!pD.call(t,i)&&i!==r&&rm(t,i,{get:()=>e[i],enumerable:!(n=dD(e,i))||n.enumerable});return t},yD=t=>gD(rm({},"__esModule",{value:!0}),t),zk={};mD(zk,{getClient:()=>Gk,namedPackagesPlugin:()=>bD});Hk.exports=yD(zk);var _D=z0(),vD=Qu(),Vk=Qu(),tm=new WeakMap,bD=t=>{let e;if(t){let r=t.overrides??{packages:{},types:{}};tm.has(r)||tm.set(r,new _D.ClientCache),e=new vD.MvrClient({cache:tm.get(r),url:t.url,pageSize:t.pageSize,overrides:r})}return async(r,n,i)=>{let s=(0,Vk.findNamesInTransaction)(r);if(s.types.length===0&&s.packages.length===0)return i();let o=await(e||Gk(n).core.mvr).resolve({types:s.types,packages:s.packages});(0,Vk.replaceNames)(r,o),await i()}};function Gk(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 am=Me((LJ,Kk)=>{"use strict";var om=Object.defineProperty,wD=Object.getOwnPropertyDescriptor,MD=Object.getOwnPropertyNames,SD=Object.prototype.hasOwnProperty,kD=(t,e)=>{for(var r in e)om(t,r,{get:e[r],enumerable:!0})},OD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of MD(e))!SD.call(t,i)&&i!==r&&om(t,i,{get:()=>e[i],enumerable:!(n=wD(e,i))||n.enumerable});return t},ED=t=>OD(om({},"__esModule",{value:!0}),t),Wk={};kD(Wk,{suiClientResolveTransactionPlugin:()=>jD});Kk.exports=ED(Wk);var AD=Qi(),sm=Jl(),ID=fo(),lf=Da(),im=g0(),TD=io(),xD=50,PD=1000n,CD=5e10;function jD(t){return async function(r,n,i){return await UD(r,t),await RD(r,t),n.onlyTransactionKind||(await ND(r,t),await DD(r,t),await BD(r,t)),await i()}}async function ND(t,e){t.gasConfig.price||(t.gasConfig.price=String(await e.getReferenceGasPrice()))}async function DD(t,e){if(t.gasConfig.budget)return;let r=await e.dryRunTransactionBlock({transactionBlock:t.build({overrides:{gasData:{budget:String(CD),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=PD*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 BD(t,e){if(!t.gasConfig.payment){let n=(await e.getCoins({owner:t.gasConfig.owner||t.sender,coinType:sm.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,AD.parse)(ID.ObjectRef,i))}}async function RD(t,e){let r=t.inputs.filter(p=>p.UnresolvedObject&&!(p.UnresolvedObject.version||p.UnresolvedObject?.initialSharedVersion)),n=[...new Set(r.map(p=>(0,sm.normalizeSuiObjectId)(p.UnresolvedObject.objectId)))],i=n.length?(0,TD.chunk)(n,xD):[],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,sm.normalizeSuiAddress)(_.UnresolvedObject.objectId),T=d.get(O);_.UnresolvedObject.initialSharedVersion??T?.initialSharedVersion?b=lf.Inputs.SharedObjectRef({objectId:O,initialSharedVersion:_.UnresolvedObject.initialSharedVersion||T?.initialSharedVersion,mutable:LD(t,p)}):$D(t,p)&&(b=lf.Inputs.ReceivingRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})),t.inputs[t.inputs.indexOf(_)]=b??lf.Inputs.ObjectRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})}}async function UD(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,im.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,im.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,im.getPureBcsSchema)(_.body);if(F){O.type="pure",r[r.indexOf(T)]=lf.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 LD(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 $D(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=FD(i.MoveCall._argumentTypes[s])||r}}),r}function FD(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 cm=Me(($J,tO)=>{"use strict";var um=Object.defineProperty,qD=Object.getOwnPropertyDescriptor,VD=Object.getOwnPropertyNames,zD=Object.prototype.hasOwnProperty,GD=(t,e)=>{for(var r in e)um(t,r,{get:e[r],enumerable:!0})},HD=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of VD(e))!zD.call(t,i)&&i!==r&&um(t,i,{get:()=>e[i],enumerable:!(n=qD(e,i))||n.enumerable});return t},WD=t=>HD(um({},"__esModule",{value:!0}),t),Yk={};GD(Yk,{getClient:()=>eO,needsTransactionResolution:()=>Qk,resolveTransactionPlugin:()=>ZD});tO.exports=WD(Yk);var KD=Da(),Xk=zn(),XD=nm(),JD=am();function Qk(t,e){return!!(t.inputs.some(r=>r.UnresolvedObject||r.UnresolvedPure)||!e.onlyTransactionKind&&(!t.gasConfig.price||!t.gasConfig.budget||!t.gasConfig.payment))}async function ZD(t,e,r){if(YD(t),!Qk(t,e))return await Jk(t),r();let n=eO(e),i=n.core?.resolveTransactionPlugin()??(0,JD.suiClientResolveTransactionPlugin)(n);return(0,XD.namedPackagesPlugin)()(t,e,async()=>{await i(t,e,async()=>{await Jk(t),await r()})})}function Jk(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 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}function YD(t){for(let e of t.commands)switch(e.$kind){case"SplitCoins":e.SplitCoins.amounts.forEach(r=>{Zk(r,Xk.bcs.U64,t)});break;case"TransferObjects":Zk(e.TransferObjects.address,Xk.bcs.Address,t);break}}function Zk(t,e,r){if(t.$kind!=="Input")return;let n=r.inputs[t.Input];n.$kind==="UnresolvedPure"&&(r.inputs[t.Input]=KD.Inputs.Pure(e.serialize(n.UnresolvedPure.value)))}});var fm=Me((FJ,nO)=>{"use strict";var lm=Object.defineProperty,QD=Object.getOwnPropertyDescriptor,e9=Object.getOwnPropertyNames,t9=Object.prototype.hasOwnProperty,r9=(t,e)=>{for(var r in e)lm(t,r,{get:e[r],enumerable:!0})},n9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of e9(e))!t9.call(t,i)&&i!==r&&lm(t,i,{get:()=>e[i],enumerable:!(n=QD(e,i))||n.enumerable});return t},i9=t=>n9(lm({},"__esModule",{value:!0}),t),rO={};r9(rO,{createObjectMethods:()=>s9});nO.exports=i9(rO);function s9(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 pm=Me((qJ,sO)=>{"use strict";var hm=Object.defineProperty,o9=Object.getOwnPropertyDescriptor,a9=Object.getOwnPropertyNames,u9=Object.prototype.hasOwnProperty,c9=(t,e)=>{for(var r in e)hm(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&&hm(t,i,{get:()=>e[i],enumerable:!(n=o9(e,i))||n.enumerable});return t},f9=t=>l9(hm({},"__esModule",{value:!0}),t),iO={};c9(iO,{createPure:()=>h9});sO.exports=f9(iO);var d9=br(),Ei=zn(),dm=Yp();function h9(t){function e(r,n){if(typeof r=="string")return t((0,dm.pureBcsSchemaFromTypeName)(r).serialize(n));if(r instanceof Uint8Array||(0,d9.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(Ei.bcs.U8.serialize(r)),e.u16=r=>t(Ei.bcs.U16.serialize(r)),e.u32=r=>t(Ei.bcs.U32.serialize(r)),e.u64=r=>t(Ei.bcs.U64.serialize(r)),e.u128=r=>t(Ei.bcs.U128.serialize(r)),e.u256=r=>t(Ei.bcs.U256.serialize(r)),e.bool=r=>t(Ei.bcs.Bool.serialize(r)),e.string=r=>t(Ei.bcs.String.serialize(r)),e.address=r=>t(Ei.bcs.Address.serialize(r)),e.id=e.address,e.vector=(r,n)=>t(Ei.bcs.vector((0,dm.pureBcsSchemaFromTypeName)(r)).serialize(n)),e.option=(r,n)=>t(Ei.bcs.option((0,dm.pureBcsSchemaFromTypeName)(r)).serialize(n)),e}});var uO=Me((VJ,aO)=>{"use strict";var mm=Object.defineProperty,p9=Object.getOwnPropertyDescriptor,m9=Object.getOwnPropertyNames,g9=Object.prototype.hasOwnProperty,y9=(t,e)=>{for(var r in e)mm(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&&mm(t,i,{get:()=>e[i],enumerable:!(n=p9(e,i))||n.enumerable});return t},v9=t=>_9(mm({},"__esModule",{value:!0}),t),oO={};y9(oO,{hashTypedData:()=>w9});aO.exports=v9(oO);var b9=c0();function w9(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,b9.blake2b)(n,{dkLen:32})}});var La=Me((zJ,fO)=>{"use strict";var vm=Object.defineProperty,M9=Object.getOwnPropertyDescriptor,S9=Object.getOwnPropertyNames,k9=Object.prototype.hasOwnProperty,O9=(t,e)=>{for(var r in e)vm(t,r,{get:e[r],enumerable:!0})},E9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of S9(e))!k9.call(t,i)&&i!==r&&vm(t,i,{get:()=>e[i],enumerable:!(n=M9(e,i))||n.enumerable});return t},A9=t=>E9(vm({},"__esModule",{value:!0}),t),lO={};O9(lO,{TransactionDataBuilder:()=>_m});fO.exports=A9(lO);var I9=br(),gm=Qi(),ff=zn(),T9=$r(),ym=fo(),x9=F0(),P9=uO();function cO(t){return(0,T9.normalizeSuiAddress)(t).replace("0x","")}var _m=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=ff.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=ff.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,gm.parse)(ym.TransactionData,e)):new t((0,gm.parse)(ym.TransactionData,(0,x9.transactionDataFromV1)(e)))}static getDigestFromBytes(e){let r=(0,P9.hashTypedData)("TransactionData",e);return(0,I9.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 ff.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:cO(c),expiration:u||{None:!0},gasData:{payment:d.payment,owner:cO(this.gasData.owner??c),price:BigInt(d.price),budget:BigInt(d.budget)},kind:{ProgrammableTransaction:{inputs:i,commands:s}}};return ff.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,gm.parse)(ym.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 wm=Me((GJ,mO)=>{"use strict";var bm=Object.defineProperty,C9=Object.getOwnPropertyDescriptor,j9=Object.getOwnPropertyNames,N9=Object.prototype.hasOwnProperty,D9=(t,e)=>{for(var r in e)bm(t,r,{get:e[r],enumerable:!0})},B9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j9(e))!N9.call(t,i)&&i!==r&&bm(t,i,{get:()=>e[i],enumerable:!(n=C9(e,i))||n.enumerable});return t},R9=t=>B9(bm({},"__esModule",{value:!0}),t),dO={};D9(dO,{extractMutableReference:()=>hO,extractReference:()=>pO,extractStructTag:()=>$9,getIdFromCallArg:()=>F9,isArgument:()=>q9});mO.exports=R9(dO);var U9=Qi(),ec=$r(),L9=fo();function hO(t){return typeof t=="object"&&"MutableReference"in t?t.MutableReference:void 0}function pO(t){return typeof t=="object"&&"Reference"in t?t.Reference:void 0}function $9(t){if(typeof t=="object"&&"Struct"in t)return t;let e=pO(t),r=hO(t);if(typeof e=="object"&&"Struct"in e)return e;if(typeof r=="object"&&"Struct"in r)return r}function F9(t){if(typeof t=="string")return(0,ec.normalizeSuiAddress)(t);if(t.Object)return t.Object.ImmOrOwnedObject?(0,ec.normalizeSuiAddress)(t.Object.ImmOrOwnedObject.objectId):t.Object.Receiving?(0,ec.normalizeSuiAddress)(t.Object.Receiving.objectId):(0,ec.normalizeSuiAddress)(t.Object.SharedObject.objectId);if(t.UnresolvedObject)return(0,ec.normalizeSuiAddress)(t.UnresolvedObject.objectId)}function q9(t){return(0,U9.is)(L9.Argument,t)}});var ra=Me((HJ,IO)=>{"use strict";var Em=Object.defineProperty,V9=Object.getOwnPropertyDescriptor,z9=Object.getOwnPropertyNames,G9=Object.prototype.hasOwnProperty,vO=t=>{throw TypeError(t)},H9=(t,e)=>{for(var r in e)Em(t,r,{get:e[r],enumerable:!0})},W9=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z9(e))!G9.call(t,i)&&i!==r&&Em(t,i,{get:()=>e[i],enumerable:!(n=V9(e,i))||n.enumerable});return t},K9=t=>W9(Em({},"__esModule",{value:!0}),t),Am=(t,e,r)=>e.has(t)||vO("Cannot "+r),_e=(t,e,r)=>(Am(t,e,"read from private field"),r?r.call(t):e.get(t)),is=(t,e,r)=>e.has(t)?vO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),nr=(t,e,r,n)=>(Am(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Ir=(t,e,r)=>(Am(t,e,"access private method"),r),bO={};H9(bO,{Transaction:()=>Q9,isTransaction:()=>EO});IO.exports=K9(bO);var hf=br(),mo=Qi(),X9=$r(),Yo=rf(),Qo=fo(),gO=F0(),J9=Ek(),df=Da(),wO=cm(),Z9=fm(),Y9=pm(),tc=La(),yO=wm(),ea,ta,Is,ss,Hn,Wn,Ai,go,Ye,yr,MO,pf,mf,gf,yf,km,Im,SO,kO;function Mm(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 OO=Symbol.for("@mysten/transaction");function EO(t){return!!t&&typeof t=="object"&&t[OO]===!0}var _O={buildPlugins:new Map,serializationPlugins:new Map},Sm=Symbol.for("@mysten/transaction/registry");function rc(){try{let t=globalThis;return t[Sm]||(t[Sm]=_O),t[Sm]}catch{return _O}}var AO=class Om{constructor(){is(this,yr),is(this,ea),is(this,ta),is(this,Is,new Map),is(this,ss,[]),is(this,Hn,[]),is(this,Wn,new Set),is(this,Ai,new Set),is(this,go,new Map),is(this,Ye),this.object=(0,Z9.createObjectMethods)(r=>{if(typeof r=="function")return this.object(this.add(r));if(typeof r=="object"&&(0,mo.is)(Qo.Argument,r))return r;let n=(0,yO.getIdFromCallArg)(r),i=_e(this,Ye).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:_e(this,Ye).inputs.indexOf(i),type:"object"}:Ir(this,yr,mf).call(this,"object",typeof r=="string"?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:(0,X9.normalizeSuiAddress)(r)}}:r)});let e=rc();nr(this,Ye,new tc.TransactionDataBuilder),nr(this,ta,[...e.buildPlugins.values()]),nr(this,ea,[...e.serializationPlugins.values()])}static fromKind(e){let r=new Om;return nr(r,Ye,tc.TransactionDataBuilder.fromKindBytes(typeof e=="string"?(0,hf.fromBase64)(e):e)),nr(r,ss,_e(r,Ye).inputs.slice()),nr(r,Hn,_e(r,Ye).commands.slice()),nr(r,Wn,new Set(_e(r,Hn).map((n,i)=>i))),r}static from(e){let r=new Om;return EO(e)?nr(r,Ye,new tc.TransactionDataBuilder(e.getData())):typeof e!="string"||!e.startsWith("{")?nr(r,Ye,tc.TransactionDataBuilder.fromBytes(typeof e=="string"?(0,hf.fromBase64)(e):e)):nr(r,Ye,tc.TransactionDataBuilder.restore(JSON.parse(e))),nr(r,ss,_e(r,Ye).inputs.slice()),nr(r,Hn,_e(r,Ye).commands.slice()),nr(r,Wn,new Set(_e(r,Hn).map((n,i)=>i))),r}static registerGlobalSerializationPlugin(e,r){rc().serializationPlugins.set(e,r??e)}static unregisterGlobalSerializationPlugin(e){rc().serializationPlugins.delete(e)}static registerGlobalBuildPlugin(e,r){rc().buildPlugins.set(e,r??e)}static unregisterGlobalBuildPlugin(e){rc().buildPlugins.delete(e)}addSerializationPlugin(e){_e(this,ea).push(e)}addBuildPlugin(e){_e(this,ta).push(e)}addIntentResolver(e,r){if(_e(this,Is).has(e)&&_e(this,Is).get(e)!==r)throw new Error(`Intent resolver for ${e} already exists`);_e(this,Is).set(e,r)}setSender(e){_e(this,Ye).sender=e}setSenderIfNotSet(e){_e(this,Ye).sender||(_e(this,Ye).sender=e)}setExpiration(e){_e(this,Ye).expiration=e?(0,mo.parse)(Qo.TransactionExpiration,e):null}setGasPrice(e){_e(this,Ye).gasConfig.price=String(e)}setGasBudget(e){_e(this,Ye).gasConfig.budget=String(e)}setGasBudgetIfNotSet(e){_e(this,Ye).gasData.budget==null&&(_e(this,Ye).gasConfig.budget=String(e))}setGasOwner(e){_e(this,Ye).gasConfig.owner=e}setGasPayment(e){_e(this,Ye).gasConfig.payment=e.map(r=>(0,mo.parse)(Qo.ObjectRef,r))}get blockData(){return(0,gO.serializeV1TransactionData)(_e(this,Ye).snapshot())}getData(){return _e(this,Ye).snapshot()}get[OO](){return!0}get pure(){return Object.defineProperty(this,"pure",{enumerable:!1,value:(0,Y9.createPure)(e=>(0,hf.isSerializedBcs)(e)?Ir(this,yr,mf).call(this,"pure",{$kind:"Pure",Pure:{bytes:e.toBase64()}}):Ir(this,yr,mf).call(this,"pure",(0,mo.is)(Qo.NormalizedCallArg,e)?(0,mo.parse)(Qo.NormalizedCallArg,e):e instanceof Uint8Array?df.Inputs.Pure(e):{$kind:"UnresolvedPure",UnresolvedPure:{value:e}}))}),this.pure}get gas(){return{$kind:"GasCoin",GasCoin:!0}}objectRef(...e){return this.object(df.Inputs.ObjectRef(...e))}receivingRef(...e){return this.object(df.Inputs.ReceivingRef(...e))}sharedObjectRef(...e){return this.object(df.Inputs.SharedObjectRef(...e))}add(e){if(typeof e=="function"){if(_e(this,go).has(e))return _e(this,go).get(e);let r=Ir(this,yr,MO).call(this),n=e(r);if(!(n&&typeof n=="object"&&"then"in n))return nr(this,Wn,_e(r,Wn)),_e(this,go).set(e,n),n;let i=Ir(this,yr,pf).call(this,{$kind:"$Intent",$Intent:{name:"AsyncTransactionThunk",inputs:{},data:{resultIndex:_e(this,Ye).commands.length,result:null}}});_e(this,Ai).add(Promise.resolve(n).then(o=>{i.$Intent.data.result=o}));let s=Mm(()=>i.$Intent.data.resultIndex);return _e(this,go).set(e,s),s}else Ir(this,yr,pf).call(this,e);return Mm(_e(this,Ye).commands.length-1)}splitCoins(e,r){let n=Yo.Commands.SplitCoins(typeof e=="string"?this.object(e):Ir(this,yr,yf).call(this,e),r.map(i=>typeof i=="number"||typeof i=="bigint"||typeof i=="string"?this.pure.u64(i):Ir(this,yr,gf).call(this,i)));return Ir(this,yr,pf).call(this,n),Mm(_e(this,Ye).commands.length-1,r.length)}mergeCoins(e,r){return this.add(Yo.Commands.MergeCoins(this.object(e),r.map(n=>this.object(n))))}publish({modules:e,dependencies:r}){return this.add(Yo.Commands.Publish({modules:e,dependencies:r}))}upgrade({modules:e,dependencies:r,package:n,ticket:i}){return this.add(Yo.Commands.Upgrade({modules:e,dependencies:r,package:n,ticket:this.object(i)}))}moveCall({arguments:e,...r}){return this.add(Yo.Commands.MoveCall({...r,arguments:e?.map(n=>Ir(this,yr,gf).call(this,n))}))}transferObjects(e,r){return this.add(Yo.Commands.TransferObjects(e.map(n=>this.object(n)),typeof r=="string"?this.pure.address(r):Ir(this,yr,gf).call(this,r)))}makeMoveVec({type:e,elements:r}){return this.add(Yo.Commands.MakeMoveVec({type:e,elements:r.map(n=>this.object(n))}))}serialize(){return JSON.stringify((0,gO.serializeV1TransactionData)(_e(this,Ye).snapshot()))}async toJSON(e={}){await this.prepareForSerialization(e);let r=this.isFullyResolved();return JSON.stringify((0,mo.parse)(J9.SerializedTransactionDataV2,r?{..._e(this,Ye).snapshot(),digest:_e(this,Ye).getDigest()}:_e(this,Ye).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!(!_e(this,Ye).sender||_e(this,Ai).size>0||_e(this,Ye).commands.some(e=>e.$Intent)||(0,wO.needsTransactionResolution)(_e(this,Ye),{}))}async build(e={}){return await this.prepareForSerialization(e),await Ir(this,yr,km).call(this,e),_e(this,Ye).build({onlyTransactionKind:e.onlyTransactionKind})}async getDigest(e={}){return await Ir(this,yr,km).call(this,e),_e(this,Ye).getDigest()}async prepareForSerialization(e){await Ir(this,yr,SO).call(this),Ir(this,yr,kO).call(this);let r=new Set;for(let i of _e(this,Ye).commands)i.$Intent&&r.add(i.$Intent.name);let n=[..._e(this,ea)];for(let i of r)if(!e.supportedIntents?.includes(i)){if(!_e(this,Is).has(i))throw new Error(`Missing intent resolver for ${i}`);n.push(_e(this,Is).get(i))}await Ir(this,yr,Im).call(this,n,e)}};ea=new WeakMap;ta=new WeakMap;Is=new WeakMap;ss=new WeakMap;Hn=new WeakMap;Wn=new WeakMap;Ai=new WeakMap;go=new WeakMap;Ye=new WeakMap;yr=new WeakSet;MO=function(){let t=new AO;return nr(t,Ye,_e(this,Ye)),nr(t,ea,_e(this,ea)),nr(t,ta,_e(this,ta)),nr(t,Is,_e(this,Is)),nr(t,Ai,_e(this,Ai)),nr(t,Wn,new Set(_e(this,Wn))),nr(t,go,_e(this,go)),_e(this,ss).push(_e(t,ss)),_e(this,Hn).push(_e(t,Hn)),t};pf=function(t){let e=_e(this,Ye).commands.length;return _e(this,Hn).push(t),_e(this,Wn).add(e),_e(this,Ye).commands.push(t),_e(this,Ye).mapCommandArguments(e,r=>{if(r.$kind==="Result"&&!_e(this,Wn).has(r.Result))throw new Error(`Result { Result: ${r.Result} } is not available to use the current transaction`);if(r.$kind==="NestedResult"&&!_e(this,Wn).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>=_e(this,Ye).inputs.length)throw new Error(`Input { Input: ${r.Input} } references an input that does not exist in the current transaction`);return r}),t};mf=function(t,e){return _e(this,ss).push(e),_e(this,Ye).addInput(t,e)};gf=function(t){return(0,hf.isSerializedBcs)(t)?this.pure(t):Ir(this,yr,yf).call(this,t)};yf=function(t){if(typeof t=="function"){let e=this.add(t);return typeof e=="function"?Ir(this,yr,yf).call(this,e):(0,mo.parse)(Qo.Argument,e)}return(0,mo.parse)(Qo.Argument,t)};km=async function(t){if(!t.onlyTransactionKind&&!_e(this,Ye).sender)throw new Error("Missing transaction sender");await Ir(this,yr,Im).call(this,[..._e(this,ta),wO.resolveTransactionPlugin],t)};Im=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(_e(this,Ye),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)(),nr(this,ss,_e(this,Ye).inputs.slice()),nr(this,Hn,_e(this,Ye).commands.slice())};SO=async function(){for(;_e(this,Ai).size>0;){let t=Promise.all(_e(this,Ai));_e(this,Ai).clear(),_e(this,Ai).add(t),await t,_e(this,Ai).delete(t)}};kO=function(){let t=_e(this,Ye).commands,e=_e(this,Ye).inputs,r=_e(this,Hn).flat(1/0),n=_e(this,ss).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");_e(this,Ye).commands=i,_e(this,Ye).inputs=n,nr(this,Hn,i),nr(this,ss,n),nr(this,Wn,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}_e(this,Ye).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 Q9=AO});var jm=Me((WJ,jO)=>{"use strict";var Cm=Object.defineProperty,eB=Object.getOwnPropertyDescriptor,tB=Object.getOwnPropertyNames,rB=Object.prototype.hasOwnProperty,xO=t=>{throw TypeError(t)},nB=(t,e)=>{for(var r in e)Cm(t,r,{get:e[r],enumerable:!0})},iB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tB(e))!rB.call(t,i)&&i!==r&&Cm(t,i,{get:()=>e[i],enumerable:!(n=eB(e,i))||n.enumerable});return t},sB=t=>iB(Cm({},"__esModule",{value:!0}),t),PO=(t,e,r)=>e.has(t)||xO("Cannot "+r),Tr=(t,e,r)=>(PO(t,e,"read from private field"),r?r.call(t):e.get(t)),xm=(t,e,r)=>e.has(t)?xO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),TO=(t,e,r,n)=>(PO(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),CO={};nB(CO,{AsyncCache:()=>vf,InMemoryCache:()=>bf,ObjectCache:()=>Pm});jO.exports=sB(CO);var Tm=$r(),na,tn,_f,vf=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,Tm.normalizeSuiAddress)(e.package)}::${e.module}::${e.function}`;return this.get("MoveFunction",r)}async addMoveFunctionDefinition(e){let r=(0,Tm.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,Tm.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)}},bf=class extends vf{constructor(){super(...arguments),xm(this,na,{OwnedObject:new Map,SharedOrImmutableObject:new Map,MoveFunction:new Map,Custom:new Map})}async get(e,r){return Tr(this,na)[e].get(r)??null}async set(e,r,n){Tr(this,na)[e].set(r,n)}async delete(e,r){Tr(this,na)[e].delete(r)}async clear(e){if(e)Tr(this,na)[e].clear();else for(let r of Object.values(Tr(this,na)))r.clear()}};na=new WeakMap;var Pm=class{constructor({cache:e=new bf,onEffects:r}){xm(this,tn),xm(this,_f),TO(this,tn,e),TO(this,_f,r)}asPlugin(){return async(e,r,n)=>{let i=e.inputs.filter(u=>u.UnresolvedObject).map(u=>u.UnresolvedObject.objectId),s=(await Tr(this,tn).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 Tr(this,tn).addMoveFunctionDefinition({package:u.MoveCall.package,module:u.MoveCall.module,function:u.MoveCall.function,parameters:u.MoveCall._argumentTypes})}))}}async clear(){await Tr(this,tn).clear()}async getMoveFunctionDefinition(e){return Tr(this,tn).getMoveFunctionDefinition(e)}async getObjects(e){return Tr(this,tn).getObjects(e)}async deleteObjects(e){return Tr(this,tn).deleteObjects(e)}async clearOwnedObjects(){await Tr(this,tn).clear("OwnedObject")}async clearCustom(){await Tr(this,tn).clear("Custom")}async getCustom(e){return Tr(this,tn).getCustom(e)}async setCustom(e,r){return Tr(this,tn).setCustom(e,r)}async deleteCustom(e){return Tr(this,tn).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([Tr(this,tn).addObjects(o),Tr(this,tn).deleteObjects(s),(r=Tr(this,_f))==null?void 0:r.call(this,e)])}};tn=new WeakMap;_f=new WeakMap});var Rm=Me((KJ,UO)=>{"use strict";var Bm=Object.defineProperty,oB=Object.getOwnPropertyDescriptor,aB=Object.getOwnPropertyNames,uB=Object.prototype.hasOwnProperty,DO=t=>{throw TypeError(t)},cB=(t,e)=>{for(var r in e)Bm(t,r,{get:e[r],enumerable:!0})},lB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of aB(e))!uB.call(t,i)&&i!==r&&Bm(t,i,{get:()=>e[i],enumerable:!(n=oB(e,i))||n.enumerable});return t},fB=t=>lB(Bm({},"__esModule",{value:!0}),t),BO=(t,e,r)=>e.has(t)||DO("Cannot "+r),nc=(t,e,r)=>(BO(t,e,"read from private field"),r?r.call(t):e.get(t)),NO=(t,e,r)=>e.has(t)?DO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Nm=(t,e,r,n)=>(BO(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),RO={};cB(RO,{CachingTransactionExecutor:()=>Dm});UO.exports=fB(RO);var dB=zn(),hB=jm(),pB=ra(),$a,Fa,Dm=class{constructor({client:e,...r}){NO(this,$a),NO(this,Fa,null),Nm(this,$a,e),this.cache=new hB.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:nc(this,$a),...r})}async executeTransaction({transaction:e,options:r,...n}){let i=(0,pB.isTransaction)(e)?await this.buildTransaction({transaction:e}):e,s=await nc(this,$a).executeTransactionBlock({...n,transactionBlock:i,options:{...r,showRawEffects:!0}});if(s.rawEffects){let o=dB.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){Nm(this,Fa,e.V2?.transactionDigest??null),await this.cache.applyEffects(e)}async waitForLastTransaction(){nc(this,Fa)&&(await nc(this,$a).waitForTransaction({digest:nc(this,Fa)}),Nm(this,Fa,null))}};$a=new WeakMap;Fa=new WeakMap});var Fm=Me((XJ,qO)=>{"use strict";var $m=Object.defineProperty,mB=Object.getOwnPropertyDescriptor,gB=Object.getOwnPropertyNames,yB=Object.prototype.hasOwnProperty,LO=t=>{throw TypeError(t)},_B=(t,e)=>{for(var r in e)$m(t,r,{get:e[r],enumerable:!0})},vB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of gB(e))!yB.call(t,i)&&i!==r&&$m(t,i,{get:()=>e[i],enumerable:!(n=mB(e,i))||n.enumerable});return t},bB=t=>vB($m({},"__esModule",{value:!0}),t),wB=(t,e,r)=>e.has(t)||LO("Cannot "+r),Ii=(t,e,r)=>(wB(t,e,"read from private field"),r?r.call(t):e.get(t)),$O=(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),FO={};_B(FO,{ParallelQueue:()=>Lm,SerialQueue:()=>Um});qO.exports=bB(FO);var yo,ia,Um=class{constructor(){$O(this,yo,[])}async runTask(e){return new Promise((r,n)=>{Ii(this,yo).push(()=>{e().finally(()=>{Ii(this,yo).shift(),Ii(this,yo).length>0&&Ii(this,yo)[0]()}).then(r,n)}),Ii(this,yo).length===1&&Ii(this,yo)[0]()})}};yo=new WeakMap;var Lm=class{constructor(e){$O(this,ia,[]),this.activeTasks=0,this.maxTasks=e}runTask(e){return new Promise((r,n)=>{this.activeTasks<this.maxTasks?(this.activeTasks++,e().finally(()=>{Ii(this,ia).length>0?Ii(this,ia).shift()():this.activeTasks--}).then(r,n)):Ii(this,ia).push(()=>{e().finally(()=>{Ii(this,ia).length>0?Ii(this,ia).shift()():this.activeTasks--}).then(r,n)})})}};ia=new WeakMap});var Hm=Me((JJ,KO)=>{"use strict";var Gm=Object.defineProperty,MB=Object.getOwnPropertyDescriptor,SB=Object.getOwnPropertyNames,kB=Object.prototype.hasOwnProperty,zO=t=>{throw TypeError(t)},OB=(t,e)=>{for(var r in e)Gm(t,r,{get:e[r],enumerable:!0})},EB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of SB(e))!kB.call(t,i)&&i!==r&&Gm(t,i,{get:()=>e[i],enumerable:!(n=MB(e,i))||n.enumerable});return t},AB=t=>EB(Gm({},"__esModule",{value:!0}),t),GO=(t,e,r)=>e.has(t)||zO("Cannot "+r),rn=(t,e,r)=>(GO(t,e,"read from private field"),r?r.call(t):e.get(t)),qa=(t,e,r)=>e.has(t)?zO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),qm=(t,e,r,n)=>(GO(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),HO={};OB(HO,{SerialTransactionExecutor:()=>zm,getGasCoinFromEffects:()=>WO});KO.exports=AB(HO);var IB=br(),VO=ra(),TB=Rm(),xB=Fm(),wf,ic,Ti,Mf,Vm,Sf,zm=class{constructor({signer:e,defaultGasBudget:r=50000000n,...n}){qa(this,wf,new xB.SerialQueue),qa(this,ic),qa(this,Ti),qa(this,Mf),qa(this,Vm,async i=>{if(!i.V2)return;let s=WO(i).ref;s?rn(this,Ti).cache.setCustom("gasCoin",s):rn(this,Ti).cache.deleteCustom("gasCoin")}),qa(this,Sf,async i=>{let s=await rn(this,Ti).cache.getCustom("gasCoin"),o=VO.Transaction.from(i);return s&&o.setGasPayment([s]),o.setGasBudgetIfNotSet(rn(this,Mf)),o.setSenderIfNotSet(rn(this,ic).toSuiAddress()),rn(this,Ti).buildTransaction({transaction:o})}),qm(this,ic,e),qm(this,Mf,r),qm(this,Ti,new TB.CachingTransactionExecutor({client:n.client,cache:n.cache,onEffects:i=>rn(this,Vm).call(this,i)}))}async applyEffects(e){return rn(this,Ti).applyEffects(e)}async buildTransaction(e){return rn(this,wf).runTask(()=>rn(this,Sf).call(this,e))}resetCache(){return rn(this,Ti).reset()}waitForLastTransaction(){return rn(this,Ti).waitForLastTransaction()}executeTransaction(e,r,n=[]){return rn(this,wf).runTask(async()=>{let i=(0,VO.isTransaction)(e)?await rn(this,Sf).call(this,e):e,{signature:s}=await rn(this,ic).signTransaction(i),o=await rn(this,Ti).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,IB.toBase64)(u),data:o}})}};wf=new WeakMap;ic=new WeakMap;Ti=new WeakMap;Mf=new WeakMap;Vm=new WeakMap;Sf=new WeakMap;function WO(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 oE=Me((ZJ,sE)=>{"use strict";var Xm=Object.defineProperty,PB=Object.getOwnPropertyDescriptor,CB=Object.getOwnPropertyNames,jB=Object.prototype.hasOwnProperty,ZO=t=>{throw TypeError(t)},NB=(t,e)=>{for(var r in e)Xm(t,r,{get:e[r],enumerable:!0})},DB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of CB(e))!jB.call(t,i)&&i!==r&&Xm(t,i,{get:()=>e[i],enumerable:!(n=PB(e,i))||n.enumerable});return t},BB=t=>DB(Xm({},"__esModule",{value:!0}),t),Jm=(t,e,r)=>e.has(t)||ZO("Cannot "+r),Ge=(t,e,r)=>(Jm(t,e,"read from private field"),r?r.call(t):e.get(t)),xr=(t,e,r)=>e.has(t)?ZO("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),pr=(t,e,r,n)=>(Jm(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Kn=(t,e,r)=>(Jm(t,e,"access private method"),r),XO=(t,e,r,n)=>({set _(i){pr(t,e,i,r)},get _(){return Ge(t,e,n)}}),YO={};NB(YO,{ParallelTransactionExecutor:()=>Km});sE.exports=BB(YO);var RB=br(),UB=io(),QO=zn(),LB=ra(),$B=La(),FB=Rm(),JO=Fm(),eE=Hm(),_o,os,Of,ac,oc,uc,Ef,za,yn,vo,oa,sa,Zm,kf,cc,Va,Ga,Ts,Sn,tE,rE,lc,Ym,nE,Wm,iE,sc={coinBatchSize:20,initialCoinBalance:200000000n,minimumCoinBalance:50000000n,maxPoolSize:50,epochBoundaryWindow:1e3},Km=class{constructor(e){xr(this,Sn),xr(this,_o),xr(this,os),xr(this,Of),xr(this,ac),xr(this,oc),xr(this,uc),xr(this,Ef),xr(this,za),xr(this,yn),xr(this,vo,[]),xr(this,oa),xr(this,sa,new Map),xr(this,Zm,new JO.SerialQueue),xr(this,kf),xr(this,cc,null),xr(this,Va,null),xr(this,Ga,0),xr(this,Ts,null),pr(this,_o,e.signer),pr(this,os,e.client),pr(this,Of,e.coinBatchSize??sc.coinBatchSize),pr(this,ac,e.initialCoinBalance??sc.initialCoinBalance),pr(this,oc,e.minimumCoinBalance??sc.minimumCoinBalance),pr(this,Ef,e.defaultGasBudget??Ge(this,oc)),pr(this,uc,e.epochBoundaryWindow??sc.epochBoundaryWindow),pr(this,za,e.maxPoolSize??sc.maxPoolSize),pr(this,oa,new FB.CachingTransactionExecutor({client:e.client,cache:e.cache})),pr(this,kf,new JO.ParallelQueue(Ge(this,za))),pr(this,yn,e.sourceCoins?new Map(e.sourceCoins.map(r=>[r,null])):null)}resetCache(){return pr(this,Ts,null),Kn(this,Sn,lc).call(this,()=>Ge(this,oa).reset())}async waitForLastTransaction(){await Kn(this,Sn,lc).call(this,()=>Kn(this,Sn,Ym).call(this))}async executeTransaction(e,r,n=[]){let{promise:i,resolve:s,reject:o}=(0,UB.promiseWithResolvers)(),u=await Kn(this,Sn,tE).call(this,e),c=()=>{Ge(this,kf).runTask(()=>Kn(this,Sn,rE).call(this,e,u,r,n).then(s,o))},d=new Set;return u.forEach(p=>{Ge(this,sa).get(p)?(d.add(p),Ge(this,sa).get(p).push(()=>{d.delete(p),d.size===0&&c()})):Ge(this,sa).set(p,[])}),d.size===0&&c(),i}};_o=new WeakMap;os=new WeakMap;Of=new WeakMap;ac=new WeakMap;oc=new WeakMap;uc=new WeakMap;Ef=new WeakMap;za=new WeakMap;yn=new WeakMap;vo=new WeakMap;oa=new WeakMap;sa=new WeakMap;Zm=new WeakMap;kf=new WeakMap;cc=new WeakMap;Va=new WeakMap;Ga=new WeakMap;Ts=new WeakMap;Sn=new WeakSet;tE=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:Ge(this,os)}),e};rE=async function(t,e,r,n=[]){let i;try{t.setSenderIfNotSet(Ge(this,_o).toSuiAddress()),await Ge(this,Zm).runTask(async()=>{t.getData().gasData.price||t.setGasPrice(await Kn(this,Sn,Wm).call(this)),t.setGasBudgetIfNotSet(Ge(this,Ef)),await Kn(this,Sn,lc).call(this),i=await Kn(this,Sn,nE).call(this),XO(this,Ga)._++,t.setGasPayment([{objectId:i.id,version:i.version,digest:i.digest}]),await Ge(this,oa).buildTransaction({transaction:t,onlyTransactionKind:!0})});let s=await t.build({client:Ge(this,os)}),{signature:o}=await Ge(this,_o).signTransaction(s),u=await Ge(this,oa).executeTransaction({transaction:s,signature:[o,...n],options:{...r,showEffects:!0}}),c=Uint8Array.from(u.rawEffects),d=QO.bcs.TransactionEffects.parse(c),p=(0,eE.getGasCoinFromEffects)(d),_=d.V2?.gasUsed;if(i&&_&&p.owner===Ge(this,_o).toSuiAddress()){let b=BigInt(_.computationCost)+BigInt(_.storageCost)+BigInt(_.storageCost)-BigInt(_.storageRebate),O=!1;new $B.TransactionDataBuilder(t.getData()).mapArguments(T=>(T.$kind==="GasCoin"&&(O=!0),T)),!O&&i.balance>=Ge(this,oc)?Ge(this,vo).push({id:p.ref.objectId,version:p.ref.version,digest:p.ref.digest,balance:i.balance-b}):(Ge(this,yn)||pr(this,yn,new Map),Ge(this,yn).set(p.ref.objectId,p.ref))}return pr(this,cc,u.digest),{digest:u.digest,effects:(0,RB.toBase64)(c),data:u}}catch(s){throw i&&(Ge(this,yn)||pr(this,yn,new Map),Ge(this,yn).set(i.id,null)),await Kn(this,Sn,lc).call(this,async()=>{await Promise.all([Ge(this,oa).cache.deleteObjects([...e]),Kn(this,Sn,Ym).call(this)])}),s}finally{e.forEach(s=>{let o=Ge(this,sa).get(s);o&&o.length>0?o.shift()():o&&Ge(this,sa).delete(s)}),XO(this,Ga)._--}};lc=async function(t){Ge(this,Va)&&await Ge(this,Va),pr(this,Va,t?.().then(()=>{pr(this,Va,null)},()=>{})??null)};Ym=async function(){let t=Ge(this,cc);t&&(pr(this,cc,null),await Ge(this,os).waitForTransaction({digest:t}))};nE=async function(){if(Ge(this,vo).length===0&&Ge(this,Ga)<=Ge(this,za)&&await Kn(this,Sn,iE).call(this),Ge(this,vo).length===0)throw new Error("No coins available");return Ge(this,vo).shift()};Wm=async function(){if((Ge(this,Ts)?Ge(this,Ts).expiration-Ge(this,uc)-Date.now():0)>0)return Ge(this,Ts).price;if(Ge(this,Ts)){let r=Math.max(Ge(this,Ts).expiration+Ge(this,uc)-Date.now(),1e3);await new Promise(n=>setTimeout(n,r))}let e=await Ge(this,os).getLatestSuiSystemState();return pr(this,Ts,{price:BigInt(e.referenceGasPrice),expiration:Number.parseInt(e.epochStartTimestampMs,10)+Number.parseInt(e.epochDurationMs,10)}),Kn(this,Sn,Wm).call(this)};iE=async function(){let t=Math.min(Ge(this,Of),Ge(this,za)-(Ge(this,vo).length+Ge(this,Ga))+1);if(t===0)return;let e=new LB.Transaction,r=Ge(this,_o).toSuiAddress();if(e.setSender(r),Ge(this,yn)){let d=[],p=[];for(let[_,b]of Ge(this,yn))b?d.push(b):p.push(_);if(p.length>0){let _=await Ge(this,os).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),pr(this,yn,new Map)}let n=new Array(t).fill(Ge(this,ac)),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 Ge(this,os).signAndExecuteTransaction({transaction:e,signer:Ge(this,_o),options:{showRawEffects:!0}}),u=QO.bcs.TransactionEffects.parse(Uint8Array.from(o.rawEffects));u.V2?.changedObjects.forEach(([d,{outputState:p}],_)=>{_===u.V2?.gasObjectIndex||!p.ObjectWrite||Ge(this,vo).push({id:d,version:u.V2.lamportVersion,digest:p.ObjectWrite[0],balance:BigInt(Ge(this,ac))})}),Ge(this,yn)||pr(this,yn,new Map);let c=(0,eE.getGasCoinFromEffects)(u).ref;Ge(this,yn).set(c.objectId,c),await Ge(this,os).waitForTransaction({digest:o.digest})}});var hE=Me((YJ,dE)=>{"use strict";var Qm=Object.defineProperty,qB=Object.getOwnPropertyDescriptor,VB=Object.getOwnPropertyNames,zB=Object.prototype.hasOwnProperty,GB=(t,e)=>{for(var r in e)Qm(t,r,{get:e[r],enumerable:!0})},HB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of VB(e))!zB.call(t,i)&&i!==r&&Qm(t,i,{get:()=>e[i],enumerable:!(n=qB(e,i))||n.enumerable});return t},WB=t=>HB(Qm({},"__esModule",{value:!0}),t),cE={};GB(cE,{coinWithBalance:()=>JB,getSuiClient:()=>fE});dE.exports=WB(cE);var Af=Qi(),KB=zn(),lE=$r(),If=rf(),aE=Da(),XB=cm(),Tf="CoinWithBalance",uE=(0,lE.normalizeStructTag)("0x2::sui::SUI");function JB({type:t=uE,balance:e,useGasCoin:r=!0}){let n=null;return i=>{if(n)return n;i.addIntentResolver(Tf,YB);let s=t==="gas"?t:(0,lE.normalizeStructTag)(t);return n=i.add(If.Commands.Intent({name:Tf,inputs:{},data:{type:s===uE&&r?"gas":s,balance:BigInt(e)}})),n}}var ZB=(0,Af.object)({type:(0,Af.string)(),balance:(0,Af.bigint)()});async function YB(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===Tf){let{type:p,balance:_}=(0,Af.parse)(ZB,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=fE(e);await Promise.all([...n].map(async d=>{o.set(d,await QB({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!==Tf)continue;let{type:_,balance:b}=p.$Intent.data;if(b===0n&&_!=="gas"){t.replaceCommand(d,If.Commands.MoveCall({target:"0x2::coin::zero",typeArguments:[_]}));continue}let O=[];if(!c.has(_)){let[T,...x]=o.get(_).map(F=>t.addInput("object",aE.Inputs.ObjectRef({objectId:F.coinObjectId,digest:F.digest,version:F.version})));x.length>0&&O.push(If.Commands.MergeCoins(T,x)),c.set(_,T)}O.push(If.Commands.SplitCoins(c.get(_),[t.addInput("pure",aE.Inputs.Pure(KB.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 QB({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 fE(t){let e=(0,XB.getClient)(t);if(!e.jsonRpc)throw new Error("CoinWithBalance intent currently only works with SuiClient");return e}});var gE=Me((QJ,mE)=>{"use strict";var eg=Object.defineProperty,eR=Object.getOwnPropertyDescriptor,tR=Object.getOwnPropertyNames,rR=Object.prototype.hasOwnProperty,nR=(t,e)=>{for(var r in e)eg(t,r,{get:e[r],enumerable:!0})},iR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tR(e))!rR.call(t,i)&&i!==r&&eg(t,i,{get:()=>e[i],enumerable:!(n=eR(e,i))||n.enumerable});return t},sR=t=>iR(eg({},"__esModule",{value:!0}),t),pE={};nR(pE,{Arguments:()=>uR});mE.exports=sR(pE);var oR=fm(),aR=pm(),uR={pure:(0,aR.createPure)(t=>e=>e.pure(t)),object:(0,oR.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 SE=Me((eZ,ME)=>{"use strict";var tg=Object.defineProperty,cR=Object.getOwnPropertyDescriptor,lR=Object.getOwnPropertyNames,fR=Object.prototype.hasOwnProperty,dR=(t,e)=>{for(var r in e)tg(t,r,{get:e[r],enumerable:!0})},hR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lR(e))!fR.call(t,i)&&i!==r&&tg(t,i,{get:()=>e[i],enumerable:!(n=cR(e,i))||n.enumerable});return t},pR=t=>hR(tg({},"__esModule",{value:!0}),t),wE={};dR(wE,{Arguments:()=>bR.Arguments,AsyncCache:()=>bE.AsyncCache,Commands:()=>_E.Commands,Inputs:()=>mR.Inputs,ObjectCache:()=>bE.ObjectCache,ParallelTransactionExecutor:()=>_R.ParallelTransactionExecutor,SerialTransactionExecutor:()=>yR.SerialTransactionExecutor,Transaction:()=>vE.Transaction,TransactionDataBuilder:()=>gR.TransactionDataBuilder,UpgradePolicy:()=>_E.UpgradePolicy,coinWithBalance:()=>vR.coinWithBalance,getPureBcsSchema:()=>yE.getPureBcsSchema,isArgument:()=>MR.isArgument,isTransaction:()=>vE.isTransaction,namedPackagesPlugin:()=>wR.namedPackagesPlugin,normalizedTypeToMoveTypeSignature:()=>yE.normalizedTypeToMoveTypeSignature});ME.exports=pR(wE);var yE=g0(),mR=Da(),_E=rf(),vE=ra(),gR=La(),bE=jm(),yR=Hm(),_R=oE(),vR=hE(),bR=gE(),wR=nm(),MR=wm()});var rg=Me((kE,xf)=>{"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,pe,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=pe(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},pe=(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,me,ze,be=j.indexOf("."),Pe=D,qe=N;for(be>=0&&(K=v,v=0,j=j.replace(".",""),ze=new f(L),oe=ze.pow(j.length-be),v=K,ze.c=P(ee(x(oe.c),oe.e,"0"),10,U,E),ze.e=ze.c.length),me=P(j,L,U,q?($=w,E):($=E,w)),G=K=me.length;me[--K]==0;me.pop());if(!me[0])return $.charAt(0);if(be<0?--G:(oe.c=me,oe.e=G,oe.s=W,oe=te(oe,ze,Pe,qe,U),me=oe.c,ie=oe.r,G=oe.e),X=G+Pe+1,be=me[X],K=U/2,ie=ie||X<0||me[X+1]!=null,ie=qe<4?(be!=null||ie)&&(qe==0||qe==(oe.s<0?3:2)):be>K||be==K&&(qe==4||ie||qe==6&&me[X-1]&1||qe==(oe.s<0?8:7)),X<1||!me[0])j=ie?ee($.charAt(1),-Pe,$.charAt(0)):$.charAt(0);else{if(me.length=X,ie)for(--U;++me[--X]>U;)me[X]=0,X||(++G,me=[1].concat(me));for(K=me.length;!me[--K];);for(be=0,j="";be<=K;j+=$.charAt(me[be++]));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%_,me=U/_|0;for(L=L.slice();ie--;)X=L[ie]%_,G=L[ie]/_|0,q=me*X+G*oe,$=oe*X+q%_*_+K,K=($/W|0)+(q/_|0)+me*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,me,ze,be,Pe,qe,ge,Fe,Nt,Te,st,Tt,Ie,He=L.s==U.s?1:-1,Et=L.c,we=U.c;if(!Et||!Et[0]||!we||!we[0])return new f(!L.s||!U.s||(Et?we&&Et[0]==we[0]:!we)?NaN:Et&&Et[0]==0||!we?He*0:He/0);for(be=new f(He),Pe=be.c=[],G=L.e-U.e,He=W+G+1,$||($=u,G=T(L.e/c)-T(U.e/c),He=He/c|0),K=0;we[K]==(Et[K]||0);K++);if(we[K]>(Et[K]||0)&&G--,He<0)Pe.push(1),ie=!0;else{for(Te=Et.length,Tt=we.length,K=0,He+=2,oe=i($/(we[0]+1)),oe>1&&(we=E(we,oe,$),Et=E(Et,oe,$),Tt=we.length,Te=Et.length),Nt=Tt,qe=Et.slice(0,Tt),ge=qe.length;ge<Tt;qe[ge++]=0);Ie=we.slice(),Ie=[0].concat(Ie),st=we[0],we[1]>=$/2&&st++;do{if(oe=0,X=P(we,qe,Tt,ge),X<0){if(Fe=qe[0],Tt!=ge&&(Fe=Fe*$+(qe[1]||0)),oe=i(Fe/st),oe>1)for(oe>=$&&(oe=$-1),me=E(we,oe,$),ze=me.length,ge=qe.length;P(me,qe,ze,ge)==1;)oe--,j(me,Tt<ze?Ie:we,ze,$),ze=me.length,X=1;else oe==0&&(X=oe=1),me=we.slice(),ze=me.length;if(ze<ge&&(me=[0].concat(me)),j(qe,me,ge,$),ge=qe.length,X==-1)for(;P(we,qe,Tt,ge)<1;)oe++,j(qe,Tt<ge?Ie:we,ge,$),ge=qe.length}else X===0&&(oe++,qe=[0]);Pe[K++]=oe,qe[0]?qe[ge++]=Et[Nt]||0:(qe=[Et[Nt]],ge=1)}while((Nt++<Te||qe[0]!=null)&&He--);ie=qe[0]!=null,Pe[0]||Pe.splice(0,1)}if($==u){for(K=1,He=Pe[0];He>=10;He/=10,K++);Z(be,W+(be.e=K+G*c-1)+1,q,ie)}else be.e=G,be.r=+ie;return be}})();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,me){return G=(me=me.toLowerCase())=="x"?16:me=="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,me,ze,be,Pe,qe=this,ge=qe.c,Fe=(E=new f(E,P)).c;if(!ge||!Fe||!ge[0]||!Fe[0])return!qe.s||!E.s||ge&&!ge[0]&&!Fe||Fe&&!Fe[0]&&!ge?E.c=E.e=E.s=null:(E.s*=qe.s,!ge||!Fe?E.c=E.e=null:(E.c=[0],E.e=0)),E;for(L=T(qe.e/c)+T(E.e/c),E.s*=qe.s,X=ge.length,ie=Fe.length,X<ie&&(ze=ge,ge=Fe,Fe=ze,U=X,X=ie,ie=U),U=X+ie,ze=[];U--;ze.push(0));for(be=u,Pe=_,U=ie;--U>=0;){for(j=0,oe=Fe[U]%Pe,me=Fe[U]/Pe|0,q=X,W=U+q;W>U;)G=ge[--q]%Pe,K=ge[q]/Pe|0,$=me*G+K*oe,G=oe*G+$%Pe*Pe+ze[W]+j,j=(G/be|0)+($/Pe|0)+me*K,ze[W--]=G%be;ze[W]=j}return j?++L:ze.splice(0,1),z(E,ze,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,me=oe?K.slice(1):K,ze=me.length;if(X&&(W=$,$=X,X=W,ze-=W),$>0&&ze>0){for(W=ze%$||$,K=me.substr(0,W);W<ze;W+=$)K+=G+me.substr(W,$);X>0&&(K+=G+me.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,me=this,ze=me.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(!ze)return new f(me);for(P=new f(C),G=j=new f(C),L=X=new f(C),oe=x(ze),W=P.e=oe.length-me.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=me.s,W=W*2,ie=te(G,L,W,N).minus(me).abs().comparedTo(te(X,j,W,N).minus(me).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=pe(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,pe,A=1,I=ae.length,C=ae[0]+"";A<I;){for(te=ae[A++]+"",pe=c-te.length;pe--;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 pe,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(pe=I&&!I[0],A=C&&!C[0],pe||A)return pe?A?0:-N:D;if(D!=N)return D;if(pe=D<0,A=k==m,!I||!C)return A?0:!I^pe?1:-1;if(!A)return k>m^pe?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]^pe?1:-1;return k==m?0:k>m^pe?1:-1}function R(ae,te,pe,A){if(ae<te||ae>pe||ae!==i(ae))throw Error(s+(A||"Argument")+(typeof ae=="number"?ae<te||ae>pe?" 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,pe){var A,I;if(te<0){for(I=pe+".";++te;I+=pe);ae=I+ae}else if(A=ae.length,++te>A){for(I=pe,te-=A;--te;I+=pe);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 xf<"u"&&xf.exports?xf.exports=e:(t||(t=typeof self<"u"&&self?self:window),t.BigNumber=e)})(kE)});var IE=Me((tZ,AE)=>{"use strict";var OE=rg(),EE=AE.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 OE||OE.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 EE.stringify!="function"&&(EE.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 xE=Me((rZ,TE)=>{"use strict";var Pf=null,SR=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,kR=/(?: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)/,OR=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 Pf==null&&(Pf=rg()),F.length>15?e.storeAsString?F:e.useNativeBigInt?BigInt(F):new Pf(F):e.alwaysParseAsBig?e.useNativeBigInt?BigInt(x):new Pf(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+'"'),SR.test(x)===!0?e.protoAction==="error"?o("Object contains forbidden prototype property"):e.protoAction==="ignore"?b():F[x]=b():kR.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,pe=J[ee];return pe&&typeof pe=="object"&&Object.keys(pe).forEach(function(A){te=H(pe,A),te!==void 0?pe[A]=te:delete pe[A]}),F.call(J,ee,pe)})({"":R},""):R}};TE.exports=OR});var jE=Me((nZ,Cf)=>{"use strict";var PE=IE().stringify,CE=xE();Cf.exports=function(t){return{parse:CE(t),stringify:PE}};Cf.exports.parse=CE();Cf.exports.stringify=PE});var jf=Me((iZ,DE)=>{"use strict";var sg=Object.defineProperty,ER=Object.getOwnPropertyDescriptor,AR=Object.getOwnPropertyNames,IR=Object.prototype.hasOwnProperty,TR=(t,e)=>{for(var r in e)sg(t,r,{get:e[r],enumerable:!0})},xR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of AR(e))!IR.call(t,i)&&i!==r&&sg(t,i,{get:()=>e[i],enumerable:!(n=ER(e,i))||n.enumerable});return t},PR=t=>xR(sg({},"__esModule",{value:!0}),t),NE={};TR(NE,{JsonRpcError:()=>ng,SuiHTTPStatusError:()=>ig,SuiHTTPTransportError:()=>fc});DE.exports=PR(NE);var CR={"-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"},fc=class extends Error{},ng=class extends fc{constructor(e,r){super(e),this.code=r,this.type=CR[r]??"ServerError"}},ig=class extends fc{constructor(e,r,n){super(e),this.status=r,this.statusText=n}}});var VE=Me((sZ,qE)=>{"use strict";var ug=Object.defineProperty,jR=Object.getOwnPropertyDescriptor,NR=Object.getOwnPropertyNames,DR=Object.prototype.hasOwnProperty,BE=t=>{throw TypeError(t)},BR=(t,e)=>{for(var r in e)ug(t,r,{get:e[r],enumerable:!0})},RR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of NR(e))!DR.call(t,i)&&i!==r&&ug(t,i,{get:()=>e[i],enumerable:!(n=jR(e,i))||n.enumerable});return t},UR=t=>RR(ug({},"__esModule",{value:!0}),t),cg=(t,e,r)=>e.has(t)||BE("Cannot "+r),cr=(t,e,r)=>(cg(t,e,"read from private field"),r?r.call(t):e.get(t)),aa=(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),Ha=(t,e,r,n)=>(cg(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),RE=(t,e,r)=>(cg(t,e,"access private method"),r),LR=(t,e,r,n)=>({set _(i){Ha(t,e,i,r)},get _(){return cr(t,e,n)}}),UE={};BR(UE,{DEFAULT_CLIENT_OPTIONS:()=>FE,WebsocketClient:()=>og});qE.exports=UR(UE);var $R=jf(),bo,dc,xs,ua,hc,ca,Nf,LE,$E;function FR(t){let e=new URL(t);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var FE={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},og=class{constructor(e,r={}){if(aa(this,Nf),aa(this,bo,0),aa(this,dc,0),aa(this,xs,null),aa(this,ua,null),aa(this,hc,new Set),aa(this,ca,new Map),this.endpoint=e,this.options={...FE,...r},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=FR(this.endpoint))}async makeRequest(e,r,n){let i=await RE(this,Nf,LE).call(this);return new Promise((s,o)=>{Ha(this,bo,cr(this,bo)+1),cr(this,ca).set(cr(this,bo),{resolve:s,reject:o,timeout:setTimeout(()=>{cr(this,ca).delete(cr(this,bo)),o(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n?.addEventListener("abort",()=>{cr(this,ca).delete(cr(this,bo)),o(n.reason)}),i.send(JSON.stringify({jsonrpc:"2.0",id:cr(this,bo),method:e,params:r}))}).then(({error:s,result:o})=>{if(s)throw new $R.JsonRpcError(s.message,s.code);return o})}async subscribe(e){let r=new ag(e);return cr(this,hc).add(r),await r.subscribe(this),()=>r.unsubscribe(this)}};bo=new WeakMap;dc=new WeakMap;xs=new WeakMap;ua=new WeakMap;hc=new WeakMap;ca=new WeakMap;Nf=new WeakSet;LE=function(){return cr(this,ua)?cr(this,ua):(Ha(this,ua,new Promise(t=>{cr(this,xs)?.close(),Ha(this,xs,new this.options.WebSocketConstructor(this.endpoint)),cr(this,xs).addEventListener("open",()=>{Ha(this,dc,0),t(cr(this,xs))}),cr(this,xs).addEventListener("close",()=>{LR(this,dc)._++,cr(this,dc)<=this.options.maxReconnects&&setTimeout(()=>{RE(this,Nf,$E).call(this)},this.options.reconnectTimeout)}),cr(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&&cr(this,ca).has(r.id)){let{resolve:n,timeout:i}=cr(this,ca).get(r.id);clearTimeout(i),n(r)}else if("params"in r){let{params:n}=r;cr(this,hc).forEach(i=>{i.subscriptionId===n.subscription&&n.subscription===i.subscriptionId&&i.onMessage(n.result)})}})})),cr(this,ua))};$E=async function(){return cr(this,xs)?.close(),Ha(this,ua,null),Promise.allSettled([...cr(this,hc)].map(t=>t.subscribe(this)))};var ag=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 mg=Me((oZ,XE)=>{"use strict";var hg=Object.defineProperty,qR=Object.getOwnPropertyDescriptor,VR=Object.getOwnPropertyNames,zR=Object.prototype.hasOwnProperty,HE=t=>{throw TypeError(t)},GR=(t,e)=>{for(var r in e)hg(t,r,{get:e[r],enumerable:!0})},HR=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of VR(e))!zR.call(t,i)&&i!==r&&hg(t,i,{get:()=>e[i],enumerable:!(n=qR(e,i))||n.enumerable});return t},WR=t=>HR(hg({},"__esModule",{value:!0}),t),pg=(t,e,r)=>e.has(t)||HE("Cannot "+r),Xn=(t,e,r)=>(pg(t,e,"read from private field"),r?r.call(t):e.get(t)),Df=(t,e,r)=>e.has(t)?HE("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),lg=(t,e,r,n)=>(pg(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),KR=(t,e,r)=>(pg(t,e,"access private method"),r),WE={};GR(WE,{SuiHTTPTransport:()=>dg});XE.exports=WR(WE);var zE=H0(),GE=jf(),XR=VE(),pc,xi,mc,fg,KE,dg=class{constructor(e){Df(this,fg),Df(this,pc,0),Df(this,xi),Df(this,mc),lg(this,xi,e)}fetch(e,r){let n=Xn(this,xi).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){lg(this,pc,Xn(this,pc)+1);let r=await this.fetch(Xn(this,xi).rpc?.url??Xn(this,xi).url,{method:"POST",signal:e.signal,headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":zE.PACKAGE_VERSION,"Client-Target-Api-Version":zE.TARGETED_RPC_VERSION,"Client-Request-Method":e.method,...Xn(this,xi).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:Xn(this,pc),method:e.method,params:e.params})});if(!r.ok)throw new GE.SuiHTTPStatusError(`Unexpected status code: ${r.status}`,r.status,r.statusText);let n=await r.json();if("error"in n&&n.error!=null)throw new GE.JsonRpcError(n.error.message,n.error.code);return n.result}async subscribe(e){let r=await KR(this,fg,KE).call(this).subscribe(e);return e.signal&&(e.signal.throwIfAborted(),e.signal.addEventListener("abort",()=>{r()})),async()=>!!await r()}};pc=new WeakMap;xi=new WeakMap;mc=new WeakMap;fg=new WeakSet;KE=function(){if(!Xn(this,mc)){let t=Xn(this,xi).WebSocketConstructor??WebSocket;if(!t)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");lg(this,mc,new XR.WebsocketClient(Xn(this,xi).websocket?.url??Xn(this,xi).url,{WebSocketConstructor:t,...Xn(this,xi).websocket}))}return Xn(this,mc)}});var YE=Me((aZ,ZE)=>{"use strict";var gg=Object.defineProperty,JR=Object.getOwnPropertyDescriptor,ZR=Object.getOwnPropertyNames,YR=Object.prototype.hasOwnProperty,QR=(t,e)=>{for(var r in e)gg(t,r,{get:e[r],enumerable:!0})},eU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ZR(e))!YR.call(t,i)&&i!==r&&gg(t,i,{get:()=>e[i],enumerable:!(n=JR(e,i))||n.enumerable});return t},tU=t=>eU(gg({},"__esModule",{value:!0}),t),JE={};QR(JE,{getFullnodeUrl:()=>rU});ZE.exports=tU(JE);function rU(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 tA=Me((uZ,eA)=>{"use strict";var QE=Object.defineProperty,nU=Object.getOwnPropertyDescriptor,iU=Object.getOwnPropertyNames,sU=Object.prototype.hasOwnProperty,oU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of iU(e))!sU.call(t,i)&&i!==r&&QE(t,i,{get:()=>e[i],enumerable:!(n=nU(e,i))||n.enumerable});return t},aU=t=>oU(QE({},"__esModule",{value:!0}),t),uU={};eA.exports=aU(uU)});var iA=Me((cZ,nA)=>{"use strict";var rA=Object.defineProperty,cU=Object.getOwnPropertyDescriptor,lU=Object.getOwnPropertyNames,fU=Object.prototype.hasOwnProperty,dU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lU(e))!fU.call(t,i)&&i!==r&&rA(t,i,{get:()=>e[i],enumerable:!(n=cU(e,i))||n.enumerable});return t},hU=t=>dU(rA({},"__esModule",{value:!0}),t),pU={};nA.exports=hU(pU)});var aA=Me((lZ,oA)=>{"use strict";var sA=Object.defineProperty,mU=Object.getOwnPropertyDescriptor,gU=Object.getOwnPropertyNames,yU=Object.prototype.hasOwnProperty,_U=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of gU(e))!yU.call(t,i)&&i!==r&&sA(t,i,{get:()=>e[i],enumerable:!(n=mU(e,i))||n.enumerable});return t},vU=t=>_U(sA({},"__esModule",{value:!0}),t),bU={};oA.exports=vU(bU)});var lA=Me((fZ,cA)=>{"use strict";var uA=Object.defineProperty,wU=Object.getOwnPropertyDescriptor,MU=Object.getOwnPropertyNames,SU=Object.prototype.hasOwnProperty,kU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of MU(e))!SU.call(t,i)&&i!==r&&uA(t,i,{get:()=>e[i],enumerable:!(n=wU(e,i))||n.enumerable});return t},OU=t=>kU(uA({},"__esModule",{value:!0}),t),EU={};cA.exports=OU(EU)});var hA=Me((dZ,dA)=>{"use strict";var fA=Object.defineProperty,AU=Object.getOwnPropertyDescriptor,IU=Object.getOwnPropertyNames,TU=Object.prototype.hasOwnProperty,xU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of IU(e))!TU.call(t,i)&&i!==r&&fA(t,i,{get:()=>e[i],enumerable:!(n=AU(e,i))||n.enumerable});return t},PU=t=>xU(fA({},"__esModule",{value:!0}),t),CU={};dA.exports=PU(CU)});var gA=Me((hZ,mA)=>{"use strict";var pA=Object.defineProperty,jU=Object.getOwnPropertyDescriptor,NU=Object.getOwnPropertyNames,DU=Object.prototype.hasOwnProperty,BU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of NU(e))!DU.call(t,i)&&i!==r&&pA(t,i,{get:()=>e[i],enumerable:!(n=jU(e,i))||n.enumerable});return t},RU=t=>BU(pA({},"__esModule",{value:!0}),t),UU={};mA.exports=RU(UU)});var _A=Me((pZ,wo)=>{"use strict";var yA=Object.defineProperty,LU=Object.getOwnPropertyDescriptor,$U=Object.getOwnPropertyNames,FU=Object.prototype.hasOwnProperty,yg=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $U(e))!FU.call(t,i)&&i!==r&&yA(t,i,{get:()=>e[i],enumerable:!(n=LU(e,i))||n.enumerable});return t},Wa=(t,e,r)=>(yg(t,e,"default"),r&&yg(r,e,"default")),qU=t=>yg(yA({},"__esModule",{value:!0}),t),la={};wo.exports=qU(la);Wa(la,tA(),wo.exports);Wa(la,iA(),wo.exports);Wa(la,aA(),wo.exports);Wa(la,lA(),wo.exports);Wa(la,hA(),wo.exports);Wa(la,gA(),wo.exports)});var bg=Me((mZ,bA)=>{"use strict";var vg=Object.defineProperty,VU=Object.getOwnPropertyDescriptor,zU=Object.getOwnPropertyNames,GU=Object.prototype.hasOwnProperty,HU=(t,e)=>{for(var r in e)vg(t,r,{get:e[r],enumerable:!0})},WU=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of zU(e))!GU.call(t,i)&&i!==r&&vg(t,i,{get:()=>e[i],enumerable:!(n=VU(e,i))||n.enumerable});return t},KU=t=>WU(vg({},"__esModule",{value:!0}),t),vA={};HU(vA,{Experimental_BaseClient:()=>_g});bA.exports=KU(vA);var XU=z0(),_g=class{constructor({network:e,base:r}){this.cache=new XU.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 SA=Me((gZ,MA)=>{"use strict";var Mg=Object.defineProperty,JU=Object.getOwnPropertyDescriptor,ZU=Object.getOwnPropertyNames,YU=Object.prototype.hasOwnProperty,QU=(t,e)=>{for(var r in e)Mg(t,r,{get:e[r],enumerable:!0})},eL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ZU(e))!YU.call(t,i)&&i!==r&&Mg(t,i,{get:()=>e[i],enumerable:!(n=JU(e,i))||n.enumerable});return t},tL=t=>eL(Mg({},"__esModule",{value:!0}),t),wA={};QU(wA,{Experimental_CoreClient:()=>wg});MA.exports=tL(wA);var rL=$l(),nL=d0(),Bf=$r(),iL=bg(),sL=Qu(),wg=class extends iL.Experimental_BaseClient{constructor(e){super(e),this.core=this,this.mvr=new sL.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,nL.deriveDynamicFieldID)(e.parentId,rL.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,Bf.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,Bf.normalizeStructTag)(i.typeParams[0]),bcs:e.name.bcs},value:{type:typeof i.typeParams[1]=="string"?i.typeParams[1]:(0,Bf.normalizeStructTag)(i.typeParams[1]),bcs:s.slice(Bf.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 EA=Me((yZ,OA)=>{"use strict";var kg=Object.defineProperty,oL=Object.getOwnPropertyDescriptor,aL=Object.getOwnPropertyNames,uL=Object.prototype.hasOwnProperty,cL=(t,e)=>{for(var r in e)kg(t,r,{get:e[r],enumerable:!0})},lL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of aL(e))!uL.call(t,i)&&i!==r&&kg(t,i,{get:()=>e[i],enumerable:!(n=oL(e,i))||n.enumerable});return t},fL=t=>lL(kg({},"__esModule",{value:!0}),t),kA={};cL(kA,{ObjectError:()=>Sg,SuiClientError:()=>Rf});OA.exports=fL(kA);var Rf=class extends Error{},Sg=class t extends Rf{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 TA=Me((_Z,IA)=>{"use strict";var Og=Object.defineProperty,dL=Object.getOwnPropertyDescriptor,hL=Object.getOwnPropertyNames,pL=Object.prototype.hasOwnProperty,mL=(t,e)=>{for(var r in e)Og(t,r,{get:e[r],enumerable:!0})},gL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of hL(e))!pL.call(t,i)&&i!==r&&Og(t,i,{get:()=>e[i],enumerable:!(n=dL(e,i))||n.enumerable});return t},yL=t=>gL(Og({},"__esModule",{value:!0}),t),AA={};mL(AA,{parseTransactionBcs:()=>bL,parseTransactionEffectsBcs:()=>wL});IA.exports=yL(AA);var _L=zn(),vL=La();function bL(t){return{...vL.TransactionDataBuilder.fromBytes(t).snapshot(),bcs:t}}function wL(t){let e=_L.bcs.TransactionEffects.parse(t);switch(e.$kind){case"V1":return ML({bytes:t,effects:e.V1});case"V2":return SL({bytes:t,effects:e.V2});default:throw new Error(`Unknown transaction effects version: ${e.$kind}`)}}function ML(t){throw new Error("V1 effects are not supported yet")}function SL({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 UA=Me((vZ,RA)=>{"use strict";var Ag=Object.defineProperty,kL=Object.getOwnPropertyDescriptor,OL=Object.getOwnPropertyNames,EL=Object.prototype.hasOwnProperty,jA=t=>{throw TypeError(t)},AL=(t,e)=>{for(var r in e)Ag(t,r,{get:e[r],enumerable:!0})},IL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of OL(e))!EL.call(t,i)&&i!==r&&Ag(t,i,{get:()=>e[i],enumerable:!(n=kL(e,i))||n.enumerable});return t},TL=t=>IL(Ag({},"__esModule",{value:!0}),t),NA=(t,e,r)=>e.has(t)||jA("Cannot "+r),Cn=(t,e,r)=>(NA(t,e,"read from private field"),r?r.call(t):e.get(t)),xL=(t,e,r)=>e.has(t)?jA("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),PL=(t,e,r,n)=>(NA(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),DA={};AL(DA,{JSONRpcTransport:()=>Eg});RA.exports=TL(DA);var Ig=br(),Xa=zn(),CL=ra(),jL=SA(),xA=EA(),BA=TA(),NL=am(),DL=La(),BL=io(),nn,Eg=class extends jL.Experimental_CoreClient{constructor({jsonRpcClient:e,mvr:r}){super({network:e.network,base:e,mvr:r}),xL(this,nn),PL(this,nn,e)}async getObjects(e){let r=(0,BL.chunk)(e.objectIds,50),n=[];for(let i of r){let s=await Cn(this,nn).multiGetObjects({ids:i,options:{showOwner:!0,showType:!0,showBcs:!0},signal:e.signal});for(let[o,u]of s.entries())u.error?n.push(xA.ObjectError.fromResponse(u.error,i[o])):n.push(PA(u.data))}return{objects:n}}async getOwnedObjects(e){let r=await Cn(this,nn).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 xA.ObjectError.fromResponse(n.error);return PA(n.data)}),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getCoins(e){let r=await Cn(this,nn).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(LL.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 Cn(this,nn).getBalance({owner:e.address,coinType:e.coinType,signal:e.signal});return{balance:{coinType:r.coinType,balance:r.totalBalance}}}async getAllBalances(e){return{balances:(await Cn(this,nn).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 Cn(this,nn).getTransactionBlock({digest:e.digest,options:{showRawInput:!0,showObjectChanges:!0,showRawEffects:!0,showEvents:!0,showEffects:!0},signal:e.signal});return{transaction:CA(r)}}async executeTransaction(e){let r=await Cn(this,nn).executeTransactionBlock({transactionBlock:e.transaction,signature:e.signatures,options:{showRawEffects:!0,showEvents:!0,showObjectChanges:!0,showRawInput:!0,showEffects:!0},signal:e.signal});return{transaction:CA(r)}}async dryRunTransaction(e){let r=CL.Transaction.from(e.transaction),n=await Cn(this,nn).dryRunTransactionBlock({transactionBlock:e.transaction,signal:e.signal}),{effects:i,objectTypes:s}=RL({effects:n.effects,objectChanges:n.objectChanges});return{transaction:{digest:await r.getDigest(),epoch:null,effects:i,objectTypes:Promise.resolve(s),signatures:[],transaction:(0,BA.parseTransactionBcs)(e.transaction)}}}async getReferenceGasPrice(e){let r=await Cn(this,nn).getReferenceGasPrice({signal:e?.signal});return{referenceGasPrice:String(r)}}async getDynamicFields(e){let r=await Cn(this,nn).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,Ig.fromBase64)(n.bcsName)}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor}}async verifyZkLoginSignature(e){let r=await Cn(this,nn).verifyZkLoginSignature({bytes:e.bytes,signature:e.signature,intentScope:e.intentScope,author:e.author});return{success:r.success,errors:r.errors}}resolveNameServiceNames(e){return Cn(this,nn).resolveNameServiceNames(e)}resolveTransactionPlugin(){return(0,NL.suiClientResolveTransactionPlugin)(Cn(this,nn))}};nn=new WeakMap;function PA(t){return{id:t.objectId,version:t.version,digest:t.digest,type:t.type,content:Promise.resolve(t.bcs?.dataType==="moveObject"?(0,Ig.fromBase64)(t.bcs.bcsBytes):new Uint8Array),owner:Ka(t.owner)}}function Ka(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 CA(t){let e=Xa.bcs.SenderSignedData.parse((0,Ig.fromBase64)(t.rawTransaction))[0],r={};t.objectChanges?.forEach(s=>{s.type!=="published"&&(r[s.objectId]=s.objectType)});let n=Xa.bcs.TransactionData.serialize(e.intentMessage.value).toBytes(),i=DL.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,BA.parseTransactionEffectsBcs)(new Uint8Array(t.rawEffects)),objectTypes:Promise.resolve(r),transaction:{...i,bcs:n},signatures:e.txSignatures}}function RL({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:Ka(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:Ka(o.owner),outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:Ka(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:Ka(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:Ka(e.gasObject.owner),idOperation:"None"},eventsDigest:e.eventsDigest??null,dependencies:e.dependencies??[],lamportVersion:e.gasObject.reference.version,changedObjects:n,unchangedSharedObjects:i,auxiliaryDataDigest:null}}}var UL=Xa.bcs.struct("Balance",{value:Xa.bcs.u64()}),LL=Xa.bcs.struct("Coin",{id:Xa.bcs.Address,balance:UL})});var qA=Me((bZ,FA)=>{"use strict";var xg=Object.defineProperty,$L=Object.getOwnPropertyDescriptor,FL=Object.getOwnPropertyNames,qL=Object.prototype.hasOwnProperty,VL=(t,e)=>{for(var r in e)xg(t,r,{get:e[r],enumerable:!0})},zL=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of FL(e))!qL.call(t,i)&&i!==r&&xg(t,i,{get:()=>e[i],enumerable:!(n=$L(e,i))||n.enumerable});return t},GL=t=>zL(xg({},"__esModule",{value:!0}),t),LA={};VL(LA,{SuiClient:()=>Tg,isSuiClient:()=>ZL});FA.exports=GL(LA);var Ja=br(),HL=bg(),WL=UA(),KL=ra(),mr=$r(),XL=Ll(),JL=mg(),Ps=Ru(),Za=Qu(),$A=Symbol.for("@mysten/SuiClient");function ZL(t){return typeof t=="object"&&t!==null&&t[$A]===!0}var Tg=class extends HL.Experimental_BaseClient{constructor(e){super({network:e.network??"unknown"}),this.jsonRpc=this,this.transport=e.transport??new JL.SuiHTTPTransport({url:e.url}),this.core=new WL.JSONRpcTransport({jsonRpcClient:this,mvr:e.mvr})}get[$A](){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,mr.isValidSuiAddress)((0,mr.normalizeSuiAddress)(r)))throw new Error("Invalid Sui address");return e&&(0,Za.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,mr.isValidSuiAddress)((0,mr.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,mr.isValidSuiAddress)((0,mr.normalizeSuiAddress)(e)))throw new Error("Invalid Sui address");return r&&(0,Za.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,mr.isValidSuiAddress)((0,mr.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,Za.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,Za.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,Ps.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,Ps.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,Ps.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,Ps.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,Ps.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,mr.isValidSuiAddress)((0,mr.normalizeSuiAddress)(e.owner)))throw new Error("Invalid Sui address");let r=e.filter?{...e.filter}:void 0;return r&&"MoveModule"in r&&(0,Ps.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,Za.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,mr.isValidSuiObjectId)((0,mr.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,mr.isValidSuiObjectId)((0,mr.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,Ps.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,mr.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,mr.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,Ja.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,mr.isValidSuiAddress)((0,mr.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,mr.isValidSuiObjectId)((0,mr.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,Za.hasMvrName)(e.MoveEventType)&&(e={...e,MoveEventType:(await this.core.mvr.resolveType({type:e.MoveEventType})).type}),e&&"MoveEventModule"in e&&(0,Ps.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,Ps.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,KL.isTransaction)(e.transactionBlock))e.transactionBlock.setSenderIfNotSet(e.sender),r=(0,Ja.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,Ja.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,Ja.toBase64)(e.transactionBlock)]})}async getDynamicFields(e){if(!e.parentId||!(0,mr.isValidSuiObjectId)((0,mr.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,Ja.fromBase58)(r.digest);return(0,Ja.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,XL.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 zA=Me((wZ,Dg)=>{"use strict";var jg=Object.defineProperty,YL=Object.getOwnPropertyDescriptor,QL=Object.getOwnPropertyNames,e$=Object.prototype.hasOwnProperty,t$=(t,e)=>{for(var r in e)jg(t,r,{get:e[r],enumerable:!0})},Cg=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of QL(e))!e$.call(t,i)&&i!==r&&jg(t,i,{get:()=>e[i],enumerable:!(n=YL(e,i))||n.enumerable});return t},r$=(t,e,r)=>(Cg(t,e,"default"),r&&Cg(r,e,"default")),n$=t=>Cg(jg({},"__esModule",{value:!0}),t),Ng={};t$(Ng,{JsonRpcError:()=>Pg.JsonRpcError,SuiClient:()=>VA.SuiClient,SuiHTTPStatusError:()=>Pg.SuiHTTPStatusError,SuiHTTPTransport:()=>i$.SuiHTTPTransport,SuiHTTPTransportError:()=>Pg.SuiHTTPTransportError,getFullnodeUrl:()=>s$.getFullnodeUrl,isSuiClient:()=>VA.isSuiClient});Dg.exports=n$(Ng);var i$=mg(),s$=YE();r$(Ng,_A(),Dg.exports);var VA=qA(),Pg=jf()});var H6=Me(Y=>{"use strict";var Bg=SE(),o$=jE(),ir=Jl(),GA=zA(),HA=require("@pythnetwork/pyth-sui-js");function a$(t){return t&&t.__esModule?t:{default:t}}var u$=a$(o$),c$=Object.create,Gg=Object.defineProperty,l$=Object.defineProperties,f$=Object.getOwnPropertyDescriptor,d$=Object.getOwnPropertyDescriptors,a6=Object.getOwnPropertyNames,WA=Object.getOwnPropertySymbols,h$=Object.getPrototypeOf,u6=Object.prototype.hasOwnProperty,p$=Object.prototype.propertyIsEnumerable,KA=(t,e,r)=>e in t?Gg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gc=(t,e)=>{for(var r in e||(e={}))u6.call(e,r)&&KA(t,r,e[r]);if(WA)for(var r of WA(e))p$.call(e,r)&&KA(t,r,e[r]);return t},$f=(t,e)=>l$(t,d$(e)),m$=(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')}),g$=(t,e)=>function(){return e||(0,t[a6(t)[0]])((e={exports:{}}).exports,e),e.exports},y$=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a6(e))!u6.call(t,i)&&i!==r&&Gg(t,i,{get:()=>e[i],enumerable:!(n=f$(e,i))||n.enumerable});return t},ru=(t,e,r)=>(r=t!=null?c$(h$(t)):{},y$(!t||!t.__esModule?Gg(r,"default",{value:t,enumerable:!0}):r,t)),qr=(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())}),nu=g$({"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=m$("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,me=ie>>>13,ze=y[6]|0,be=ze&8191,Pe=ze>>>13,qe=y[7]|0,ge=qe&8191,Fe=qe>>>13,Nt=y[8]|0,Te=Nt&8191,st=Nt>>>13,Tt=y[9]|0,Ie=Tt&8191,He=Tt>>>13,Et=v[0]|0,we=Et&8191,mt=Et>>>13,zt=v[1]|0,Ce=zt&8191,gt=zt>>>13,Gt=v[2]|0,je=Gt&8191,yt=Gt>>>13,Ht=v[3]|0,Ne=Ht&8191,_t=Ht>>>13,Wt=v[4]|0,De=Wt&8191,vt=Wt>>>13,Kt=v[5]|0,Be=Kt&8191,bt=Kt>>>13,Xt=v[6]|0,Re=Xt&8191,wt=Xt>>>13,Jt=v[7]|0,Ue=Jt&8191,Mt=Jt>>>13,Zt=v[8]|0,Le=Zt&8191,St=Zt>>>13,Yt=v[9]|0,$e=Yt&8191,pt=Yt>>>13;h.negative=a.negative^l.negative,h.length=19,g=Math.imul(z,we),f=Math.imul(z,mt),f=f+Math.imul(Z,we)|0,S=Math.imul(Z,mt);var Zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,g=Math.imul(E,we),f=Math.imul(E,mt),f=f+Math.imul(P,we)|0,S=Math.imul(P,mt),g=g+Math.imul(z,Ce)|0,f=f+Math.imul(z,gt)|0,f=f+Math.imul(Z,Ce)|0,S=S+Math.imul(Z,gt)|0;var Yn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,g=Math.imul(L,we),f=Math.imul(L,mt),f=f+Math.imul(U,we)|0,S=Math.imul(U,mt),g=g+Math.imul(E,Ce)|0,f=f+Math.imul(E,gt)|0,f=f+Math.imul(P,Ce)|0,S=S+Math.imul(P,gt)|0,g=g+Math.imul(z,je)|0,f=f+Math.imul(z,yt)|0,f=f+Math.imul(Z,je)|0,S=S+Math.imul(Z,yt)|0;var Qn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,g=Math.imul(q,we),f=Math.imul(q,mt),f=f+Math.imul($,we)|0,S=Math.imul($,mt),g=g+Math.imul(L,Ce)|0,f=f+Math.imul(L,gt)|0,f=f+Math.imul(U,Ce)|0,S=S+Math.imul(U,gt)|0,g=g+Math.imul(E,je)|0,f=f+Math.imul(E,yt)|0,f=f+Math.imul(P,je)|0,S=S+Math.imul(P,yt)|0,g=g+Math.imul(z,Ne)|0,f=f+Math.imul(z,_t)|0,f=f+Math.imul(Z,Ne)|0,S=S+Math.imul(Z,_t)|0;var ei=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,g=Math.imul(G,we),f=Math.imul(G,mt),f=f+Math.imul(K,we)|0,S=Math.imul(K,mt),g=g+Math.imul(q,Ce)|0,f=f+Math.imul(q,gt)|0,f=f+Math.imul($,Ce)|0,S=S+Math.imul($,gt)|0,g=g+Math.imul(L,je)|0,f=f+Math.imul(L,yt)|0,f=f+Math.imul(U,je)|0,S=S+Math.imul(U,yt)|0,g=g+Math.imul(E,Ne)|0,f=f+Math.imul(E,_t)|0,f=f+Math.imul(P,Ne)|0,S=S+Math.imul(P,_t)|0,g=g+Math.imul(z,De)|0,f=f+Math.imul(z,vt)|0,f=f+Math.imul(Z,De)|0,S=S+Math.imul(Z,vt)|0;var ti=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,g=Math.imul(oe,we),f=Math.imul(oe,mt),f=f+Math.imul(me,we)|0,S=Math.imul(me,mt),g=g+Math.imul(G,Ce)|0,f=f+Math.imul(G,gt)|0,f=f+Math.imul(K,Ce)|0,S=S+Math.imul(K,gt)|0,g=g+Math.imul(q,je)|0,f=f+Math.imul(q,yt)|0,f=f+Math.imul($,je)|0,S=S+Math.imul($,yt)|0,g=g+Math.imul(L,Ne)|0,f=f+Math.imul(L,_t)|0,f=f+Math.imul(U,Ne)|0,S=S+Math.imul(U,_t)|0,g=g+Math.imul(E,De)|0,f=f+Math.imul(E,vt)|0,f=f+Math.imul(P,De)|0,S=S+Math.imul(P,vt)|0,g=g+Math.imul(z,Be)|0,f=f+Math.imul(z,bt)|0,f=f+Math.imul(Z,Be)|0,S=S+Math.imul(Z,bt)|0;var ri=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(be,we),f=Math.imul(be,mt),f=f+Math.imul(Pe,we)|0,S=Math.imul(Pe,mt),g=g+Math.imul(oe,Ce)|0,f=f+Math.imul(oe,gt)|0,f=f+Math.imul(me,Ce)|0,S=S+Math.imul(me,gt)|0,g=g+Math.imul(G,je)|0,f=f+Math.imul(G,yt)|0,f=f+Math.imul(K,je)|0,S=S+Math.imul(K,yt)|0,g=g+Math.imul(q,Ne)|0,f=f+Math.imul(q,_t)|0,f=f+Math.imul($,Ne)|0,S=S+Math.imul($,_t)|0,g=g+Math.imul(L,De)|0,f=f+Math.imul(L,vt)|0,f=f+Math.imul(U,De)|0,S=S+Math.imul(U,vt)|0,g=g+Math.imul(E,Be)|0,f=f+Math.imul(E,bt)|0,f=f+Math.imul(P,Be)|0,S=S+Math.imul(P,bt)|0,g=g+Math.imul(z,Re)|0,f=f+Math.imul(z,wt)|0,f=f+Math.imul(Z,Re)|0,S=S+Math.imul(Z,wt)|0;var ni=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(ge,we),f=Math.imul(ge,mt),f=f+Math.imul(Fe,we)|0,S=Math.imul(Fe,mt),g=g+Math.imul(be,Ce)|0,f=f+Math.imul(be,gt)|0,f=f+Math.imul(Pe,Ce)|0,S=S+Math.imul(Pe,gt)|0,g=g+Math.imul(oe,je)|0,f=f+Math.imul(oe,yt)|0,f=f+Math.imul(me,je)|0,S=S+Math.imul(me,yt)|0,g=g+Math.imul(G,Ne)|0,f=f+Math.imul(G,_t)|0,f=f+Math.imul(K,Ne)|0,S=S+Math.imul(K,_t)|0,g=g+Math.imul(q,De)|0,f=f+Math.imul(q,vt)|0,f=f+Math.imul($,De)|0,S=S+Math.imul($,vt)|0,g=g+Math.imul(L,Be)|0,f=f+Math.imul(L,bt)|0,f=f+Math.imul(U,Be)|0,S=S+Math.imul(U,bt)|0,g=g+Math.imul(E,Re)|0,f=f+Math.imul(E,wt)|0,f=f+Math.imul(P,Re)|0,S=S+Math.imul(P,wt)|0,g=g+Math.imul(z,Ue)|0,f=f+Math.imul(z,Mt)|0,f=f+Math.imul(Z,Ue)|0,S=S+Math.imul(Z,Mt)|0;var ii=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,g=Math.imul(Te,we),f=Math.imul(Te,mt),f=f+Math.imul(st,we)|0,S=Math.imul(st,mt),g=g+Math.imul(ge,Ce)|0,f=f+Math.imul(ge,gt)|0,f=f+Math.imul(Fe,Ce)|0,S=S+Math.imul(Fe,gt)|0,g=g+Math.imul(be,je)|0,f=f+Math.imul(be,yt)|0,f=f+Math.imul(Pe,je)|0,S=S+Math.imul(Pe,yt)|0,g=g+Math.imul(oe,Ne)|0,f=f+Math.imul(oe,_t)|0,f=f+Math.imul(me,Ne)|0,S=S+Math.imul(me,_t)|0,g=g+Math.imul(G,De)|0,f=f+Math.imul(G,vt)|0,f=f+Math.imul(K,De)|0,S=S+Math.imul(K,vt)|0,g=g+Math.imul(q,Be)|0,f=f+Math.imul(q,bt)|0,f=f+Math.imul($,Be)|0,S=S+Math.imul($,bt)|0,g=g+Math.imul(L,Re)|0,f=f+Math.imul(L,wt)|0,f=f+Math.imul(U,Re)|0,S=S+Math.imul(U,wt)|0,g=g+Math.imul(E,Ue)|0,f=f+Math.imul(E,Mt)|0,f=f+Math.imul(P,Ue)|0,S=S+Math.imul(P,Mt)|0,g=g+Math.imul(z,Le)|0,f=f+Math.imul(z,St)|0,f=f+Math.imul(Z,Le)|0,S=S+Math.imul(Z,St)|0;var si=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(Ie,we),f=Math.imul(Ie,mt),f=f+Math.imul(He,we)|0,S=Math.imul(He,mt),g=g+Math.imul(Te,Ce)|0,f=f+Math.imul(Te,gt)|0,f=f+Math.imul(st,Ce)|0,S=S+Math.imul(st,gt)|0,g=g+Math.imul(ge,je)|0,f=f+Math.imul(ge,yt)|0,f=f+Math.imul(Fe,je)|0,S=S+Math.imul(Fe,yt)|0,g=g+Math.imul(be,Ne)|0,f=f+Math.imul(be,_t)|0,f=f+Math.imul(Pe,Ne)|0,S=S+Math.imul(Pe,_t)|0,g=g+Math.imul(oe,De)|0,f=f+Math.imul(oe,vt)|0,f=f+Math.imul(me,De)|0,S=S+Math.imul(me,vt)|0,g=g+Math.imul(G,Be)|0,f=f+Math.imul(G,bt)|0,f=f+Math.imul(K,Be)|0,S=S+Math.imul(K,bt)|0,g=g+Math.imul(q,Re)|0,f=f+Math.imul(q,wt)|0,f=f+Math.imul($,Re)|0,S=S+Math.imul($,wt)|0,g=g+Math.imul(L,Ue)|0,f=f+Math.imul(L,Mt)|0,f=f+Math.imul(U,Ue)|0,S=S+Math.imul(U,Mt)|0,g=g+Math.imul(E,Le)|0,f=f+Math.imul(E,St)|0,f=f+Math.imul(P,Le)|0,S=S+Math.imul(P,St)|0,g=g+Math.imul(z,$e)|0,f=f+Math.imul(z,pt)|0,f=f+Math.imul(Z,$e)|0,S=S+Math.imul(Z,pt)|0;var oi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(Ie,Ce),f=Math.imul(Ie,gt),f=f+Math.imul(He,Ce)|0,S=Math.imul(He,gt),g=g+Math.imul(Te,je)|0,f=f+Math.imul(Te,yt)|0,f=f+Math.imul(st,je)|0,S=S+Math.imul(st,yt)|0,g=g+Math.imul(ge,Ne)|0,f=f+Math.imul(ge,_t)|0,f=f+Math.imul(Fe,Ne)|0,S=S+Math.imul(Fe,_t)|0,g=g+Math.imul(be,De)|0,f=f+Math.imul(be,vt)|0,f=f+Math.imul(Pe,De)|0,S=S+Math.imul(Pe,vt)|0,g=g+Math.imul(oe,Be)|0,f=f+Math.imul(oe,bt)|0,f=f+Math.imul(me,Be)|0,S=S+Math.imul(me,bt)|0,g=g+Math.imul(G,Re)|0,f=f+Math.imul(G,wt)|0,f=f+Math.imul(K,Re)|0,S=S+Math.imul(K,wt)|0,g=g+Math.imul(q,Ue)|0,f=f+Math.imul(q,Mt)|0,f=f+Math.imul($,Ue)|0,S=S+Math.imul($,Mt)|0,g=g+Math.imul(L,Le)|0,f=f+Math.imul(L,St)|0,f=f+Math.imul(U,Le)|0,S=S+Math.imul(U,St)|0,g=g+Math.imul(E,$e)|0,f=f+Math.imul(E,pt)|0,f=f+Math.imul(P,$e)|0,S=S+Math.imul(P,pt)|0;var ai=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(Ie,je),f=Math.imul(Ie,yt),f=f+Math.imul(He,je)|0,S=Math.imul(He,yt),g=g+Math.imul(Te,Ne)|0,f=f+Math.imul(Te,_t)|0,f=f+Math.imul(st,Ne)|0,S=S+Math.imul(st,_t)|0,g=g+Math.imul(ge,De)|0,f=f+Math.imul(ge,vt)|0,f=f+Math.imul(Fe,De)|0,S=S+Math.imul(Fe,vt)|0,g=g+Math.imul(be,Be)|0,f=f+Math.imul(be,bt)|0,f=f+Math.imul(Pe,Be)|0,S=S+Math.imul(Pe,bt)|0,g=g+Math.imul(oe,Re)|0,f=f+Math.imul(oe,wt)|0,f=f+Math.imul(me,Re)|0,S=S+Math.imul(me,wt)|0,g=g+Math.imul(G,Ue)|0,f=f+Math.imul(G,Mt)|0,f=f+Math.imul(K,Ue)|0,S=S+Math.imul(K,Mt)|0,g=g+Math.imul(q,Le)|0,f=f+Math.imul(q,St)|0,f=f+Math.imul($,Le)|0,S=S+Math.imul($,St)|0,g=g+Math.imul(L,$e)|0,f=f+Math.imul(L,pt)|0,f=f+Math.imul(U,$e)|0,S=S+Math.imul(U,pt)|0;var ui=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ui>>>26)|0,ui&=67108863,g=Math.imul(Ie,Ne),f=Math.imul(Ie,_t),f=f+Math.imul(He,Ne)|0,S=Math.imul(He,_t),g=g+Math.imul(Te,De)|0,f=f+Math.imul(Te,vt)|0,f=f+Math.imul(st,De)|0,S=S+Math.imul(st,vt)|0,g=g+Math.imul(ge,Be)|0,f=f+Math.imul(ge,bt)|0,f=f+Math.imul(Fe,Be)|0,S=S+Math.imul(Fe,bt)|0,g=g+Math.imul(be,Re)|0,f=f+Math.imul(be,wt)|0,f=f+Math.imul(Pe,Re)|0,S=S+Math.imul(Pe,wt)|0,g=g+Math.imul(oe,Ue)|0,f=f+Math.imul(oe,Mt)|0,f=f+Math.imul(me,Ue)|0,S=S+Math.imul(me,Mt)|0,g=g+Math.imul(G,Le)|0,f=f+Math.imul(G,St)|0,f=f+Math.imul(K,Le)|0,S=S+Math.imul(K,St)|0,g=g+Math.imul(q,$e)|0,f=f+Math.imul(q,pt)|0,f=f+Math.imul($,$e)|0,S=S+Math.imul($,pt)|0;var ci=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ci>>>26)|0,ci&=67108863,g=Math.imul(Ie,De),f=Math.imul(Ie,vt),f=f+Math.imul(He,De)|0,S=Math.imul(He,vt),g=g+Math.imul(Te,Be)|0,f=f+Math.imul(Te,bt)|0,f=f+Math.imul(st,Be)|0,S=S+Math.imul(st,bt)|0,g=g+Math.imul(ge,Re)|0,f=f+Math.imul(ge,wt)|0,f=f+Math.imul(Fe,Re)|0,S=S+Math.imul(Fe,wt)|0,g=g+Math.imul(be,Ue)|0,f=f+Math.imul(be,Mt)|0,f=f+Math.imul(Pe,Ue)|0,S=S+Math.imul(Pe,Mt)|0,g=g+Math.imul(oe,Le)|0,f=f+Math.imul(oe,St)|0,f=f+Math.imul(me,Le)|0,S=S+Math.imul(me,St)|0,g=g+Math.imul(G,$e)|0,f=f+Math.imul(G,pt)|0,f=f+Math.imul(K,$e)|0,S=S+Math.imul(K,pt)|0;var li=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(li>>>26)|0,li&=67108863,g=Math.imul(Ie,Be),f=Math.imul(Ie,bt),f=f+Math.imul(He,Be)|0,S=Math.imul(He,bt),g=g+Math.imul(Te,Re)|0,f=f+Math.imul(Te,wt)|0,f=f+Math.imul(st,Re)|0,S=S+Math.imul(st,wt)|0,g=g+Math.imul(ge,Ue)|0,f=f+Math.imul(ge,Mt)|0,f=f+Math.imul(Fe,Ue)|0,S=S+Math.imul(Fe,Mt)|0,g=g+Math.imul(be,Le)|0,f=f+Math.imul(be,St)|0,f=f+Math.imul(Pe,Le)|0,S=S+Math.imul(Pe,St)|0,g=g+Math.imul(oe,$e)|0,f=f+Math.imul(oe,pt)|0,f=f+Math.imul(me,$e)|0,S=S+Math.imul(me,pt)|0;var fi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(Ie,Re),f=Math.imul(Ie,wt),f=f+Math.imul(He,Re)|0,S=Math.imul(He,wt),g=g+Math.imul(Te,Ue)|0,f=f+Math.imul(Te,Mt)|0,f=f+Math.imul(st,Ue)|0,S=S+Math.imul(st,Mt)|0,g=g+Math.imul(ge,Le)|0,f=f+Math.imul(ge,St)|0,f=f+Math.imul(Fe,Le)|0,S=S+Math.imul(Fe,St)|0,g=g+Math.imul(be,$e)|0,f=f+Math.imul(be,pt)|0,f=f+Math.imul(Pe,$e)|0,S=S+Math.imul(Pe,pt)|0;var di=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(Ie,Ue),f=Math.imul(Ie,Mt),f=f+Math.imul(He,Ue)|0,S=Math.imul(He,Mt),g=g+Math.imul(Te,Le)|0,f=f+Math.imul(Te,St)|0,f=f+Math.imul(st,Le)|0,S=S+Math.imul(st,St)|0,g=g+Math.imul(ge,$e)|0,f=f+Math.imul(ge,pt)|0,f=f+Math.imul(Fe,$e)|0,S=S+Math.imul(Fe,pt)|0;var hi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(Ie,Le),f=Math.imul(Ie,St),f=f+Math.imul(He,Le)|0,S=Math.imul(He,St),g=g+Math.imul(Te,$e)|0,f=f+Math.imul(Te,pt)|0,f=f+Math.imul(st,$e)|0,S=S+Math.imul(st,pt)|0;var pi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(Ie,$e),f=Math.imul(Ie,pt),f=f+Math.imul(He,$e)|0,S=Math.imul(He,pt);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]=Yn,M[2]=Qn,M[3]=ei,M[4]=ti,M[5]=ri,M[6]=ni,M[7]=ii,M[8]=si,M[9]=oi,M[10]=ai,M[11]=ui,M[12]=ci,M[13]=li,M[14]=fi,M[15]=di,M[16]=hi,M[17]=pi,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 pe(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()}pe.prototype._tmp=function(){var a=new o(null);return a.words=new Array(Math.ceil(this.n/13)),a},pe.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},pe.prototype.split=function(a,l){a.iushrn(this.n,0,l)},pe.prototype.imulK=function(a){return a.imul(this.k)};function A(){pe.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(A,pe),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(){pe.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,pe);function C(){pe.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(C,pe);function D(){pe.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(D,pe),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)}}),lr=ru(nu()),Ya=ru(nu()),c6=(t=>(t.InvalidType="InvalidType",t))(c6||{}),l6=(t=>(t.MissAggregatorPackage="MissAggregatorPackage",t.MissGlobalConfig="MissGlobalConfig",t.InvalidWallet="InvalidWallet",t.SimulateError="SimulateError",t))(l6||{}),f6=(t=>(t.InsufficientBalance="InsufficientBalance",t.SimulateEventError="simulateEventError",t.CannotGetDecimals="CannotGetDecimals",t.MissCoinA="MissCoinA",t.MissCoinB="MissCoinB",t.MissTurbosFeeType="MissTurbosFeeType",t.MissAftermathLpSupplyType="MissAftermathLpSupplyType",t))(f6||{}),d6=(t=>(t[t.NumberTooLarge=1e3]="NumberTooLarge",t[t.RateLimitExceeded=1001]="RateLimitExceeded",t[t.InsufficientLiquidity=1002]="InsufficientLiquidity",t[t.HoneyPot=1003]="HoneyPot",t))(d6||{});function Uf(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 _$=class h6 extends Error{constructor(e,r){super(e),this.message=e,this.errorCode=r}static isAggregatorErrorCode(e,r){return e instanceof h6&&e.errorCode===r}},v$=0,p6=1,b$=2;function XA(t,e){return t===e?v$:t<e?p6:b$}function w$(t,e){let r=0,n=t.length<=e.length?t.length:e.length,i=XA(t.length,e.length);for(;r<n;){let s=XA(t.charCodeAt(r),e.charCodeAt(r));if(r+=1,s!==0)return s}return i}function M$(t,e){return w$(t,e)===p6}function Rg(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 S$(t){return t.split("::")[0]}function eu(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=eu(r),d=$f(gc({},c),{type_arguments:i.map(p=>eu(p).source_address)});return d.type_arguments=d.type_arguments.map(p=>Pi.isSuiCoin(p)?p:eu(p).source_address),d.source_address=Rg(d.full_address,d.type_arguments),d}let s=r.split("::"),u={full_address:r,address:r===Hg||r===y6?"0x2":ir.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=Rg(u.full_address,u.type_arguments),u}catch{return{full_address:t,address:"",module:"",name:"",type_arguments:[],source_address:t}}}function Ug(t){return eu(t).source_address}function m6(t){return t.toLowerCase().startsWith("0x")?ir.normalizeSuiObjectId(t):t}function g6(t){for(let e in t){let r=typeof t[e];if(r==="object")g6(t[e]);else if(r==="string"){let n=t[e];t[e]=m6(n)}}}function k$(t,e,r){return`${t}::${e}::${r}`}var O$="0x2::coin::Coin",E$=/^0x2::coin::Coin<(.+)>$/,A$=1e3,I$=500,T$=100,x$=100,P$=1e3,Hg="0x2::sui::SUI",y6="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",C$="SUI",j$=450,N$="0x0000000000000000000000000000000000000005",Pi=class Mo{static getCoinTypeArg(e){let r=e.type.match(E$);return r?r[1]:null}static isSUI(e){let r=Mo.getCoinTypeArg(e);return r?Mo.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`${O$}<${e}>`}static getCoinAssets(e,r){let n=[];return r.forEach(i=>{Ug(i.coinAddress)===Ug(e)&&n.push(i)}),n}static isSuiCoin(e){return eu(e).full_address===Hg}static selectCoinObjectIdGreaterThanOrEqual(e,r,n=[]){let i=Mo.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=Mo.sortByBalance(e.filter(d=>!n.includes(d.coinObjectId))),s=Mo.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:Mo.sortByBalance(u),remainingCoins:Mo.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 Ns(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 _6(t,e){return t.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]})}function v6(t,e){t=Ns(t),e=Ns(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 D$(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 B$(t){let e=/<([^>]*)>/,r=t.match(e);if(r)return r[1]}function R$(t,e,r,n){let i=Pi.getCoinAssets(n,e);if(r===BigInt(0))return Pi.isSuiCoin(n)||i.length===0&&!Pi.isSuiCoin(n)?{targetCoin:_6(t,n),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:t.object(i[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(i[0].balance.toString())};if(Pi.calculateTotalBalance(i)<r)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+n,"InsufficientBalance"+n);if(Pi.isSuiCoin(n))return{targetCoin:t.splitCoins(t.gas,[t.pure.u64(r.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(r.toString())};let o=Pi.sortByBalance(i);o.slice(0,3).reduce((b,O)=>b+O.balance,BigInt(0))<BigInt(r)&&(o=Pi.sortByBalanceDes(i));let c=Pi.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 bc=ru(nu()),fa=new bc.default(0),U$=new bc.default(1),b6=new bc.default(2),L$=b6.pow(new bc.default(128)),$$=new bc.default("18446744073709551615"),Ff="18446744073709551615",F$=1e9,q$="aggregator",V$="CETUS",z$="DEEPBOOK",G$="KRIYA",H$="FLOWX",W$="TURBOS",K$="AFTERMATH",X$="integrate",J$="cetus",Z$="deepbook",Y$="kriya",Q$="utils",eF="pool",tF="pay",rF="flowx_amm",nF="turbos",iF="aftermath",w6="custodian_v2",M6="clob_v2",sF="flash_swap",oF="flash_swap_with_partner",aF="repay_flash_swap",uF="repay_flash_swap_with_partner",cF="flash_swap_a2b",lF="flash_swap_b2a",fF="flash_swap_with_partner_a2b",dF="flash_swap_with_partner_b2a",hF="repay_flash_swap_a2b",pF="repay_flash_swap_b2a",mF="repay_flash_swap_with_partner_a2b",gF="repay_flash_swap_with_partner_b2a",yF="swap_a2b",_F="swap_b2a",vF="transfer_or_destroy_coin",bF="check_coins_threshold",wF="join_vec",MF="transfer_account_cap",SF="0x0000000000000000000000000000000000000000000000000000000000000006",kF="0x1::coin::CoinInfo",OF="0x1::coin::CoinStore",EF="0x2::coin::zero",S6="0x000000000000000000000000000000000000000000000000000000000000dee9",k6="0x000000000000000000000000000000000000000000000000000000000000dee9",AF="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",O6="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",IF="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",TF="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",xF="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",PF="",CF="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",jF="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",NF="",DF="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",BF="",RF="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",UF="",LF="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",$F="",FF="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",qF="",yc={AGGREGATOR_V3:"aggregator_v3"},VF="https://api-sui.cetus.zone/router_v3",zF="https://api-sui.cetus.zone/router_v2",GF={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},Wf={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},_c={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},Cs={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"}},jt={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:Ff,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},E6=1010102;function HF(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 Ya.default(t.amount_in.toString()),amountOut:new Ya.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 A6(t,e,r,n,i){return qr(this,null,function*(){let s;if(r.liquidityChanges&&r.liquidityChanges.length>0?s=yield KF(t,r):s=yield WF(t,e,r),!s)return null;if(!s.ok){let c=1e3;return s.status===429&&(c=1001),{quoteID:"",amountIn:fa,amountOut:fa,paths:[],byAmountIn:r.byAmountIn,insufficientLiquidity:!1,deviationRatio:0,error:{code:c,msg:Uf(c)}}}let o=u$.default.parse(yield s.text()),u=o.msg==="liquidity is not enough";if(o.msg&&o.msg.indexOf("HoneyPot scam")>-1)return{quoteID:"",amountIn:fa,amountOut:fa,paths:[],byAmountIn:r.byAmountIn,insufficientLiquidity:u,deviationRatio:0,error:{code:1003,msg:Uf(1003)}};if(o.data!=null){let c=HF(o.data,r.byAmountIn);if(n>0&&i!=="0x0")if(r.byAmountIn){let d=c.amountOut.mul(new Ya.default(n)).div(new Ya.default(1e6));c.overlayFee=Number(d.toString()),c.amountOut=c.amountOut.sub(d)}else{let d=c.amountIn.mul(new Ya.default(n)).div(new Ya.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:fa,amountOut:fa,paths:[],insufficientLiquidity:u,byAmountIn:r.byAmountIn,deviationRatio:0,error:{code:1002,msg:Uf(1002)}}})}function WF(t,e,r){return qr(this,null,function*(){try{let{from:n,target:i,amount:s,byAmountIn:o,depth:u,splitAlgorithm:c,splitFactor:d,splitCount:p,providers:_}=r,b=Ns(n),O=Ns(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=${E6}`,console.log("url",T),yield fetch(T)}catch(n){return console.error(n),null}})}function KF(t,e){return qr(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=Ns(r),O=Ns(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:E6};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 XF(t){return qr(this,null,function*(){let e=`${t}/deepbookv3_config`;try{return(yield fetch(e)).json()}catch(r){return console.error("Error:",r),null}})}function Lg(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 I6=(t=>(t[t.Mainnet=0]="Mainnet",t[t.Testnet=1]="Testnet",t))(I6||{}),JF=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}},ZF=ru(nu()),Qa=9e15,Eo=1e9,$g="0123456789abcdef",qf="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Vf="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Fg={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Qa,maxE:Qa,crypto:!1},T6,js,dt=!0,Kf="[DecimalError] ",Oo=Kf+"Invalid argument: ",x6=Kf+"Precision limit exceeded",P6=Kf+"crypto unavailable",C6="[object Decimal]",sn=Math.floor,Pr=Math.pow,YF=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,QF=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,eq=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,j6=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ji=1e7,rt=7,tq=9007199254740991,rq=qf.length-1,qg=Vf.length-1,fe={toStringTag:C6};fe.absoluteValue=fe.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),Ke(t)};fe.ceil=function(){return Ke(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(Oo+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())+rt,n.rounding=1,r=nq(n,U6(n,r)),n.precision=t,n.rounding=e,Ke(js==2||js==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(dt=!1,s=p.s*Pr(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Vr(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=Pr(r,1/3),t=sn((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=qt(d.plus(p).times(u),d.plus(c),o+2,1),Vr(u.d).slice(0,o)===(r=Vr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(Ke(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")&&(Ke(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return dt=!0,Ke(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-sn(this.e/rt))*rt,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};fe.dividedBy=fe.div=function(t){return qt(this,new this.constructor(t))};fe.dividedToIntegerBy=fe.divToInt=function(t){var e=this,r=e.constructor;return Ke(qt(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 Ke(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/Jf(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=tu(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 Ke(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=tu(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/Jf(5,t)),i=tu(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,Ke(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,qt(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()?Ci(r,i,s):new r(0):new r(NaN):e.isZero()?Ci(r,i+4,s).times(.5):(r.precision=i+6,r.rounding=1,e=e.asin(),t=Ci(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,dt=!1,r=r.times(r).minus(1).sqrt().plus(r),dt=!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,dt=!1,r=r.times(r).plus(1).sqrt().plus(r),dt=!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?Ke(new s(i),t,e,!0):(s.precision=r=n-i.e,i=qt(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=Ci(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<=qg)return o=Ci(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=qg)return o=Ci(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/rt+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(dt=!1,e=Math.ceil(u/rt),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)),dt=!0,Ke(o,p.precision=_,p.rounding=b,!0)};fe.isFinite=function(){return!!this.d};fe.isInteger=fe.isInt=function(){return!!this.d&&sn(this.e/rt)>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(dt=!1,u=_+O,o=ko(d,u),n=e?zf(p,u+10):ko(t,u),c=qt(o,n,u,1),vc(c.d,i=_,b))do if(u+=10,o=ko(d,u),n=e?zf(p,u+10):ko(t,u),c=qt(o,n,u,1),!s){+Vr(c.d).slice(i+1,i+15)+1==1e14&&(c=Ke(c,_+1,0));break}while(vc(c.d,i+=10,b));return dt=!0,Ke(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 dt?Ke(t,u,c):t}if(r=sn(t.e/rt),p=sn(O.e/rt),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/rt),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]=ji-1;--d[i],d[n]+=ji}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=Xf(d,r),dt?Ke(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]?Ke(new n(r),n.precision,n.rounding):(dt=!1,n.modulo==9?(e=qt(r,t.abs(),0,3,1),e.s*=t.s):e=qt(r,t,0,n.modulo,1),e=e.times(t),dt=!0,r.minus(e))};fe.naturalExponential=fe.exp=function(){return Vg(this)};fe.naturalLogarithm=fe.ln=function(){return ko(this)};fe.negated=fe.neg=function(){var t=new this.constructor(this);return t.s=-t.s,Ke(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(_)),dt?Ke(t,u,c):t;if(s=sn(_.e/rt),n=sn(t.e/rt),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/rt),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)/ji|0,d[i]%=ji;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=Xf(d,n),dt?Ke(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(Oo+t);return r.d?(e=N6(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};fe.round=function(){var t=this,e=t.constructor;return Ke(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())+rt,n.rounding=1,r=sq(n,U6(n,r)),n.precision=t,n.rounding=e,Ke(js>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(dt=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Vr(u),(e.length+c)%2==0&&(e+="0"),d=Math.sqrt(e),c=sn((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(qt(o,s,r+2,1)).times(.5),Vr(s.d).slice(0,r)===(e=Vr(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(Ke(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")&&(Ke(n,c+1,1),t=!n.times(n).eq(o));break}return dt=!0,Ke(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=qt(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,Ke(js==2||js==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=sn(p.e/rt)+sn(t.e/rt),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%ji|0,e=u/ji|0;s[i]=(s[i]+e)%ji|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=Xf(s,r),dt?Ke(t,_.precision,_.rounding):t};fe.toBinary=function(t,e){return Wg(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:(kn(t,0,Eo),e===void 0?e=n.rounding:kn(e,0,8),Ke(r,t+r.e+1,e))};fe.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=as(n,!0):(kn(t,0,Eo),e===void 0?e=i.rounding:kn(e,0,8),n=Ke(new i(n),t+1,e),r=as(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=as(i):(kn(t,0,Eo),e===void 0?e=s.rounding:kn(e,0,8),n=Ke(new s(i),t+i.e+1,e),r=as(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=N6(T)-O.e-1,o=s%rt,e.d[0]=Pr(10,o<0?rt+o:o),t==null)t=s>0?e:d;else{if(u=new x(t),!u.isInt()||u.lt(d))throw Error(Oo+u);t=u.gt(e)?s>0?e:d:u}for(dt=!1,u=new x(Vr(T)),p=x.precision,x.precision=s=T.length*rt*2;_=qt(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=qt(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=qt(d,n,s,1).minus(O).abs().cmp(qt(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,dt=!0,b};fe.toHexadecimal=fe.toHex=function(t,e){return Wg(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:kn(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]?(dt=!1,r=qt(r,t,0,e,1).times(t),dt=!0,Ke(r)):(t.s=r.s,r=t),r};fe.toNumber=function(){return+this};fe.toOctal=function(t,e){return Wg(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(Pr(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return Ke(u,n,s);if(e=sn(t.e/rt),e>=t.d.length-1&&(r=d<0?-d:d)<=tq)return i=D6(c,u,r,n),t.s<0?new c(1).div(i):Ke(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=Pr(+u,d),e=r==0||!isFinite(r)?sn(d*(Math.log("0."+Vr(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):(dt=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=Vg(t.times(ko(u,n+r)),n),i.d&&(i=Ke(i,n+5,1),vc(i.d,n,s)&&(e=n+10,i=Ke(Vg(t.times(ko(u,e+r)),e),e+5,1),+Vr(i.d).slice(n+1,n+15)+1==1e14&&(i=Ke(i,n+1,0)))),i.s=o,dt=!0,c.rounding=s,Ke(i,n,s))};fe.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=as(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(kn(t,1,Eo),e===void 0?e=i.rounding:kn(e,0,8),n=Ke(new i(n),t,e),r=as(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):(kn(t,1,Eo),e===void 0?e=n.rounding:kn(e,0,8)),Ke(new n(r),t,e)};fe.toString=function(){var t=this,e=t.constructor,r=as(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};fe.truncated=fe.trunc=function(){return Ke(new this.constructor(this),this.e+1,1)};fe.valueOf=fe.toJSON=function(){var t=this,e=t.constructor,r=as(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Vr(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=rt-n.length,r&&(s+=So(r)),s+=n;o=t[e],n=o+"",r=rt-n.length,r&&(s+=So(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function kn(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Oo+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+=rt,i=0):(i=Math.ceil((e+1)/rt),e%=rt),s=Pr(10,rt-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)==Pr(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)==Pr(10,e-3)-1,o}function Lf(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]+=$g.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 nq(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/Jf(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=tu(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 qt=(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,pe,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=ji,O=rt,p=sn(n.e/O)-sn(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--;_++)pe=b*c+(a[_]||0),H[_]=pe/l|0,b=pe%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,T6=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,Ke(R,u?s+R.e+1:s,o,T)}return R}})();function Ke(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+=rt,o=e,p=_[b=0],c=p/Pr(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/rt),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=rt,o=s-rt+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=rt,o=s-rt+i,c=o<0?0:p/Pr(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%Pr(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/Pr(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]=Pr(10,(rt-e%rt)%rt),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=Pr(10,rt-s),_[b]=o>0?(p/Pr(10,i-o)%Pr(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]==ji&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=ji)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return dt&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function as(t,e,r){if(!t.isFinite())return R6(t);var n,i=t.e,s=Vr(t.d),o=s.length;return e?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+So(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):i<0?(s="0."+So(-i-1)+s,r&&(n=r-o)>0&&(s+=So(n))):i>=o?(s+=So(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+So(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=So(n))),s}function Xf(t,e){var r=t[0];for(e*=rt;r>=10;r/=10)e++;return e}function zf(t,e,r){if(e>rq)throw dt=!0,r&&(t.precision=r),Error(x6);return Ke(new t(qf),e,1,!0)}function Ci(t,e,r){if(e>qg)throw Error(x6);return Ke(new t(Vf),e,r,!0)}function N6(t){var e=t.length-1,r=e*rt+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 So(t){for(var e="";t--;)e+="0";return e}function D6(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/rt+4);for(dt=!1;;){if(r%2&&(s=s.times(e),ZA(s.d,o)&&(i=!0)),r=sn(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}e=e.times(e),ZA(e.d,o)}return dt=!0,s}function JA(t){return t.d[t.d.length-1]&1}function B6(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 Vg(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?(dt=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(Pr(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=Ke(s.times(t),c,1),r=r.times(++p),u=o.plus(qt(s,r,c,1)),Vr(u.d).slice(0,c)===Vr(o.d).slice(0,c)){for(i=_;i--;)o=Ke(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 Ke(o,b.precision=T,O,dt=!0);else return b.precision=T,o}o=u}}function ko(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?(dt=!1,p=J):p=e,R.precision=p+=T,r=Vr(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=Vr(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=zf(R,p+2,J).times(s+""),x=ko(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?Ke(x,J,H,dt=!0):x;for(_=x,c=o=x=qt(x.minus(1),x.plus(1),p,1),b=Ke(x.times(x),p,1),i=3;;){if(o=Ke(o.times(b),p,1),d=c.plus(qt(o,new R(i),p,1)),Vr(d.d).slice(0,p)===Vr(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus(zf(R,p+2,J).times(s+""))),c=qt(c,new R(O),p,1),e==null)if(vc(c.d,p-T,H,u))R.precision=p+=T,d=o=x=qt(_.minus(1),_.plus(1),p,1),b=Ke(x.times(x),p,1),i=u=1;else return Ke(c,R.precision=J,H,dt=!0);else return R.precision=J,c;c=d,i+=2}}function R6(t){return String(t.s*t.s/0)}function zg(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)%rt,r<0&&(n+=rt),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=rt;n<i;)t.d.push(+e.slice(n,n+=rt));e=e.slice(n),n=rt-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),dt&&(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 iq(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),j6.test(e))return zg(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(QF.test(e))r=16,e=e.toLowerCase();else if(YF.test(e))r=2;else if(eq.test(e))r=8;else throw Error(Oo+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=D6(n,new n(r),s,s*2)),d=Lf(e,r,ji),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=Xf(d,p),t.d=d,dt=!1,o&&(t=qt(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?Pr(2,c):wc.pow(2,c))),dt=!0,t)}function sq(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:tu(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/Jf(5,r)),e=tu(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 tu(t,e,r,n,i){var s,o,u,c,d=t.precision,p=Math.ceil(d/rt);for(dt=!1,c=r.times(r),u=new t(n);;){if(o=qt(u.times(c),new t(e++*e++),d,1),u=i?n.plus(o):n.minus(o),n=qt(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 dt=!0,o.d.length=p+1,o}function Jf(t,e){for(var r=t;--e;)r*=t;return r}function U6(t,e){var r,n=e.s<0,i=Ci(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=JA(r)?n?2:3:n?4:1,e;js=JA(r)?n?1:4:n?3:2}return e.minus(i).abs()}function Wg(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor,T=r!==void 0;if(T?(kn(r,1,Eo),n===void 0?n=O.rounding:kn(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=R6(t);else{for(p=as(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=Lf(as(b),10,i),b.e=b.d.length),_=Lf(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=qt(t,b,r,n,0,i),_=t.d,s=t.e,d=T6),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+=$g.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(_=Lf(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=$g.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 ZA(t,e){if(t.length>e)return t.length=e,!0}function oq(t){return new this(t).abs()}function aq(t){return new this(t).acos()}function uq(t){return new this(t).acosh()}function cq(t,e){return new this(t).plus(e)}function lq(t){return new this(t).asin()}function fq(t){return new this(t).asinh()}function dq(t){return new this(t).atan()}function hq(t){return new this(t).atanh()}function pq(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=Ci(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?Ci(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=Ci(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan(qt(t,e,s,1)),e=Ci(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(qt(t,e,s,1)),r}function mq(t){return new this(t).cbrt()}function gq(t){return Ke(t=new this(t),t.e+1,2)}function yq(t,e,r){return new this(t).clamp(e,r)}function _q(t){if(!t||typeof t!="object")throw Error(Kf+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,Eo,"rounding",0,8,"toExpNeg",-Qa,0,"toExpPos",0,Qa,"maxE",0,Qa,"minE",-Qa,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=Fg[r]),(n=t[r])!==void 0)if(sn(n)===n&&n>=s[e+1]&&n<=s[e+2])this[r]=n;else throw Error(Oo+r+": "+n);if(r="crypto",i&&(this[r]=Fg[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(P6);else this[r]=!1;else throw Error(Oo+r+": "+n);return this}function vq(t){return new this(t).cos()}function bq(t){return new this(t).cosh()}function L6(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,YA(s)){d.s=s.s,dt?!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++;dt?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 zg(d,s.toString())}else if(c!=="string")throw Error(Oo+s);return(u=s.charCodeAt(0))===45?(s=s.slice(1),d.s=-1):(u===43&&(s=s.slice(1)),d.s=1),j6.test(s)?zg(d,s):iq(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=_q,i.clone=L6,i.isDecimal=YA,i.abs=oq,i.acos=aq,i.acosh=uq,i.add=cq,i.asin=lq,i.asinh=fq,i.atan=dq,i.atanh=hq,i.atan2=pq,i.cbrt=mq,i.ceil=gq,i.clamp=yq,i.cos=vq,i.cosh=bq,i.div=wq,i.exp=Mq,i.floor=Sq,i.hypot=kq,i.ln=Oq,i.log=Eq,i.log10=Iq,i.log2=Aq,i.max=Tq,i.min=xq,i.mod=Pq,i.mul=Cq,i.pow=jq,i.random=Nq,i.round=Dq,i.sign=Bq,i.sin=Rq,i.sinh=Uq,i.sqrt=Lq,i.sub=$q,i.sum=Fq,i.tan=qq,i.tanh=Vq,i.trunc=zq,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 wq(t,e){return new this(t).div(e)}function Mq(t){return new this(t).exp()}function Sq(t){return Ke(t=new this(t),t.e+1,3)}function kq(){var t,e,r=new this(0);for(dt=!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 dt=!0,new this(1/0);r=e}return dt=!0,r.sqrt()}function YA(t){return t instanceof wc||t&&t.toStringTag===C6||!1}function Oq(t){return new this(t).ln()}function Eq(t,e){return new this(t).log(e)}function Aq(t){return new this(t).log(2)}function Iq(t){return new this(t).log(10)}function Tq(){return B6(this,arguments,"lt")}function xq(){return B6(this,arguments,"gt")}function Pq(t,e){return new this(t).mod(e)}function Cq(t,e){return new this(t).mul(e)}function jq(t,e){return new this(t).pow(e)}function Nq(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:kn(t,1,Eo),n=Math.ceil(t/rt),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(P6);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=rt,n&&t&&(i=Pr(10,rt-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-=rt)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<rt&&(r-=rt-n)}return o.e=r,o.d=u,o}function Dq(t){return Ke(t=new this(t),t.e+1,this.rounding)}function Bq(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Rq(t){return new this(t).sin()}function Uq(t){return new this(t).sinh()}function Lq(t){return new this(t).sqrt()}function $q(t,e){return new this(t).sub(e)}function Fq(){var t=0,e=arguments,r=new this(e[t]);for(dt=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return dt=!0,Ke(r,this.precision,this.rounding)}function qq(t){return new this(t).tan()}function Vq(t){return new this(t).tanh()}function zq(t){return Ke(t=new this(t),t.e+1,1)}fe[Symbol.for("nodejs.util.inspect.custom")]=fe.toString;fe[Symbol.toStringTag]="Decimal";var wc=fe.constructor=L6(Fg);qf=new wc(qf);Vf=new wc(Vf);var Gf=wc;function Gq(t,e,r){return Number($6(new Gf(t.toString()),e,r).toFixed(0))}function QA(t,e,r){let n=$6(new Gf(t.toString()),e,r);return new ZF.default(n.toFixed(0))}function $6(t,e,r){return e?t.mul(1-r):t.mul(1+r)}var e6=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?jt.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(ir.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(ir.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})}},Hq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::kriya_clmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Wq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::flowx_clmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Kq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::turbos::swap`,typeArguments:[e.coinAType,e.coinBType,e.feeType],arguments:n})}},Xq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::bluefin::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Jq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::momentum::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Zq=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::magma::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Yq=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?jt.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})}},Qq=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?jt.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})}},eV=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?jt.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})}},tV=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::deepbookv3::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?_c.Mainnet:_c.Testnet}},rV=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})}},nV=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?jt.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(ir.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})}},iV=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?jt.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(ir.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})}},t6=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?jt.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})}},sV=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::haedal_hmm::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},oV=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::obric::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},aV=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?jt.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(ir.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(ir.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})}},uV=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?jt.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(ir.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(ir.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(ir.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})}},cV=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?jt.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(ir.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(ir.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(ir.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})}},lV="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",fV="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",dV="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",hV=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?jt.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 lV:{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 fV:case dV:{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(ir.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})}},pV=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?jt.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})}},mV=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?jt.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})}},gV=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?jt.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})}},yV=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?jt.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})}},_V=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?jt.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})}},vV=jt.DEFAULT_PUBLISHED_AT.Mainnet;function Mc(t,e){return t&&t.has(yc.AGGREGATOR_V3)?t.get(yc.AGGREGATOR_V3):e||vV}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=Mc(_,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 n6(t,e){let{swapContext:r,targetCoinType:n,aggregatorPublishedAt:i,packages:s}=t,o=Mc(s,i);return e.moveCall({target:`${o}::router::confirm_swap`,typeArguments:[n],arguments:[r]})}function bV(t,e){let{coinType:r,amount:n,swapCtx:i,aggregatorPublishedAt:s,packages:o}=t,u=Mc(o,s),c=[i,e.pure.u64(n.toString())];return e.moveCall({target:`${u}::router::take_balance`,typeArguments:[r],arguments:c})}function wV(t,e){let{balance:r,coinType:n,recipient:i,aggregatorPublishedAt:s,packages:o}=t,u=Mc(o,s),c=[r,e.pure.address(i)];e.moveCall({target:`${u}::router::transfer_balance`,typeArguments:[n],arguments:c})}function MV(t,e){let{coin:r,coinType:n,aggregatorPublishedAt:i,packages:s}=t,o=Mc(s,i);e.moveCall({target:`${o}::router::transfer_or_destroy_coin`,typeArguments:[n],arguments:[r]})}function SV(){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 kV(){let t=Date.now(),e=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${t.toString(16)}_${e}`}function F6(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 OV(t){if(!F6(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 q6(t){return t.endsWith("/find_routes")?t.replace("/find_routes",""):t}function EV(t,e,r){return qr(this,null,function*(){let n=yield AV(e,r);return n!==null?{accountCap:t.object(n),isCreate:!1}:{accountCap:t.moveCall({target:`${k6}::${M6}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function AV(t,e){return qr(this,null,function*(){let r=50,n=null;for(;;){let i=t.getOwnedObjects({owner:e,cursor:n,limit:r,filter:{MoveModule:{package:S6,module:w6}}});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 IV(t,e){return e?.has("aggregator_v2")?e.get("aggregator_v2"):t||Wf.V2.Mainnet}function TV(t,e){return e?.has("aggregator_v2_extend")?e.get("aggregator_v2_extend"):t||Wf.V2_EXTEND.Mainnet}function xV(t,e){return e?.has("aggregator_v2_extend2")?e.get("aggregator_v2_extend2"):t||Wf.V2_EXTEND2.Mainnet}var jn=ru(nu());function PV(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:CV(n),gasUsed:n.computationCost||"0",gasPrice:"1000",success:!0}}function CV(t){let e=new jn.default(t.computationCost||"0"),r=new jn.default(t.storageCost||"0"),n=new jn.default(t.storageRebate||"0"),i=new jn.default(t.nonRefundableStorageFee||"0");return e.add(r).sub(n).add(i).toString()}function jV(t,e){let r=new jn.default(e);return r.isZero()?0:t.div(r).toNumber()}function NV(t,e,r=1){let n=t.mul(new jn.default(Math.floor(r*1e6))).div(new jn.default(1e6));return n.isZero()?0:n.sub(e).mul(new jn.default(1e4)).div(n).toNumber()/100}function DV(t,e){let r=t.filter(u=>u.gasMetrics.success),n=e.filter(u=>u.gasMetrics.success),i=i6(r),s=i6(n),o=i.isZero()?0:i.sub(s).mul(new jn.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 i6(t){return t.length===0?new jn.default(0):t.reduce((r,n)=>r.add(new jn.default(n.gasMetrics.totalGasCost)),new jn.default(0)).div(new jn.default(t.length))}function BV(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 RV(t){return JSON.stringify(t,null,2)}function UV(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 s6=ru(nu()),LV=t=>{var e,r,n;return $f(gc({},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=$f(gc({},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})})},$V=t=>{var e;return $f(gc({},t),{amountIn:new s6.default(t?.amountIn),amountOut:new s6.default(t?.amountIn),paths:(e=t?.paths)==null?void 0:e.map(n=>{var i,s,o,u;let c=gc({},n);return n?.initialPrice&&(c.initialPrice=new Gf((i=n?.initialPrice)==null?void 0:i.toString())),(s=n?.extendedDetails)!=null&&s.after_sqrt_price&&(c.extendedDetails={after_sqrt_price:new Gf((u=(o=n?.extendedDetails)==null?void 0:o.after_sqrt_price)==null?void 0:u.toString())}),c})})};function FV(t,e=!0){return qr(this,null,function*(){console.log("inputs",t.getData().inputs),t.getData().commands.forEach((r,n)=>{e&&console.log(`transaction ${n}: `,JSON.stringify(r,qV,2))})})}function qV(t,e){return typeof e=="bigint"?e.toString():e}function VV(t){return!(!t.startsWith("0x")||t.length!==66)}var zV=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},GV=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?jt.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(ir.SUI_CLOCK_OBJECT_ID)];t.moveCall({target:`${e.publishedAt}::fullsail::swap`,typeArguments:[e.coinAType,e.coinBType],arguments:n})}},Hf="CETUS",HV="DEEPBOOK",Kg="KRIYA",Xg="FLOWX",Jg="FLOWXV3",Zg="KRIYAV3",Yg="TURBOS",Qg="AFTERMATH",ey="HAEDAL",ty="VOLO",ry="AFSUI",ny="BLUEMOVE",iy="DEEPBOOKV3",sy="SCALLOP",oy="SUILEND",ay="BLUEFIN",Zf="HAEDALPMM",uy="ALPHAFI",cy="SPRINGSUI",ly="STEAMM",Yf="METASTABLE",Qf="OBRIC",fy="HAWAL",ed="STEAMM_OMM",dy="MOMENTUM",td="STEAMM_OMM_V2",hy="MAGMA",rd="SEVENK",nd="HAEDALHMMV2",py="FULLSAIL",V6="https://api-sui.cetus.zone/router_v3",id=[Hf,Kg,Xg,Jg,Zg,Yg,Qg,ey,ty,ry,ny,iy,sy,oy,ay,Zf,uy,cy,ly,Yf,Qf,fy,dy,ed,td,hy,rd,nd,py];function WV(){return id}function KV(t){return id.filter(e=>!t.includes(e))}function XV(t){return id.filter(e=>t.includes(e))}function o6(t){let e=new Set;for(let r of t){if(r.provider===Zf&&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===Yf&&(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===Qf&&(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===ed||r.provider===td)&&(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===rd&&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===nd&&r.extendedDetails&&r.extendedDetails.haedalhmmv2_base_price_seed&&e.add(r.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(e)}var z6=class G6{constructor(e){var r,n;this.endpoint=e.endpoint?q6(e.endpoint):V6,this.client=e.client||new GA.SuiClient({url:GA.getFullnodeUrl("mainnet")}),this.signer=e.signer||"",this.env=e.env||0;let i=G6.CONFIG[this.env];if(this.pythConnections=this.newPythClients((r=e.pythUrls)!=null?r:[]),this.pythClient=new HA.SuiPythClient(this.client,i.pythStateId,i.wormholeStateId),this.apiKey=e.apiKey||"",this.partner=e.partner,e.overlayFeeRate)if(e.overlayFeeRate>0&&e.overlayFeeRate<=Cs.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=e.overlayFeeRate*jt.FEE_DENOMINATOR,this.overlayFeeRate>jt.MAX_FEE_RATE)throw new Error(Cs.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(Cs.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(n=e.overlayFeeReceiver)!=null?n:Cs.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(e){return e.includes("https://hermes.pyth.network")||e.push("https://hermes.pyth.network"),e.map(n=>new HA.SuiPriceServiceConnection(n,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?_c.Mainnet:_c.Testnet}getOneCoinUsedToMerge(e){return qr(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 qr(this,null,function*(){return A6(this.endpoint,this.apiKey,e,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(e,r,n,i,s,o,u,c,d){return qr(this,null,function*(){})}newDexRouterV3(e,r,n){switch(e){case Hf:return new e6(this.env,n);case Zg:return new Hq(this.env);case Jg:return new Wq(this.env);case Yg:return new Kq(this.env);case ay:return new Xq(this.env);case dy:return new Jq(this.env);case hy:return new Zq(this.env);case Kg:return new Yq(this.env);case Xg:return new Qq(this.env);case ny:return new eV(this.env);case iy:return new tV(this.env);case Qg:return new rV(this.env);case ly:return new nV(this.env);case sy:return new iV(this.env);case oy:return new t6(this.env);case cy:return new t6(this.env);case Zf:return new sV(this.env,r);case Qf:return new oV(this.env,r);case rd:return new aV(this.env,r);case ed:return new uV(this.env,r);case td:return new cV(this.env,r);case Yf:return new hV(this.env,r);case uy:return new pV(this.env);case ty:return new mV(this.env);case ry:return new gV(this.env);case ey:return new yV(this.env);case fy:return new _V(this.env);case nd:return new zV(this.env,r);case py:return new GV(this.env);default:throw new Error(`${Cs.ERRORS.UNSUPPORTED_DEX} ${e}`)}}expectInputSwapV3(e,r,n,i,s,o,u){if(n.quoteID==null)throw new Error(Cs.ERRORS.QUOTE_ID_REQUIRED);let c=Lg(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 n6({swapContext:d,targetCoinType:c.targetCoinType,packages:c.packages},e)}expectOutputSwapV3(e,r,n,i,s,o){let u=[],c=new e6(this.env,o),d=Lg(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),_=YV(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=bV({coinType:d.fromCoinType,amount:Ff,swapCtx:p,packages:d.packages},e);return wV({balance:T,coinType:d.fromCoinType,recipient:this.signer,packages:d.packages},e),n6({swapContext:p,targetCoinType:d.targetCoinType,packages:d.packages},e)}routerSwap(e){return qr(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(Cs.ERRORS.INVALID_SLIPPAGE);let c=e.router.byAmountIn,d=r.amountIn,p=r.amountOut,_=new lr.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(c?_=p.mul(new lr.default(this.overlayFeeRate)).div(new lr.default(1e6)):_=d.mul(new lr.default(this.overlayFeeRate)).div(new lr.default(1e6)));let b=c?p.sub(_):p,O=c?d:d.add(_),T=QA(c?b:O,c,i);if(!e.router.packages||!e.router.packages.get(yc.AGGREGATOR_V3))throw new Error(Cs.ERRORS.PACKAGES_REQUIRED);let x=o6(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 qr(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 lr.default(this.overlayFeeRate)).div(new lr.default(1e6)).toString()):p=Number(r.amountIn.mul(new lr.default(this.overlayFeeRate)).div(new lr.default(1e6)).toString()));let _=d?r.amountOut.sub(new lr.default(p)):r.amountOut,b=d?r.amountIn:r.amountIn.add(new lr.default(p)),O=Gq(d?_:b,d,n),T=d?b:O,x=Bg.coinWithBalance({balance:BigInt(T.toString()),useGasCoin:!0,type:u}),F;o&&o>0&&(F=Bg.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(Pi.isSuiCoin(c))i.mergeCoins(i.gas,[H]);else{let J=yield this.getOneCoinUsedToMerge(c);J!=null?i.mergeCoins(i.object(J),[H]):MV({coin:H,coinType:c,packages:r.packages},i)}})}fixableRouterSwapV3(e){return qr(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 lr.default(this.overlayFeeRate)).div(new lr.default(1e6)).toString()):c=Number(r.amountIn.mul(new lr.default(this.overlayFeeRate)).div(new lr.default(1e6)).toString()));let d=r.byAmountIn?r.amountOut.sub(new lr.default(c)):r.amountOut,p=r.byAmountIn?r.amountIn:r.amountIn.add(new lr.default(c)),_=QA(r.byAmountIn?d:p,r.byAmountIn,i),b=o6(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 qr(this,null,function*(){var r,n,i,s;let{from:o,target:u,amount:c,byAmountIn:d,pools:p}=e,_=Ns(o),b=Ns(u),O=new Bg.Transaction,T=v6(_,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 lr.default(0):new lr.default(Ff),te=0;for(let l=0;l<ee.length;l+=1)if(!ee[l].parsedJson.data.is_exceed)if(e.byAmountIn){let h=new lr.default(ee[l].parsedJson.data.amount_out);h.gt(ae)&&(te=l,ae=h)}else{let h=new lr.default(ee[l].parsedJson.data.amount_out);h.lt(ae)&&(te=l,ae=h)}let pe=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(pe.fee_rate)/1e6,D=new lr.default((n=pe.amount_in)!=null?n:0),N=new lr.default((i=pe.fee_amount)!=null?i:0),k=D.add(N),m={amountIn:k,amountOut:new lr.default((s=pe.amount_out)!=null?s:0),paths:[{id:p[te],direction:T,provider:Hf,from:_,target:b,feeRate:C,amountIn:k.toString(),amountOut:pe.amount_out,publishedAt:O6,extendedDetails:{afterSqrtPrice:pe.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:e.byAmountIn,quoteID:`degraded-${ZV()}`,packages:new Map([[yc.AGGREGATOR_V3,jt.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:pe.is_exceed,routeData:m}})}updatePythPriceIDs(e,r){return qr(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 qr(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:e,sender:this.signer})})}sendTransaction(e,r){return qr(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:r})})}};z6.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var JV=z6;function ZV(){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 YV(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 QV=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=ry;Y.AFTERMATH=Qg;Y.AFTERMATH_AMM=K$;Y.AFTERMATH_MODULE=iF;Y.AGGREGATOR=q$;Y.AGGREGATOR_V3_CONFIG=jt;Y.ALL_DEXES=id;Y.ALPHAFI=uy;Y.AggregatorClient=JV;Y.AggregatorConfig=JF;Y.AggregatorError=_$;Y.AggregatorServerErrorCode=d6;Y.BLUEFIN=ay;Y.BLUEMOVE=ny;Y.CETUS=Hf;Y.CETUS_DEX=V$;Y.CETUS_MODULE=J$;Y.CETUS_PUBLISHED_AT=AF;Y.CETUS_V3_PUBLISHED_AT=O6;Y.CHECK_COINS_THRESHOLD_FUNC=bF;Y.CLIENT_CONFIG=Cs;Y.CLOCK_ADDRESS=SF;Y.CoinInfoAddress=kF;Y.CoinStoreAddress=OF;Y.CoinUtils=Pi;Y.ConfigErrorCode=l6;Y.DEEPBOOKV2=HV;Y.DEEPBOOKV3=iy;Y.DEEPBOOK_CLOB_V2_MODULE=M6;Y.DEEPBOOK_CUSTODIAN_V2_MODULE=w6;Y.DEEPBOOK_DEX=z$;Y.DEEPBOOK_MODULE=Z$;Y.DEEPBOOK_PACKAGE_ID=S6;Y.DEEPBOOK_PUBLISHED_AT=k6;Y.DEEPBOOK_V3_DEEP_FEE_TYPES=_c;Y.DEFAULT_AGG_V2_ENDPOINT=zF;Y.DEFAULT_AGG_V3_ENDPOINT=VF;Y.DEFAULT_ENDPOINT=V6;Y.DEFAULT_GAS_BUDGET_FOR_MERGE=I$;Y.DEFAULT_GAS_BUDGET_FOR_SPLIT=A$;Y.DEFAULT_GAS_BUDGET_FOR_STAKE=P$;Y.DEFAULT_GAS_BUDGET_FOR_TRANSFER=T$;Y.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=x$;Y.DEFAULT_NFT_TRANSFER_GAS_FEE=j$;Y.Env=I6;Y.FLOWXV2=Xg;Y.FLOWXV3=Jg;Y.FLOWX_AMM=H$;Y.FLOWX_AMM_MODULE=rF;Y.FULLSAIL=py;Y.FlashSwapA2BFunc=cF;Y.FlashSwapB2AFunc=lF;Y.FlashSwapFunc=sF;Y.FlashSwapWithPartnerA2BFunc=fF;Y.FlashSwapWithPartnerB2AFunc=dF;Y.FlashSwapWithPartnerFunc=oF;Y.GAS_SYMBOL=C$;Y.GAS_TYPE_ARG=Hg;Y.GAS_TYPE_ARG_LONG=y6;Y.HAEDAL=ey;Y.HAEDALHMMV2=nd;Y.HAEDALPMM=Zf;Y.HAWAL=fy;Y.INTEGRATE=X$;Y.JOIN_FUNC=wF;Y.KRIYA=Kg;Y.KRIYAV3=Zg;Y.KRIYA_DEX=G$;Y.KRIYA_MODULE=Y$;Y.MAGMA=hy;Y.MAINNET_AFTERMATH_INSURANCE_FUND_ID=LF;Y.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=DF;Y.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=FF;Y.MAINNET_AFTERMATH_REGISTRY_ID=jF;Y.MAINNET_AFTERMATH_TREASURY_ID=RF;Y.MAINNET_CETUS_GLOBAL_CONFIG_ID=IF;Y.MAINNET_FLOWX_AMM_CONTAINER_ID=xF;Y.METASTABLE=Yf;Y.MOMENTUM=dy;Y.OBRIC=Qf;Y.ONE=U$;Y.PACKAGE_NAMES=yc;Y.PAY_MODULE=tF;Y.POOL_MODULT=eF;Y.PUBLISHED_ADDRESSES=Wf;Y.PYTH_CONFIG=GF;Y.REPAY_FLASH_SWAP_A2B_FUNC=hF;Y.REPAY_FLASH_SWAP_B2A_FUNC=pF;Y.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=mF;Y.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=gF;Y.RepayFalshSwapFunc=aF;Y.RepayFlashSwapWithPartnerFunc=uF;Y.SCALLOP=sy;Y.SEVENK=rd;Y.SPRINGSUI=cy;Y.STEAMM=ly;Y.STEAMM_OMM=ed;Y.STEAMM_OMM_V2=td;Y.SUILEND=oy;Y.SUI_SYSTEM_STATE_OBJECT_ID=N$;Y.SWAP_A2B_FUNC=yF;Y.SWAP_B2A_FUNC=_F;Y.SuiZeroCoinFn=EF;Y.TEN_POW_NINE=F$;Y.TESTNET_AFTERMATH_INSURANCE_FUND_ID=$F;Y.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=BF;Y.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=qF;Y.TESTNET_AFTERMATH_REGISTRY_ID=NF;Y.TESTNET_AFTERMATH_TREASURY_ID=UF;Y.TESTNET_CETUS_GLOBAL_CONFIG_ID=TF;Y.TESTNET_FLOWX_AMM_CONTAINER_ID=PF;Y.TRANSFER_ACCOUNT_CAP=MF;Y.TRANSFER_OR_DESTORY_COIN_FUNC=vF;Y.TURBOS=Yg;Y.TURBOS_DEX=W$;Y.TURBOS_MODULE=nF;Y.TURBOS_VERSIONED=CF;Y.TWO=b6;Y.TransactionErrorCode=f6;Y.TypesErrorCode=c6;Y.U128=L$;Y.U64_MAX=Ff;Y.U64_MAX_BN=$$;Y.UTILS_MODULE=Q$;Y.VOLO=ty;Y.ZERO=fa;Y.buildInputCoin=R$;Y.calculateGasEfficiency=jV;Y.calculatePriceImpact=NV;Y.checkInvalidSuiAddress=VV;Y.compareCoins=v6;Y.compareGasMetrics=DV;Y.completionCoin=Ns;Y.composeType=Rg;Y.createTarget=k$;Y.dealWithFastRouterSwapParamsForMsafe=LV;Y.exportToCSV=UV;Y.exportToJSON=RV;Y.extractAddressFromType=S$;Y.extractGasMetrics=PV;Y.extractStructTagFromType=eu;Y.extractTimestampFromDowngradeUuid6=OV;Y.fixSuiObjectId=m6;Y.formatGasMetrics=BV;Y.generateDowngradeUuid6=SV;Y.generateSimpleDowngradeUuid6=kV;Y.getAggregatorServerErrorMessage=Uf;Y.getAggregatorV2Extend2PublishedAt=xV;Y.getAggregatorV2ExtendPublishedAt=TV;Y.getAggregatorV2PublishedAt=IV;Y.getAllProviders=WV;Y.getDeepbookV3Config=XF;Y.getDefaultSuiInputType=QV;Y.getOrCreateAccountCap=EV;Y.getProvidersExcluding=KV;Y.getProvidersIncluding=XV;Y.getRouterResult=A6;Y.isSortedSymbols=M$;Y.isValidDowngradeUuid6=F6;Y.mintZeroCoin=_6;Y.normalizeCoinType=Ug;Y.parseAftermathFeeType=B$;Y.parseTurbosPoolFeeType=D$;Y.patchFixSuiObjectId=g6;Y.printTransaction=FV;Y.processEndpoint=q6;Y.processFlattenRoutes=Lg;Y.restituteMsafeFastRouterSwapParams=$V});var aH={};rT(aH,{CetusLeverageSDK:()=>Cc,default:()=>oH,leverage_mainnet:()=>Id});module.exports=nT(aH);var XI=require("@cetusprotocol/common-sdk");var Dc=require("@cetusprotocol/common-sdk");var Id={full_rpc_url:Dc.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Dc.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};var D_=require("@suilend/sdk/client"),ar=require("@suilend/sdk");var iT=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Td=Math.ceil,Bn=Math.floor,_n="[BigNumber Error] ",Ry=_n+"Number primitive has more than 15 significant digits: ",mi=1e14,Ot=14,xd=9007199254740991,Pd=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Fs=1e7,jr=1e9;function Uy(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(!iT.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(dr(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(Ry+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!==Bn(A)))throw Error(Ry+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)%Ot,k<0&&(m+=Ot),m<l){for(m&&y.c.push(+h.slice(0,m)),l-=Ot;m<l;)y.c.push(+h.slice(m,m+=Ot));m=Ot-(h=h.slice(m)).length}else m-=l;for(;m--;h+="0");y.c.push(+h)}}else y.c=[y.e=0]}H.clone=Uy,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],dr(C,0,jr,I),o=C),A.hasOwnProperty(I="ROUNDING_MODE")&&(C=A[I],dr(C,0,8,I),u=C),A.hasOwnProperty(I="EXPONENTIAL_AT")&&(C=A[I],C&&C.pop?(dr(C[0],-jr,0,I),dr(C[1],0,jr,I),c=C[0],d=C[1]):(dr(C,-jr,jr,I),c=-(d=C<0?-C:C))),A.hasOwnProperty(I="RANGE"))if(C=A[I],C&&C.pop)dr(C[0],-jr,-1,I),dr(C[1],1,jr,I),p=C[0],_=C[1];else if(dr(C,-jr,jr,I),C)p=-(_=C<0?-C:C);else throw Error(_n+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(_n+"crypto unavailable");else b=C;else throw Error(_n+I+" not true or false: "+C);if(A.hasOwnProperty(I="MODULO_MODE")&&(C=A[I],dr(C,0,9,I),O=C),A.hasOwnProperty(I="POW_PRECISION")&&(C=A[I],dr(C,0,jr,I),T=C),A.hasOwnProperty(I="FORMAT"))if(C=A[I],typeof C=="object")x=C;else throw Error(_n+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(_n+I+" invalid: "+C)}else throw Error(_n+"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>=-jr&&N<=jr&&N===Bn(N)){if(D[0]===0){if(N===0&&D.length===1)return!0;break e}if(I=(N+1)%Ot,I<1&&(I+=Ot),String(D[0]).length==I){for(I=0;I<D.length;I++)if(C=D[I],C<0||C>=mi||C!==Bn(C))break e;if(C!==0)return!0}}}else if(D===null&&N===null&&(k===null||k===1||k===-1))return!0;throw Error(_n+"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 Bn(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:dr(C,0,jr),m=Td(C/Ot),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(_n+"crypto unavailable");if(!b)for(;l<m;)a=I(),a<9e15&&(h[l++]=a%1e14);for(m=h[--l],C%=Ot,m&&C&&(a=Pd[Ot-C],h[l]=Bn(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-=Ot);for(l=1,a=h[0];a>=10;a/=10,l++);l<Ot&&(k-=Ot-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(fs(Dn(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?fs(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=fs(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%Fs,w=N/Fs|0;for(D=D.slice();v--;)l=D[v]%Fs,h=D[v]/Fs|0,m=w*l+h*M,a=M*l+m%Fs*Fs+y,y=(a/k|0)+(m/Fs|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=mi,h=Rn(D.e/Ot)-Rn(N.e/Ot),U=U/Ot|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=Bn(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=Bn(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==mi){for(y=1,U=S[0];U>=10;U/=10,y++);te(f,k+(f.e=y+h*Ot-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:dr(C,0,8),!A.c)return A.toString();if(N=A.c[0],m=A.e,I==null)l=Dn(A.c),l=D==1||D==2&&(m<=c||m>=d)?Rc(l,m):fs(l,m,"0");else if(A=te(new H(A),I,C),k=A.e,l=Dn(A.c),a=l.length,D==1||D==2&&(I<=k||k<=c)){for(;a<I;l+="0",a++);l=Rc(l,k)}else if(I-=m+(D===2&&k>m),l=fs(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*Ot-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(_n+"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=Pd;if(v){e:{for(N=1,a=v[0];a>=10;a/=10,N++);if(k=I-N,k<0)k+=Ot,m=I,l=v[h=0],y=Bn(l/M[N-m-1]%10);else if(h=Td((k+1)/Ot),h>=v.length)if(D){for(;v.length<=h;v.push(0));l=y=0,N=1,k%=Ot,m=k-Ot+1}else break e;else{for(l=a=v[h],N=1;a>=10;a/=10,N++);k%=Ot,m=k-Ot+N,y=m<0?0:Bn(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[(Ot-I%Ot)%Ot],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[Ot-k],v[h]=m>0?Bn(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]==mi&&(v[0]=1));break}else{if(v[h]+=a,v[h]!=mi)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 pe(A){var I,C=A.e;return C===null?A.toString():(I=Dn(A.c),I=C<=c||C>=d?Rc(I,C):fs(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 dr(A,0,jr),I==null?I=u:dr(I,0,8),te(new H(k),A+k.e+1,I);if(!(C=k.c))return null;if(D=((N=C.length-1)-Rn(this.e/Ot))*Ot,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(_n+"Exponent not an integer: "+pe(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(+pe(v),a?A.s*(2-Bc(A)):+pe(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&&Bc(A)?-0:0,v.e>-1&&(k=1/k),new H(l?1/k:k);T&&(k=Td(T/Ot+2))}for(a?(C=new H(.5),l&&(A.s=1),h=Bc(A)):(N=Math.abs(+pe(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=Bn(N/2),N===0)break;h=N%2}else if(A=A.times(C),te(A,A.e+1,1),A.e>14)h=Bc(A);else{if(N=+pe(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:dr(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&&Rn(this.e/Ot)>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/Ot,h=A.e/Ot,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=Rn(l),h=Rn(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=mi-1;D>a;){if(y[--D]<v[D]){for(C=D;C&&!y[--C];y[C]=I);--y[C],y[D]+=mi}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=Rn(V.e/Ot)+Rn(A.e/Ot),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=mi,S=Fs,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/Ot,m=A.e/Ot,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=Rn(k),m=Rn(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)/mi|0,a[I]=mi===a[I]?0:a[I]%mi;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 dr(A,1,jr),I==null?I=u:dr(I,0,8),te(new H(k),A,I);if(!(C=k.c))return null;if(N=C.length-1,D=N*Ot+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 dr(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(+pe(k)),a==0||a==1/0?(I=Dn(m),(I.length+l)%2==0&&(I+="0"),a=Math.sqrt(+I),l=Rn((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))),Dn(N.c).slice(0,a)===(I=Dn(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&&(dr(A,0,jr),A++),J(this,A,I,1)},i.toFixed=function(A,I){return A!=null&&(dr(A,0,jr),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(_n+"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(_n+"Argument "+(a.isInteger()?"out of range: ":"not an integer: ")+pe(a));if(!g)return new H(w);for(I=new H(s),h=C=new H(s),D=l=new H(s),M=Dn(g),k=I.e=M.length-w.e-1,I.c[0]=Pd[(m=k%Ot)<0?Ot+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+pe(this)},i.toPrecision=function(A,I){return A!=null&&dr(A,1,jr),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?Rc(Dn(C.c),N):fs(Dn(C.c),N,"0"):A===10&&R?(C=te(new H(C),o+N+1,u),I=fs(Dn(C.c),C.e,"0")):(dr(A,2,F.length,"Base"),I=r(fs(Dn(C.c),N,"0"),10,A,D,!0)),D<0&&C.c[0]&&(I="-"+I)),I},i.valueOf=i.toJSON=function(){return pe(this)},i._isBigNumber=!0,i[Symbol.toStringTag]="BigNumber",i[Symbol.for("nodejs.util.inspect.custom")]=i.valueOf,t!=null&&H.set(t),H}function Rn(t){var e=t|0;return t>0||t===e?e:e-1}function Dn(t){for(var e,r,n=1,i=t.length,s=t[0]+"";n<i;){for(e=t[n++]+"",r=Ot-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 dr(t,e,r,n){if(t<e||t>r||t!==Bn(t))throw Error(_n+(n||"Argument")+(typeof t=="number"?t<e||t>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function Bc(t){var e=t.c.length-1;return Rn(t.e/Ot)==e&&t.c[e]%2!=0}function Rc(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function fs(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 sT=Uy(),Ri=sT;var Ui=require("@suilend/sdk"),ga=require("@suilend/sui-fe");var Ly=Nc(require("crypto")),Lc=new Uint8Array(256),Uc=Lc.length;function Cd(){return Uc>Lc.length-16&&(Ly.default.randomFillSync(Lc),Uc=0),Lc.slice(Uc,Uc+=16)}var Rr=[];for(let t=0;t<256;++t)Rr.push((t+256).toString(16).slice(1));function $y(t,e=0){return Rr[t[e+0]]+Rr[t[e+1]]+Rr[t[e+2]]+Rr[t[e+3]]+"-"+Rr[t[e+4]]+Rr[t[e+5]]+"-"+Rr[t[e+6]]+Rr[t[e+7]]+"-"+Rr[t[e+8]]+Rr[t[e+9]]+"-"+Rr[t[e+10]]+Rr[t[e+11]]+Rr[t[e+12]]+Rr[t[e+13]]+Rr[t[e+14]]+Rr[t[e+15]]}var Fy=Nc(require("crypto")),jd={randomUUID:Fy.default.randomUUID};function oT(t,e,r){if(jd.randomUUID&&!e&&!t)return jd.randomUUID();t=t||{};let n=t.random||(t.rng||Cd)();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 $y(n)}var $c=oT;var qy=require("@cetusprotocol/common-sdk"),Nd=10n;function Vy(t){return t.depositedAmount.eq(0)?new Ri(0):t.borrowedAmount.div(t.depositedAmount).times(100)}function Dd(t){let e=Vy(t);if(!e.gt(100))return(0,Ui.linearlyInterpolate)(t.config.interestRate,"utilPercent","aprPercent",e)}function zy(t){let e=Vy(t),r=Dd(t);if(!(r===void 0||e.gt(100)))return new Ri(e.div(100)).times(r.div(100)).times(1-t.config.spreadFeeBps/1e4).times(100)}function Gy(t,e,r,n){let{apiUrl:i}=(0,qy.getPackagerConfigs)(n.sdkOptions.suilend);t===Ui.Side.DEPOSIT&&([ga.NORMALIZED_flSUI_COINTYPE,ga.NORMALIZED_jugSUI_COINTYPE].includes(e.coinType)&&r.push({stats:{id:$c(),isActive:!0,rewardIndex:-1,reserve:e,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${i}/partners/LiqAg.png`,perDay:new Ri(.036),side:Ui.Side.DEPOSIT},obligationClaims:{}}),e.coinType===ga.NORMALIZED_LBTC_COINTYPE&&r.push({stats:{id:$c(),isActive:!0,rewardIndex:-1,reserve:e,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${i}/partners/Lombard Lux.png`,perDay:new Ri(0),side:Ui.Side.DEPOSIT},obligationClaims:{}}))}function Hy(t,e,r){return{...t,depositedAmount:e===Ui.Side.DEPOSIT?Ri.max(t.depositedAmount.plus(r),0):t.depositedAmount,borrowedAmount:e===Ui.Side.BORROW?Ri.max(t.borrowedAmount.plus(r),0):t.borrowedAmount}}function Wy(t,e,r){let n=t===Ui.Side.DEPOSIT?e.depositedAmount:e.borrowedAmount,i=t===Ui.Side.DEPOSIT?r.depositedAmount:r.borrowedAmount,s=i.eq(0)?new Ri(-1):n.div(i);return{multiplier:s,isValid:!s.eq(-1)}}function Ky(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 Xy(t,e){if(!Nd)throw new Error("oraclePriceMultiplierDecimal is required");if(t===0n)throw new Error("Invalid oracle price");if(e<0n){let r=10n**(Nd- -e);return t*r}return t/10n**(e+Nd)}var Xr=require("@cetusprotocol/common-sdk");function aT(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Zy(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 Bd(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Yy(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Rd(t){if(!Array.isArray(t))throw new Error("array expected")}function Qy(t,e){if(!Zy(!0,e))throw new Error(`${t}: array of strings expected`)}function uT(t,e){if(!Zy(!1,e))throw new Error(`${t}: array of numbers expected`)}function cT(...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 lT(t){let e=typeof t=="string"?t.split(""):t,r=e.length;Qy("alphabet",e);let n=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Rd(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=>(Rd(i),i.map(s=>{Bd("alphabet.decode",s);let o=n.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function fT(t=""){return Bd("join",t),{encode:e=>(Qy("join.decode",e),e.join(t)),decode:e=>(Bd("join.decode",e),e.split(t))}}function Jy(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(Rd(t),!t.length)return[];let n=0,i=[],s=Array.from(t,u=>{if(Yy(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 dT(t){Yy(t);let e=2**8;return{encode:r=>{if(!aT(r))throw new Error("radix.encode input should be Uint8Array");return Jy(Array.from(r),e,t)},decode:r=>(uT("radix.decode",r),Uint8Array.from(Jy(r,t,e)))}}var hT=t=>cT(dT(58),lT(t),fT("")),Ud=hT("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var gi=t=>Ud.encode(t),En=t=>Ud.decode(t);function hr(t){return Uint8Array.from(atob(t),e=>e.charCodeAt(0))}var Ld=8192;function Qt(t){if(t.length<Ld)return btoa(String.fromCharCode(...t));let e="";for(var r=0;r<t.length;r+=Ld){let n=t.slice(r,r+Ld);e+=String.fromCharCode(...n)}return btoa(e)}function qs(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 cn(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function Vs(t,e){return Array.from({length:Math.ceil(t.length/e)},(r,n)=>t.slice(n*e,(n+1)*e))}var ya=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=yT(r),this._batchScheduleFn=_T(r),this._cacheKeyFn=vT(r),this._cacheMap=bT(r),this._batch=null,this.name=wT(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=mT(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(!e_(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}},pT=typeof process=="object"&&typeof process.nextTick=="function"?function(t){$d||($d=Promise.resolve()),$d.then(()=>{process.nextTick(t)})}:typeof setImmediate=="function"?function(t){setImmediate(t)}:function(t){setTimeout(t)},$d;function mT(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(()=>{gT(t,r)}),r}function gT(t,e){if(e.hasDispatched=!0,e.keys.length===0){qd(e);return}let r;try{r=t._batchLoadFn(e.keys)}catch(n){return Fd(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 Fd(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(!e_(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)}`);qd(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=>{Fd(t,e,n)})}function Fd(t,e,r){qd(e);for(let n=0;n<e.keys.length;n++)t.clear(e.keys[n]),e.callbacks[n].reject(r)}function qd(t){if(t.cacheHits)for(let e=0;e<t.cacheHits.length;e++)t.cacheHits[e]()}function yT(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 _T(t){let e=t&&t.batchScheduleFn;if(e===void 0)return pT;if(typeof e!="function")throw new TypeError(`batchScheduleFn must be a function: ${e}`);return e}function vT(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 bT(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 wT(t){return t&&t.name?t.name:null}function e_(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 Do(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 t_(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 Fc=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}=t_(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 Vd(t,e){switch(e){case"base58":return gi(t);case"base64":return Qt(t);case"hex":return cn(t);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function yu(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 qc=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 zd(BigInt(e),8).forEach(r=>this.write8(r)),this}write128(e){return zd(BigInt(e),16).forEach(r=>this.write8(r)),this}write256(e){return zd(BigInt(e),32).forEach(r=>this.write8(r)),this}writeULEB(e){return Do(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 Vd(this.toBytes(),e)}};function zd(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 r_=t=>{throw TypeError(t)},n_=(t,e,r)=>e.has(t)||r_("Cannot "+r),yi=(t,e,r)=>(n_(t,e,"read from private field"),r?r.call(t):e.get(t)),zc=(t,e,r)=>e.has(t)?r_("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),Gc=(t,e,r,n)=>(n_(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),_a,_u,Vc,zs,MT=class i_{constructor(e){zc(this,_a),zc(this,_u),this.name=e.name,this.read=e.read,this.serializedSize=e.serializedSize??(()=>null),Gc(this,_a,e.write),Gc(this,_u,e.serialize??((r,n)=>{let i=new qc({initialSize:this.serializedSize(r)??void 0,...n});return yi(this,_a).call(this,r,i),i.toBytes()})),this.validate=e.validate??(()=>{})}write(e,r){this.validate(e),yi(this,_a).call(this,e,r)}serialize(e,r){return this.validate(e),new Hc(this,yi(this,_u).call(this,e,r))}parse(e){let r=new Fc(e);return this.read(r)}fromHex(e){return this.parse(qs(e))}fromBase58(e){return this.parse(En(e))}fromBase64(e){return this.parse(hr(e))}transform({name:e,input:r,output:n,validate:i}){return new i_({name:e??this.name,read:s=>n?n(this.read(s)):this.read(s),write:(s,o)=>yi(this,_a).call(this,r?r(s):s,o),serializedSize:s=>this.serializedSize(r?r(s):s),serialize:(s,o)=>yi(this,_u).call(this,r?r(s):s,o),validate:s=>{i?.(s),this.validate(r?r(s):s)}})}};_a=new WeakMap;_u=new WeakMap;var Un=MT,s_=Symbol.for("@mysten/serialized-bcs");function va(t){return!!t&&typeof t=="object"&&t[s_]===!0}var Hc=class{constructor(e,r){zc(this,Vc),zc(this,zs),Gc(this,Vc,e),Gc(this,zs,r)}get[s_](){return!0}toBytes(){return yi(this,zs)}toHex(){return cn(yi(this,zs))}toBase64(){return Qt(yi(this,zs))}toBase58(){return gi(yi(this,zs))}parse(){return yi(this,Vc).parse(yi(this,zs))}};Vc=new WeakMap;zs=new WeakMap;function vu({size:t,...e}){return new Un({...e,serializedSize:()=>t})}function Wc({readMethod:t,writeMethod:e,...r}){return vu({...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 Kc({readMethod:t,writeMethod:e,...r}){return vu({...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 o_({serialize:t,...e}){let r=new Un({...e,serialize:t,write:(n,i)=>{for(let s of r.serialize(n).toBytes())i.write8(s)}});return r}function a_({toBytes:t,fromBytes:e,...r}){return new Un({...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=Do(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 u_(t){let e=null;function r(){return e||(e=t()),e}return new Un({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 Wc({name:"u8",readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...t})},u16(t){return Wc({name:"u16",readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...t})},u32(t){return Wc({name:"u32",readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...t})},u64(t){return Kc({name:"u64",readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...t})},u128(t){return Kc({name:"u128",readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...t})},u256(t){return Kc({name:"u256",readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...t})},bool(t){return vu({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 o_({name:"uleb128",read:e=>e.readULEB(),serialize:e=>Uint8Array.from(Do(e)),...t})},bytes(t,e){return vu({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 Un({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:Do(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 a_({name:"string",toBytes:e=>new TextEncoder().encode(e),fromBytes:e=>new TextDecoder().decode(e),...t})},fixedArray(t,e,r){return new Un({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 Un({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 Un({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 Un({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 Un({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 u_(t)}};var ds=cn;var c_=/^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i,l_=/^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i;function f_(t){return t.length>235?!1:t.includes("@")?c_.test(t):l_.test(t)}function d_(t,e="at"){let r=t.toLowerCase(),n;if(r.includes("@")){if(!c_.test(r))throw new Error(`Invalid SuiNS name ${t}`);let[i,s]=r.split("@");n=[...i?i.split("."):[],s]}else{if(!l_.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 ST=/^([a-z0-9]+(?:-[a-z0-9]+)*)$/,kT=/^\d+$/,OT=64,h_="/",Wr=t=>{let e=t.split(h_);if(e.length<2||e.length>3)return!1;let[r,n,i]=e;return i!==void 0&&!kT.test(i)||!f_(r)?!1:ST.test(n)&&n.length<OT},p_=t=>{let e=t.split(/::|<|>|,/);for(let r of e)if(r.includes(h_)&&!Wr(r))return!1;return!0};var ET=32;function Xc(t){try{return En(t).length===ET}catch{return!1}}var Bo=32;function Kr(t){return IT(t)&&TT(t)===Bo}function Gs(t){return Kr(t)}function AT(t){return t.includes("::")?Li(t):t}function Li(t){let[e,r]=t.split("::"),n=Wr(e),i=t.slice(e.length+r.length+4),s=i.includes("<")?i.slice(0,i.indexOf("<")):i,o=i.includes("<")?yu(i.slice(i.indexOf("<")+1,i.lastIndexOf(">"))).map(u=>AT(u.trim())):[];return{address:n?e:Ve(e),module:r,name:s,typeParams:o}}function Ro(t){let{address:e,module:r,name:n,typeParams:i}=typeof t=="string"?Li(t):t,s=i?.length>0?`<${i.map(o=>typeof o=="string"?o:Ro(o)).join(",")}>`:"";return`${e}::${r}::${n}${s}`}function Ve(t,e=!1){let r=t.toLowerCase();return!e&&r.startsWith("0x")&&(r=r.slice(2)),`0x${r.padStart(Bo*2,"0")}`}function Nr(t,e=!1){return Ve(t,e)}function IT(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2===0}function TT(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}var xT=BigInt(1e9),Gd="0x1",Jc="0x2";var PT=Nr("0x6");var Hd=`${Jc}::sui::SUI`,Zc=Nr("0x5");function CT(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Qc(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function el(t,...e){if(!CT(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 Wd(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 m_(t,e){el(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function bu(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function tl(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}var g_=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function y_(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}var $i=g_?t=>t:t=>y_(t);function jT(t){for(let e=0;e<t.length;e++)t[e]=y_(t[e]);return t}var Uo=g_?t=>t:jT;function NT(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function ba(t){return typeof t=="string"&&(t=NT(t)),el(t),t}var Yc=class{};function __(t){let e=(n,i)=>t(i).update(ba(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var v_=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 rl=BigInt(4294967295),b_=BigInt(32);function w_(t,e=!1){return e?{h:Number(t&rl),l:Number(t>>b_&rl)}:{h:Number(t>>b_&rl)|0,l:Number(t&rl)|0}}var Kd=(t,e,r)=>t>>>r|e<<32-r,Xd=(t,e,r)=>t<<32-r|e>>>r,M_=(t,e,r)=>t<<64-r|e>>>r-32,S_=(t,e,r)=>t>>>r-32|e<<64-r,k_=(t,e)=>e,O_=(t,e)=>t;function Jd(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var Zd=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Yd=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;var Mr=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Oe=new Uint32Array(32);function Hs(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Oe[2*t],d=Oe[2*t+1],p=Oe[2*e],_=Oe[2*e+1],b=Oe[2*r],O=Oe[2*r+1],T=Oe[2*n],x=Oe[2*n+1],F=Zd(c,p,o);d=Yd(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:k_(x,T),Dl:O_(x,T)},{h:O,l:b}=Jd(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:Kd(_,p,24),Bl:Xd(_,p,24)},Oe[2*t]=c,Oe[2*t+1]=d,Oe[2*e]=p,Oe[2*e+1]=_,Oe[2*r]=b,Oe[2*r+1]=O,Oe[2*n]=T,Oe[2*n+1]=x}function Ws(t,e,r,n,i,s){let o=i[s],u=i[s+1],c=Oe[2*t],d=Oe[2*t+1],p=Oe[2*e],_=Oe[2*e+1],b=Oe[2*r],O=Oe[2*r+1],T=Oe[2*n],x=Oe[2*n+1],F=Zd(c,p,o);d=Yd(F,d,_,u),c=F|0,{Dh:x,Dl:T}={Dh:x^d,Dl:T^c},{Dh:x,Dl:T}={Dh:Kd(x,T,16),Dl:Xd(x,T,16)},{h:O,l:b}=Jd(O,b,x,T),{Bh:_,Bl:p}={Bh:_^O,Bl:p^b},{Bh:_,Bl:p}={Bh:M_(_,p,63),Bl:S_(_,p,63)},Oe[2*t]=c,Oe[2*t+1]=d,Oe[2*e]=p,Oe[2*e+1]=_,Oe[2*r]=b,Oe[2*r+1]=O,Oe[2*n]=T,Oe[2*n+1]=x}function BT(t,e={},r,n,i){if(Qc(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 Qd=class extends Yc{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,Qc(e),Qc(r),this.blockLen=e,this.outputLen=r,this.buffer=new Uint8Array(e),this.buffer32=bu(this.buffer)}update(e){Wd(this),e=ba(e),el(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&&(Uo(i),this.compress(i,0,!1),Uo(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));Uo(_);for(let b=0;c+r<s;b+=i.length,c+=r)this.length+=r,this.compress(_,b,!1);Uo(_);continue}n.set(e.subarray(c,c+d),this.pos),this.pos+=d,this.length+=d,c+=d}return this}digestInto(e){Wd(this),m_(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,tl(this.buffer.subarray(r)),Uo(n),this.compress(n,0,!0),Uo(n);let i=bu(e);this.get().forEach((s,o)=>i[o]=$i(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()}},nl=class extends Qd{constructor(e={}){let r=e.dkLen===void 0?64:e.dkLen;super(128,r),this.v0l=Mr[0]|0,this.v0h=Mr[1]|0,this.v1l=Mr[2]|0,this.v1h=Mr[3]|0,this.v2l=Mr[4]|0,this.v2h=Mr[5]|0,this.v3l=Mr[6]|0,this.v3h=Mr[7]|0,this.v4l=Mr[8]|0,this.v4h=Mr[9]|0,this.v5l=Mr[10]|0,this.v5h=Mr[11]|0,this.v6l=Mr[12]|0,this.v6h=Mr[13]|0,this.v7l=Mr[14]|0,this.v7h=Mr[15]|0,BT(r,e,64,16,16);let{key:n,personalization:i,salt:s}=e,o=0;if(n!==void 0&&(n=ba(n),o=n.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=ba(s);let u=bu(s);this.v4l^=$i(u[0]),this.v4h^=$i(u[1]),this.v5l^=$i(u[2]),this.v5h^=$i(u[3])}if(i!==void 0){i=ba(i);let u=bu(i);this.v6l^=$i(u[0]),this.v6h^=$i(u[1]),this.v7l^=$i(u[2]),this.v7h^=$i(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)=>Oe[d]=c),Oe.set(Mr,16);let{h:i,l:s}=w_(BigInt(this.length));Oe[24]=Mr[8]^s,Oe[25]=Mr[9]^i,n&&(Oe[28]=~Oe[28],Oe[29]=~Oe[29]);let o=0,u=v_;for(let c=0;c<12;c++)Hs(0,4,8,12,e,r+2*u[o++]),Ws(0,4,8,12,e,r+2*u[o++]),Hs(1,5,9,13,e,r+2*u[o++]),Ws(1,5,9,13,e,r+2*u[o++]),Hs(2,6,10,14,e,r+2*u[o++]),Ws(2,6,10,14,e,r+2*u[o++]),Hs(3,7,11,15,e,r+2*u[o++]),Ws(3,7,11,15,e,r+2*u[o++]),Hs(0,5,10,15,e,r+2*u[o++]),Ws(0,5,10,15,e,r+2*u[o++]),Hs(1,6,11,12,e,r+2*u[o++]),Ws(1,6,11,12,e,r+2*u[o++]),Hs(2,7,8,13,e,r+2*u[o++]),Ws(2,7,8,13,e,r+2*u[o++]),Hs(3,4,9,14,e,r+2*u[o++]),Ws(3,4,9,14,e,r+2*u[o++]);this.v0l^=Oe[0]^Oe[16],this.v0h^=Oe[1]^Oe[17],this.v1l^=Oe[2]^Oe[18],this.v1h^=Oe[3]^Oe[19],this.v2l^=Oe[4]^Oe[20],this.v2h^=Oe[5]^Oe[21],this.v3l^=Oe[6]^Oe[22],this.v3h^=Oe[7]^Oe[23],this.v4l^=Oe[8]^Oe[24],this.v4h^=Oe[9]^Oe[25],this.v5l^=Oe[10]^Oe[26],this.v5h^=Oe[11]^Oe[27],this.v6l^=Oe[12]^Oe[28],this.v6h^=Oe[13]^Oe[29],this.v7l^=Oe[14]^Oe[30],this.v7h^=Oe[15]^Oe[31],tl(Oe)}destroy(){this.destroyed=!0,tl(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},E_=__(t=>new nl(t));var il=E_;var RT=/^vector<(.+)>$/,UT=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/,_i=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(RT);if(n)return{vector:t.parseFromStr(n[1],r)};let i=e.match(UT);if(i)return{struct:{address:r?Ve(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 yu(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 LT(t){return B.u64({name:"unsafe_u64",...t}).transform({input:e=>e,output:e=>Number(e)})}function $T(t){return B.enum("Option",{None:null,Some:t})}var Rt=B.bytes(Bo).transform({validate:t=>{let e=typeof t=="string"?t:cn(t);if(!e||!Kr(Ve(e)))throw new Error(`Invalid Sui address ${e}`)},input:t=>typeof t=="string"?qs(Ve(t)):t,output:t=>Ve(cn(t))}),An=B.vector(B.u8()).transform({name:"ObjectDigest",input:t=>En(t),output:t=>gi(new Uint8Array(t)),validate:t=>{if(En(t).length!==32)throw new Error("ObjectDigest must be 32 bytes")}}),vn=B.struct("SuiObjectRef",{objectId:Rt,version:B.u64(),digest:An}),eh=B.struct("SharedObjectRef",{objectId:Rt,initialSharedVersion:B.u64(),mutable:B.bool()}),th=B.enum("ObjectArg",{ImmOrOwnedObject:vn,SharedObject:eh,Receiving:vn}),hs=B.enum("Owner",{AddressOwner:Rt,ObjectOwner:Rt,Shared:B.struct("Shared",{initialSharedVersion:B.u64()}),Immutable:null,ConsensusV2:B.struct("ConsensusV2",{authenticator:B.enum("Authenticator",{SingleOwner:Rt}),startVersion:B.u64()})}),rh=B.enum("CallArg",{Pure:B.struct("Pure",{bytes:B.vector(B.u8()).transform({input:t=>typeof t=="string"?hr(t):t,output:t=>Qt(new Uint8Array(t))})}),Object:th}),nh=B.enum("TypeTag",{bool:null,u8:null,u64:null,u128:null,address:null,signer:null,vector:B.lazy(()=>nh),struct:B.lazy(()=>ch),u16:null,u32:null,u256:null}),sl=nh.transform({input:t=>typeof t=="string"?_i.parseFromStr(t,!0):t,output:t=>_i.tagToString(t)}),vi=B.enum("Argument",{GasCoin:null,Input:B.u16(),Result:B.u16(),NestedResult:B.tuple([B.u16(),B.u16()])}),ih=B.struct("ProgrammableMoveCall",{package:Rt,module:B.string(),function:B.string(),typeArguments:B.vector(sl),arguments:B.vector(vi)}),sh=B.enum("Command",{MoveCall:ih,TransferObjects:B.struct("TransferObjects",{objects:B.vector(vi),address:vi}),SplitCoins:B.struct("SplitCoins",{coin:vi,amounts:B.vector(vi)}),MergeCoins:B.struct("MergeCoins",{destination:vi,sources:B.vector(vi)}),Publish:B.struct("Publish",{modules:B.vector(B.vector(B.u8()).transform({input:t=>typeof t=="string"?hr(t):t,output:t=>Qt(new Uint8Array(t))})),dependencies:B.vector(Rt)}),MakeMoveVec:B.struct("MakeMoveVec",{type:$T(sl).transform({input:t=>t===null?{None:!0}:{Some:t},output:t=>t.Some??null}),elements:B.vector(vi)}),Upgrade:B.struct("Upgrade",{modules:B.vector(B.vector(B.u8()).transform({input:t=>typeof t=="string"?hr(t):t,output:t=>Qt(new Uint8Array(t))})),dependencies:B.vector(Rt),package:Rt,ticket:vi})}),oh=B.struct("ProgrammableTransaction",{inputs:B.vector(rh),commands:B.vector(sh)}),ah=B.enum("TransactionKind",{ProgrammableTransaction:oh,ChangeEpoch:null,Genesis:null,ConsensusCommitPrologue:null}),uh=B.enum("TransactionExpiration",{None:null,Epoch:LT()}),ch=B.struct("StructTag",{address:Rt,module:B.string(),name:B.string(),typeParams:B.vector(nh)}),lh=B.struct("GasData",{payment:B.vector(vn),owner:Rt,price:B.u64(),budget:B.u64()}),fh=B.struct("TransactionDataV1",{kind:ah,sender:Rt,gasData:lh,expiration:uh}),dh=B.enum("TransactionData",{V1:fh}),hh=B.enum("IntentScope",{TransactionData:null,TransactionEffects:null,CheckpointSummary:null,PersonalMessage:null}),ph=B.enum("IntentVersion",{V0:null}),mh=B.enum("AppId",{Sui:null}),gh=B.struct("Intent",{scope:hh,version:ph,appId:mh});function yh(t){return B.struct(`IntentMessage<${t.name}>`,{intent:gh,value:t})}var _h=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())}),vh=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())}),bh=B.struct("MultiSigPkMap",{pubKey:vh,weight:B.u8()}),wh=B.struct("MultiSigPublicKey",{pk_map:B.vector(bh),threshold:B.u16()}),A_=B.struct("MultiSig",{sigs:B.vector(_h),bitmap:B.u16(),multisig_pk:wh}),FT=B.vector(B.u8()).transform({input:t=>typeof t=="string"?hr(t):t,output:t=>Qt(new Uint8Array(t))}),Mh=B.struct("SenderSignedTransaction",{intentMessage:yh(dh),txSignatures:B.vector(FT)}),I_=B.vector(Mh,{name:"SenderSignedData"}),T_=B.struct("PasskeyAuthenticator",{authenticatorData:B.vector(B.u8()),clientDataJson:B.string(),userSignature:B.vector(B.u8())});var qT=B.enum("PackageUpgradeError",{UnableToFetchPackage:B.struct("UnableToFetchPackage",{packageId:Rt}),NotAPackage:B.struct("NotAPackage",{objectId:Rt}),IncompatibleUpgrade:null,DigestDoesNotMatch:B.struct("DigestDoesNotMatch",{digest:B.vector(B.u8())}),UnknownUpgradePolicy:B.struct("UnknownUpgradePolicy",{policy:B.u8()}),PackageIDDoesNotMatch:B.struct("PackageIDDoesNotMatch",{packageId:Rt,ticketId:Rt})}),VT=B.struct("ModuleId",{address:Rt,name:B.string()}),x_=B.struct("MoveLocation",{module:VT,function:B.u16(),instruction:B.u16(),functionName:B.option(B.string())}),zT=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}),GT=B.enum("TypeArgumentError",{TypeNotFound:null,ConstraintNotSatisfied:null}),HT=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:Rt}),InsufficientCoinBalance:null,CoinBalanceOverflow:null,PublishErrorNonZeroAddress:null,SuiMoveVerificationError:null,MovePrimitiveRuntimeError:B.option(x_),MoveAbort:B.tuple([x_,B.u64()]),VMVerificationOrDeserializationError:null,VMInvariantViolation:null,FunctionNotFound:null,ArityMismatch:null,TypeArityMismatch:null,NonEntryFunctionInvoked:null,CommandArgumentError:B.struct("CommandArgumentError",{argIdx:B.u16(),kind:zT}),TypeArgumentError:B.struct("TypeArgumentError",{argumentIdx:B.u16(),kind:GT}),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:qT}),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(Rt)}),AddressDeniedForCoin:B.struct("AddressDeniedForCoin",{address:Rt,coinType:B.string()}),CoinTypeGlobalPause:B.struct("CoinTypeGlobalPause",{coinType:B.string()}),ExecutionCancelledDueToRandomnessUnavailable:null}),P_=B.enum("ExecutionStatus",{Success:null,Failed:B.struct("ExecutionFailed",{error:HT,command:B.option(B.u64())})}),C_=B.struct("GasCostSummary",{computationCost:B.u64(),storageCost:B.u64(),storageRebate:B.u64(),nonRefundableStorageFee:B.u64()}),WT=B.struct("TransactionEffectsV1",{status:P_,executedEpoch:B.u64(),gasUsed:C_,modifiedAtVersions:B.vector(B.tuple([Rt,B.u64()])),sharedObjects:B.vector(vn),transactionDigest:An,created:B.vector(B.tuple([vn,hs])),mutated:B.vector(B.tuple([vn,hs])),unwrapped:B.vector(B.tuple([vn,hs])),deleted:B.vector(vn),unwrappedThenDeleted:B.vector(vn),wrapped:B.vector(vn),gasObject:B.tuple([vn,hs]),eventsDigest:B.option(An),dependencies:B.vector(An)}),Sh=B.tuple([B.u64(),An]),KT=B.enum("ObjectIn",{NotExist:null,Exist:B.tuple([Sh,hs])}),XT=B.enum("ObjectOut",{NotExist:null,ObjectWrite:B.tuple([An,hs]),PackageWrite:Sh}),JT=B.enum("IDOperation",{None:null,Created:null,Deleted:null}),ZT=B.struct("EffectsObjectChange",{inputState:KT,outputState:XT,idOperation:JT}),YT=B.enum("UnchangedSharedKind",{ReadOnlyRoot:Sh,MutateDeleted:B.u64(),ReadDeleted:B.u64(),Cancelled:B.u64(),PerEpochConfig:null}),QT=B.struct("TransactionEffectsV2",{status:P_,executedEpoch:B.u64(),gasUsed:C_,transactionDigest:An,gasObjectIndex:B.option(B.u32()),eventsDigest:B.option(An),dependencies:B.vector(An),lamportVersion:B.u64(),changedObjects:B.vector(B.tuple([Rt,ZT])),unchangedSharedObjects:B.vector(B.tuple([Rt,YT])),auxDataDigest:B.option(An)}),j_=B.enum("TransactionEffects",{V1:WT,V2:QT});function wa(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 Rt}let e=t.match(/^(vector|option)<(.+)>$/);if(e){let[r,n]=e.slice(1);return r==="vector"?B.vector(wa(n)):B.option(wa(n))}throw new Error(`Invalid Pure type name: ${t}`)}var it={...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:Rt,AppId:mh,Argument:vi,CallArg:rh,Command:sh,CompressedSignature:_h,GasData:lh,Intent:gh,IntentMessage:yh,IntentScope:hh,IntentVersion:ph,MultiSig:A_,MultiSigPkMap:bh,MultiSigPublicKey:wh,ObjectArg:th,ObjectDigest:An,Owner:hs,PasskeyAuthenticator:T_,ProgrammableMoveCall:ih,ProgrammableTransaction:oh,PublicKey:vh,SenderSignedData:I_,SenderSignedTransaction:Mh,SharedObjectRef:eh,StructTag:ch,SuiObjectRef:vn,TransactionData:dh,TransactionDataV1:fh,TransactionEffects:j_,TransactionExpiration:uh,TransactionKind:ah,TypeTag:sl};function N_(t,e,r){let n=it.Address.serialize(t).toBytes(),i=it.TypeTag.serialize(e).toBytes(),s=it.u64().serialize(r.length).toBytes(),o=il.create({dkLen:32});return o.update(new Uint8Array([240])),o.update(n),o.update(s),o.update(r),o.update(i),`0x${cn(o.digest().slice(0,32))}`}var ol=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(pe=>pe.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=(0,ar.getFilteredRewards)(d);Gy(c,o,p,this.sdk);let _=(0,ar.getStakingYieldAprPercent)(c,o.coinType,i),b=c===ar.Side.DEPOSIT?o.depositAprPercent:o.borrowAprPercent,O=b,T=Hy(o,c,r);O=c===ar.Side.DEPOSIT?zy(T):Dd(T);let{multiplier:x,isValid:F}=Wy(c,o,T),R=(0,ar.getDedupedPerDayRewards)(p),H=(0,ar.getDedupedAprRewards)(p),{newPerDayRewards:J,newAprRewards:ee}=Ky(R,H,x,F),ae=(0,ar.getTotalAprPercent)(c,b,p,_),te=O===void 0||ee.some(pe=>pe.stats.aprPercent===void 0)?void 0:(0,ar.getTotalAprPercent)(c,O,ee,_);return{borrowLimit:o.config.borrowLimit.toString(),borrowedAmount:o.borrowedAmount.toString(),remainingBorrowLimit:(0,Xr.d)(o.config.borrowLimit.toString()).sub((0,Xr.d)(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}=(0,Xr.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(r,n)).createObligation(e)};this.refreshReservePrices=async(e,r,n)=>{let{lendingMarketId:i,lendingMarketType:s}=(0,Xr.getPackagerConfigs)(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}=(0,Xr.getPackagerConfigs)(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=>ds(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=(0,Xr.d)(b).mul((0,Xr.d)(10).pow((0,Xr.d)(O))).toString(),x={coin_type:_.coinType.name,price:T,oracle_price:0n,last_update_time:p.publishTime};x.oracle_price=Xy(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}=(0,Xr.getPackagerConfigs)(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==(0,Xr.removeHexPrefix)(e)||c.coinType.name==(0,Xr.removeHexPrefix)(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 D_.SuilendClient.initialize(e,r,this.sdk.FullClient,!0)),this.suilendClientCache[n]}async getLendingMarketData(e=!1){if(!e&&this.lendingMarketCache)return this.lendingMarketCache;let r=(0,Xr.getPackagerConfigs)(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(0,ar.initializeSuilend)(this.sdk.FullClient,u),{rewardPriceMap:R}=await(0,ar.initializeSuilendRewards)(_,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 Ri(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(0,ar.initializeObligations)(this.sdk.FullClient,i.suilendClient,i.refreshedRawReserves,i.reserveMap,this.sdk.senderAddress),u=(0,ar.formatRewards)(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}=(0,Xr.getPackagerConfigs)(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=(0,ar.getNetAprPercent)(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}};var he=require("@cetusprotocol/common-sdk");var Ma=9e15,Zs=1e9,kh="0123456789abcdef",cl="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ll="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Oh={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ma,maxE:Ma,crypto:!1},L_,ps,ct=!0,dl="[DecimalError] ",Js=dl+"Invalid argument: ",$_=dl+"Precision limit exceeded",F_=dl+"crypto unavailable",q_="[object Decimal]",Jr=Math.floor,Sr=Math.pow,ex=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,tx=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,rx=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,V_=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,bi=1e7,et=7,nx=9007199254740991,ix=cl.length-1,Eh=ll.length-1,le={toStringTag:q_};le.absoluteValue=le.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),We(t)};le.ceil=function(){return We(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(Js+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())+et,n.rounding=1,r=sx(n,K_(n,r)),n.precision=t,n.rounding=e,We(ps==2||ps==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(ct=!1,s=p.s*Sr(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Ur(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=Sr(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=$t(d.plus(p).times(u),d.plus(c),o+2,1),Ur(u.d).slice(0,o)===(r=Ur(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(We(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")&&(We(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return ct=!0,We(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-Jr(this.e/et))*et,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};le.dividedBy=le.div=function(t){return $t(this,new this.constructor(t))};le.dividedToIntegerBy=le.divToInt=function(t){var e=this,r=e.constructor;return We($t(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 We(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/pl(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=Sa(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 We(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=Sa(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/pl(5,t)),i=Sa(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,We(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,$t(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()?Fi(e,n,i):new e(0):new e(NaN):t.isZero()?Fi(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,ct=!1,r=r.times(r).minus(1).sqrt().plus(r),ct=!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,ct=!1,r=r.times(r).plus(1).sqrt().plus(r),ct=!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?We(new s(i),t,e,!0):(s.precision=r=n-i.e,i=$t(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=Fi(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<=Eh)return o=Fi(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=Eh)return o=Fi(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/et+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(ct=!1,e=Math.ceil(u/et),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)),ct=!0,We(o,p.precision=_,p.rounding=b,!0)};le.isFinite=function(){return!!this.d};le.isInteger=le.isInt=function(){return!!this.d&&Jr(this.e/et)>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(ct=!1,u=_+O,o=Xs(d,u),n=e?fl(p,u+10):Xs(t,u),c=$t(o,n,u,1),wu(c.d,i=_,b))do if(u+=10,o=Xs(d,u),n=e?fl(p,u+10):Xs(t,u),c=$t(o,n,u,1),!s){+Ur(c.d).slice(i+1,i+15)+1==1e14&&(c=We(c,_+1,0));break}while(wu(c.d,i+=10,b));return ct=!0,We(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 ct?We(t,u,c):t}if(r=Jr(t.e/et),p=Jr(O.e/et),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/et),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]=bi-1;--d[i],d[n]+=bi}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=hl(d,r),ct?We(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]?We(new n(r),n.precision,n.rounding):(ct=!1,n.modulo==9?(e=$t(r,t.abs(),0,3,1),e.s*=t.s):e=$t(r,t,0,n.modulo,1),e=e.times(t),ct=!0,r.minus(e))};le.naturalExponential=le.exp=function(){return Ah(this)};le.naturalLogarithm=le.ln=function(){return Xs(this)};le.negated=le.neg=function(){var t=new this.constructor(this);return t.s=-t.s,We(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(_)),ct?We(t,u,c):t;if(s=Jr(_.e/et),n=Jr(t.e/et),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/et),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)/bi|0,d[i]%=bi;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=hl(d,n),ct?We(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(Js+t);return r.d?(e=z_(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};le.round=function(){var t=this,e=t.constructor;return We(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())+et,n.rounding=1,r=ax(n,K_(n,r)),n.precision=t,n.rounding=e,We(ps>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(ct=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Ur(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($t(o,s,r+2,1)).times(.5),Ur(s.d).slice(0,r)===(e=Ur(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(We(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")&&(We(n,c+1,1),t=!n.times(n).eq(o));break}return ct=!0,We(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=$t(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,We(ps==2||ps==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=Jr(p.e/et)+Jr(t.e/et),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%bi|0,e=u/bi|0;s[i]=(s[i]+e)%bi|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=hl(s,r),ct?We(t,_.precision,_.rounding):t};le.toBinary=function(t,e){return Ih(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:(bn(t,0,Zs),e===void 0?e=n.rounding:bn(e,0,8),We(r,t+r.e+1,e))};le.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=qi(n,!0):(bn(t,0,Zs),e===void 0?e=i.rounding:bn(e,0,8),n=We(new i(n),t+1,e),r=qi(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=qi(i):(bn(t,0,Zs),e===void 0?e=s.rounding:bn(e,0,8),n=We(new s(i),t+i.e+1,e),r=qi(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=z_(T)-O.e-1,o=s%et,e.d[0]=Sr(10,o<0?et+o:o),t==null)t=s>0?e:d;else{if(u=new x(t),!u.isInt()||u.lt(d))throw Error(Js+u);t=u.gt(e)?s>0?e:d:u}for(ct=!1,u=new x(Ur(T)),p=x.precision,x.precision=s=T.length*et*2;_=$t(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=$t(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=$t(d,n,s,1).minus(O).abs().cmp($t(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,ct=!0,b};le.toHexadecimal=le.toHex=function(t,e){return Ih(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:bn(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]?(ct=!1,r=$t(r,t,0,e,1).times(t),ct=!0,We(r)):(t.s=r.s,r=t),r};le.toNumber=function(){return+this};le.toOctal=function(t,e){return Ih(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(Sr(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return We(u,n,s);if(e=Jr(t.e/et),e>=t.d.length-1&&(r=d<0?-d:d)<=nx)return i=G_(c,u,r,n),t.s<0?new c(1).div(i):We(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=Sr(+u,d),e=r==0||!isFinite(r)?Jr(d*(Math.log("0."+Ur(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):(ct=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=Ah(t.times(Xs(u,n+r)),n),i.d&&(i=We(i,n+5,1),wu(i.d,n,s)&&(e=n+10,i=We(Ah(t.times(Xs(u,e+r)),e),e+5,1),+Ur(i.d).slice(n+1,n+15)+1==1e14&&(i=We(i,n+1,0)))),i.s=o,ct=!0,c.rounding=s,We(i,n,s))};le.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=qi(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(bn(t,1,Zs),e===void 0?e=i.rounding:bn(e,0,8),n=We(new i(n),t,e),r=qi(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):(bn(t,1,Zs),e===void 0?e=n.rounding:bn(e,0,8)),We(new n(r),t,e)};le.toString=function(){var t=this,e=t.constructor,r=qi(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};le.truncated=le.trunc=function(){return We(new this.constructor(this),this.e+1,1)};le.valueOf=le.toJSON=function(){var t=this,e=t.constructor,r=qi(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Ur(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=et-n.length,r&&(s+=Ks(r)),s+=n;o=t[e],n=o+"",r=et-n.length,r&&(s+=Ks(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function bn(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Js+t)}function wu(t,e,r,n){var i,s,o,u;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=et,i=0):(i=Math.ceil((e+1)/et),e%=et),s=Sr(10,et-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)==Sr(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)==Sr(10,e-3)-1,o}function al(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]+=kh.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 sx(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/pl(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=Sa(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 $t=(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,pe,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=bi,O=et,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--;_++)pe=b*c+(a[_]||0),H[_]=pe/l|0,b=pe%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,L_=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,We(R,u?s+R.e+1:s,o,T)}return R}})();function We(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+=et,o=e,p=_[b=0],c=p/Sr(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/et),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=et,o=s-et+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=et,o=s-et+i,c=o<0?0:p/Sr(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%Sr(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/Sr(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]=Sr(10,(et-e%et)%et),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=Sr(10,et-s),_[b]=o>0?(p/Sr(10,i-o)%Sr(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]==bi&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=bi)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return ct&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function qi(t,e,r){if(!t.isFinite())return W_(t);var n,i=t.e,s=Ur(t.d),o=s.length;return e?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+Ks(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):i<0?(s="0."+Ks(-i-1)+s,r&&(n=r-o)>0&&(s+=Ks(n))):i>=o?(s+=Ks(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+Ks(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=Ks(n))),s}function hl(t,e){var r=t[0];for(e*=et;r>=10;r/=10)e++;return e}function fl(t,e,r){if(e>ix)throw ct=!0,r&&(t.precision=r),Error($_);return We(new t(cl),e,1,!0)}function Fi(t,e,r){if(e>Eh)throw Error($_);return We(new t(ll),e,r,!0)}function z_(t){var e=t.length-1,r=e*et+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 Ks(t){for(var e="";t--;)e+="0";return e}function G_(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/et+4);for(ct=!1;;){if(r%2&&(s=s.times(e),R_(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),R_(e.d,o)}return ct=!0,s}function B_(t){return t.d[t.d.length-1]&1}function H_(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 Ah(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?(ct=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(Sr(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=We(s.times(t),c,1),r=r.times(++p),u=o.plus($t(s,r,c,1)),Ur(u.d).slice(0,c)===Ur(o.d).slice(0,c)){for(i=_;i--;)o=We(o.times(o),c,1);if(e==null)if(d<3&&wu(o.d,c-n,O,d))b.precision=c+=10,r=s=u=new b(1),p=0,d++;else return We(o,b.precision=T,O,ct=!0);else return b.precision=T,o}o=u}}function Xs(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?(ct=!1,p=J):p=e,R.precision=p+=T,r=Ur(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=Ur(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=fl(R,p+2,J).times(s+""),x=Xs(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?We(x,J,H,ct=!0):x;for(_=x,c=o=x=$t(x.minus(1),x.plus(1),p,1),b=We(x.times(x),p,1),i=3;;){if(o=We(o.times(b),p,1),d=c.plus($t(o,new R(i),p,1)),Ur(d.d).slice(0,p)===Ur(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus(fl(R,p+2,J).times(s+""))),c=$t(c,new R(O),p,1),e==null)if(wu(c.d,p-T,H,u))R.precision=p+=T,d=o=x=$t(_.minus(1),_.plus(1),p,1),b=We(x.times(x),p,1),i=u=1;else return We(c,R.precision=J,H,ct=!0);else return R.precision=J,c;c=d,i+=2}}function W_(t){return String(t.s*t.s/0)}function ul(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)%et,r<0&&(n+=et),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=et;n<i;)t.d.push(+e.slice(n,n+=et));e=e.slice(n),n=et-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),ct&&(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 ox(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),V_.test(e))return ul(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(tx.test(e))r=16,e=e.toLowerCase();else if(ex.test(e))r=2;else if(rx.test(e))r=8;else throw Error(Js+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=G_(n,new n(r),s,s*2)),d=al(e,r,bi),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=hl(d,p),t.d=d,ct=!1,o&&(t=$t(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?Sr(2,c):Mu.pow(2,c))),ct=!0,t)}function ax(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:Sa(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/pl(5,r)),e=Sa(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 Sa(t,e,r,n,i){var s,o,u,c,d=1,p=t.precision,_=Math.ceil(p/et);for(ct=!1,c=r.times(r),u=new t(n);;){if(o=$t(u.times(c),new t(e++*e++),p,1),u=i?n.plus(o):n.minus(o),n=$t(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 ct=!0,o.d.length=_+1,o}function pl(t,e){for(var r=t;--e;)r*=t;return r}function K_(t,e){var r,n=e.s<0,i=Fi(t,t.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return ps=n?4:1,e;if(r=e.divToInt(i),r.isZero())ps=n?3:2;else{if(e=e.minus(r.times(i)),e.lte(s))return ps=B_(r)?n?2:3:n?4:1,e;ps=B_(r)?n?1:4:n?3:2}return e.minus(i).abs()}function Ih(t,e,r,n){var i,s,o,u,c,d,p,_,b,O=t.constructor,T=r!==void 0;if(T?(bn(r,1,Zs),n===void 0?n=O.rounding:bn(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=W_(t);else{for(p=qi(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=al(qi(b),10,i),b.e=b.d.length),_=al(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=$t(t,b,r,n,0,i),_=t.d,s=t.e,d=L_),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+=kh.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(_=al(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=kh.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 R_(t,e){if(t.length>e)return t.length=e,!0}function ux(t){return new this(t).abs()}function cx(t){return new this(t).acos()}function lx(t){return new this(t).acosh()}function fx(t,e){return new this(t).plus(e)}function dx(t){return new this(t).asin()}function hx(t){return new this(t).asinh()}function px(t){return new this(t).atan()}function mx(t){return new this(t).atanh()}function gx(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=Fi(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?Fi(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=Fi(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan($t(t,e,s,1)),e=Fi(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan($t(t,e,s,1)),r}function yx(t){return new this(t).cbrt()}function _x(t){return We(t=new this(t),t.e+1,2)}function vx(t,e,r){return new this(t).clamp(e,r)}function bx(t){if(!t||typeof t!="object")throw Error(dl+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,Zs,"rounding",0,8,"toExpNeg",-Ma,0,"toExpPos",0,Ma,"maxE",0,Ma,"minE",-Ma,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=Oh[r]),(n=t[r])!==void 0)if(Jr(n)===n&&n>=s[e+1]&&n<=s[e+2])this[r]=n;else throw Error(Js+r+": "+n);if(r="crypto",i&&(this[r]=Oh[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(F_);else this[r]=!1;else throw Error(Js+r+": "+n);return this}function wx(t){return new this(t).cos()}function Mx(t){return new this(t).cosh()}function X_(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,U_(s)){d.s=s.s,ct?!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++;ct?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 ul(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),V_.test(s)?ul(d,s):ox(d,s);if(c==="bigint")return s<0?(s=-s,d.s=-1):d.s=1,ul(d,s.toString());throw Error(Js+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=bx,i.clone=X_,i.isDecimal=U_,i.abs=ux,i.acos=cx,i.acosh=lx,i.add=fx,i.asin=dx,i.asinh=hx,i.atan=px,i.atanh=mx,i.atan2=gx,i.cbrt=yx,i.ceil=_x,i.clamp=vx,i.cos=wx,i.cosh=Mx,i.div=Sx,i.exp=kx,i.floor=Ox,i.hypot=Ex,i.ln=Ax,i.log=Ix,i.log10=xx,i.log2=Tx,i.max=Px,i.min=Cx,i.mod=jx,i.mul=Nx,i.pow=Dx,i.random=Bx,i.round=Rx,i.sign=Ux,i.sin=Lx,i.sinh=$x,i.sqrt=Fx,i.sub=qx,i.sum=Vx,i.tan=zx,i.tanh=Gx,i.trunc=Hx,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 Sx(t,e){return new this(t).div(e)}function kx(t){return new this(t).exp()}function Ox(t){return We(t=new this(t),t.e+1,3)}function Ex(){var t,e,r=new this(0);for(ct=!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 ct=!0,new this(1/0);r=e}return ct=!0,r.sqrt()}function U_(t){return t instanceof Mu||t&&t.toStringTag===q_||!1}function Ax(t){return new this(t).ln()}function Ix(t,e){return new this(t).log(e)}function Tx(t){return new this(t).log(2)}function xx(t){return new this(t).log(10)}function Px(){return H_(this,arguments,-1)}function Cx(){return H_(this,arguments,1)}function jx(t,e){return new this(t).mod(e)}function Nx(t,e){return new this(t).mul(e)}function Dx(t,e){return new this(t).pow(e)}function Bx(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:bn(t,1,Zs),n=Math.ceil(t/et),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(F_);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=et,n&&t&&(i=Sr(10,et-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-=et)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<et&&(r-=et-n)}return o.e=r,o.d=u,o}function Rx(t){return We(t=new this(t),t.e+1,this.rounding)}function Ux(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Lx(t){return new this(t).sin()}function $x(t){return new this(t).sinh()}function Fx(t){return new this(t).sqrt()}function qx(t,e){return new this(t).sub(e)}function Vx(){var t=0,e=arguments,r=new this(e[t]);for(ct=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return ct=!0,We(r,this.precision,this.rounding)}function zx(t){return new this(t).tan()}function Gx(t){return new this(t).tanh()}function Hx(t){return We(t=new this(t),t.e+1,1)}le[Symbol.for("nodejs.util.inspect.custom")]=le.toString;le[Symbol.toStringTag]="Decimal";var Mu=le.constructor=X_(Oh);cl=new Mu(cl);ll=new Mu(ll);var Vi=Mu;var tp=Nc(Z_());var Wx="object",Kx="ID",Xx="ascii",Jx="String",Zx="string",Yx="String",Qx="option",e3="Option";function Y_(t){let e=typeof t.body=="object"&&"datatype"in t.body?t.body.datatype:null;return!!e&&Ve(e.package)===Ve("0x2")&&e.module==="tx_context"&&e.type==="TxContext"}function ml(t){if(typeof t=="string")switch(t){case"address":return it.Address;case"bool":return it.Bool;case"u8":return it.U8;case"u16":return it.U16;case"u32":return it.U32;case"u64":return it.U64;case"u128":return it.U128;case"u256":return it.U256;default:throw new Error(`Unknown type signature ${t}`)}if("vector"in t){if(t.vector==="u8")return it.vector(it.U8).transform({input:r=>typeof r=="string"?new TextEncoder().encode(r):r,output:r=>r});let e=ml(t.vector);return e?it.vector(e):null}if("datatype"in t){let e=Ve(t.datatype.package);if(e===Ve(Gd)){if(t.datatype.module===Xx&&t.datatype.type===Jx)return it.String;if(t.datatype.module===Zx&&t.datatype.type===Yx)return it.String;if(t.datatype.module===Qx&&t.datatype.type===e3){let r=ml(t.datatype.typeParameters[0]);return r?it.vector(r):null}}if(e===Ve(Jc)&&t.datatype.module===Wx&&t.datatype.type===Kx)return it.Address}return null}function Q_(t){return typeof t=="object"&&"Reference"in t?{ref:"&",body:Su(t.Reference)}:typeof t=="object"&&"MutableReference"in t?{ref:"&mut",body:Su(t.MutableReference)}:{ref:null,body:Su(t)}}function Su(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:Su(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(Su)}};if("TypeParameter"in t)return{typeParameter:t.TypeParameter};throw new Error(`Unexpected type ${JSON.stringify(t)}`)}function t3(t){return{$kind:"Pure",Pure:{bytes:t instanceof Uint8Array?Qt(t):t.toBase64()}}}var Ln={Pure:t3,ObjectRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{digest:e,version:r,objectId:Ve(t)}}}},SharedObjectRef({objectId:t,mutable:e,initialSharedVersion:r}){return{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{mutable:e,initialSharedVersion:r,objectId:Ve(t)}}}},ReceivingRef({objectId:t,digest:e,version:r}){return{$kind:"Object",Object:{$kind:"Receiving",Receiving:{digest:e,version:r,objectId:Ve(t)}}}}};var xh;function r3(t){return{lang:t?.lang??xh?.lang,message:t?.message,abortEarly:t?.abortEarly??xh?.abortEarly,abortPipeEarly:t?.abortPipeEarly??xh?.abortPipeEarly}}var n3;function i3(t){return n3?.get(t)}var s3;function o3(t){return s3?.get(t)}var a3;function u3(t,e){return a3?.get(t)?.get(e)}function tv(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 In(t,e,r,n,i){let s=i&&"input"in i?i.input:r.value,o=i?.expected??t.expects??null,u=i?.received??tv(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??u3(t.reference,c.lang)??(d?o3(c.lang):null)??n.message??i3(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 c3(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}var l3=class extends Error{issues;constructor(t){super(t[0].message),this.name="ValiError",this.issues=t}};function Lo(t,e){return{kind:"validation",type:"check",reference:Lo,async:!1,expects:null,requirement:t,message:e,_run(r,n){return r.typed&&!this.requirement(r.value)&&In(this,"input",r,n),r}}}function or(t){return{kind:"validation",type:"integer",reference:or,async:!1,expects:null,requirement:Number.isInteger,message:t,_run(e,r){return e.typed&&!this.requirement(e.value)&&In(this,"integer",e,r),e}}}function ku(t){return{kind:"transformation",type:"transform",reference:ku,async:!1,operation:t,_run(e){return e.value=this.operation(e.value),e}}}function Ph(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function Ou(t,e){return!t._run({typed:!1,value:e},{abortEarly:!0}).issues}function Qe(t,e){return{kind:"schema",type:"array",reference:Qe,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 In(this,"type",r,n);return r}}}function gl(t){return{kind:"schema",type:"bigint",reference:gl,expects:"bigint",async:!1,message:t,_run(e,r){return typeof e.value=="bigint"?e.typed=!0:In(this,"type",e,r),e}}}function $o(t){return{kind:"schema",type:"boolean",reference:$o,expects:"boolean",async:!1,message:t,_run(e,r){return typeof e.value=="boolean"?e.typed=!0:In(this,"type",e,r),e}}}function Fo(t){return{kind:"schema",type:"lazy",reference:Fo,expects:"unknown",async:!1,getter:t,_run(e,r){return this.getter(e.value)._run(e,r)}}}function ot(t,e){return{kind:"schema",type:"literal",reference:ot,expects:tv(t),async:!1,literal:t,message:e,_run(r,n){return r.value===this.literal?r.typed=!0:In(this,"type",r,n),r}}}function xt(t,...e){let r={kind:"schema",type:"nullable",reference:xt,expects:`${t.expects} | null`,async:!1,wrapped:t,_run(n,i){return n.value===null&&("default"in this&&(n.value=Ph(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 ms(t,...e){let r={kind:"schema",type:"nullish",reference:ms,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=Ph(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 er(t){return{kind:"schema",type:"number",reference:er,expects:"number",async:!1,message:t,_run(e,r){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:In(this,"type",e,r),e}}}function Se(t,e){return{kind:"schema",type:"object",reference:Se,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 In(this,"type",r,n);return r}}}function _r(t,...e){let r={kind:"schema",type:"optional",reference:_r,expects:`${t.expects} | undefined`,async:!1,wrapped:t,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=Ph(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 qo(t,e,r){return{kind:"schema",type:"record",reference:qo,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(c3(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 In(this,"type",n,i);return n}}}function lt(t){return{kind:"schema",type:"string",reference:lt,expects:"string",async:!1,message:t,_run(e,r){return typeof e.value=="string"?e.typed=!0:In(this,"type",e,r),e}}}function Eu(t,e){return{kind:"schema",type:"tuple",reference:Eu,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 In(this,"type",r,n);return r}}}function ev(t){let e;if(t)for(let r of t)e?e.push(...r.issues):e=r.issues;return e}function vr(t,e){return{kind:"schema",type:"union",reference:vr,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];In(this,"type",r,n,{issues:ev(s)}),r.typed=!0}else{if(o?.length===1)return o[0];In(this,"type",r,n,{issues:ev(o)})}return r}}}function zi(){return{kind:"schema",type:"unknown",reference:zi,expects:"unknown",async:!1,_run(t){return t.typed=!0,t}}}function Ft(t,e,r){let n=t._run({typed:!1,value:e},r3(r));if(n.issues)throw new l3(n.issues);return n.value}function Bt(...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 Qs(t){let e=Object.entries(t).map(([r,n])=>Se({[r]:n}));return Bt(vr(e),ku(r=>({...r,$kind:Object.keys(r)[0]})))}var Vo=Bt(lt(),ku(t=>Ve(t)),Lo(Kr)),ln=Vo,Ys=lt(),Zr=Bt(vr([lt(),Bt(er(),or())]),Lo(t=>{try{return BigInt(t),BigInt(t)>=0&&BigInt(t)<=18446744073709551615n}catch{return!1}},"Invalid u64")),wi=Se({objectId:Vo,version:Zr,digest:lt()}),tr=Bt(vr([Se({GasCoin:ot(!0)}),Se({Input:Bt(er(),or()),type:_r(ot("pure"))}),Se({Input:Bt(er(),or()),type:_r(ot("object"))}),Se({Result:Bt(er(),or())}),Se({NestedResult:Eu([Bt(er(),or()),Bt(er(),or())])})]),ku(t=>({...t,$kind:Object.keys(t)[0]}))),f3=Se({budget:xt(Zr),price:xt(Zr),owner:xt(Vo),payment:xt(Qe(wi))}),SK=Se({address:lt(),module:lt(),name:lt(),typeParams:Qe(lt())}),Ch=vr([ot("address"),ot("bool"),ot("u8"),ot("u16"),ot("u32"),ot("u64"),ot("u128"),ot("u256"),Se({vector:Fo(()=>Ch)}),Se({datatype:Se({package:lt(),module:lt(),type:lt(),typeParameters:Qe(Fo(()=>Ch))})}),Se({typeParameter:Bt(er(),or())})]),d3=Se({ref:xt(vr([ot("&"),ot("&mut")])),body:Ch}),h3=Se({package:ln,module:lt(),function:lt(),typeArguments:Qe(lt()),arguments:Qe(tr),_argumentTypes:_r(xt(Qe(d3)))}),p3=Se({name:lt(),inputs:qo(lt(),vr([tr,Qe(tr)])),data:qo(lt(),zi())}),m3=Qs({MoveCall:h3,TransferObjects:Se({objects:Qe(tr),address:tr}),SplitCoins:Se({coin:tr,amounts:Qe(tr)}),MergeCoins:Se({destination:tr,sources:Qe(tr)}),Publish:Se({modules:Qe(Ys),dependencies:Qe(ln)}),MakeMoveVec:Se({type:xt(lt()),elements:Qe(tr)}),Upgrade:Se({modules:Qe(Ys),dependencies:Qe(ln),package:ln,ticket:tr}),$Intent:p3}),rv=Qs({ImmOrOwnedObject:wi,SharedObject:Se({objectId:ln,initialSharedVersion:Zr,mutable:$o()}),Receiving:wi}),g3=Qs({Object:rv,Pure:Se({bytes:Ys}),UnresolvedPure:Se({value:zi()}),UnresolvedObject:Se({objectId:ln,version:_r(xt(Zr)),digest:_r(xt(lt())),initialSharedVersion:_r(xt(Zr))})}),jh=Qs({Object:rv,Pure:Se({bytes:Ys})}),Nh=Qs({None:ot(!0),Epoch:Zr}),ka=Se({version:ot(2),sender:ms(Vo),expiration:ms(Nh),gasData:f3,inputs:Qe(g3),commands:Qe(m3)});var eo={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=>Ft(tr,r)),address:Ft(tr,e)}}},SplitCoins(t,e){return{$kind:"SplitCoins",SplitCoins:{coin:Ft(tr,t),amounts:e.map(r=>Ft(tr,r))}}},MergeCoins(t,e){return{$kind:"MergeCoins",MergeCoins:{destination:Ft(tr,t),sources:e.map(r=>Ft(tr,r))}}},Publish({modules:t,dependencies:e}){return{$kind:"Publish",Publish:{modules:t.map(r=>typeof r=="string"?r:Qt(new Uint8Array(r))),dependencies:e.map(r=>Nr(r))}}},Upgrade({modules:t,dependencies:e,package:r,ticket:n}){return{$kind:"Upgrade",Upgrade:{modules:t.map(i=>typeof i=="string"?i:Qt(new Uint8Array(i))),dependencies:e.map(i=>Nr(i)),package:r,ticket:Ft(tr,n)}}},MakeMoveVec({type:t,elements:e}){return{$kind:"MakeMoveVec",MakeMoveVec:{type:t??null,elements:e.map(r=>Ft(tr,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=>Ft(tr,s)):Ft(tr,i)])),data:r}}}};var Dh=Se({digest:lt(),objectId:lt(),version:vr([Bt(er(),or()),lt(),gl()])}),y3=Qs({ImmOrOwned:Dh,Shared:Se({objectId:ln,initialSharedVersion:Zr,mutable:$o()}),Receiving:Dh}),nv=Qs({Object:y3,Pure:Qe(Bt(er(),or()))}),sv=vr([Se({kind:ot("Input"),index:Bt(er(),or()),value:zi(),type:_r(ot("object"))}),Se({kind:ot("Input"),index:Bt(er(),or()),value:zi(),type:ot("pure")})]),_3=vr([Se({Epoch:Bt(er(),or())}),Se({None:xt(ot(!0))})]),iv=Bt(vr([er(),lt(),gl()]),Lo(t=>{if(!["string","number","bigint"].includes(typeof t))return!1;try{return BigInt(t),!0}catch{return!1}})),Bh=vr([Se({bool:xt(ot(!0))}),Se({u8:xt(ot(!0))}),Se({u64:xt(ot(!0))}),Se({u128:xt(ot(!0))}),Se({address:xt(ot(!0))}),Se({signer:xt(ot(!0))}),Se({vector:Fo(()=>Bh)}),Se({struct:Fo(()=>v3)}),Se({u16:xt(ot(!0))}),Se({u32:xt(ot(!0))}),Se({u256:xt(ot(!0))})]),v3=Se({address:lt(),module:lt(),name:lt(),typeParams:Qe(Bh)}),b3=Se({budget:_r(iv),price:_r(iv),payment:_r(Qe(Dh)),owner:_r(lt())}),w3=[sv,Se({kind:ot("GasCoin")}),Se({kind:ot("Result"),index:Bt(er(),or())}),Se({kind:ot("NestedResult"),index:Bt(er(),or()),resultIndex:Bt(er(),or())})],_s=vr([...w3]),M3=Se({kind:ot("MoveCall"),target:Bt(lt(),Lo(t=>t.split("::").length===3)),typeArguments:Qe(lt()),arguments:Qe(_s)}),S3=Se({kind:ot("TransferObjects"),objects:Qe(_s),address:_s}),k3=Se({kind:ot("SplitCoins"),coin:_s,amounts:Qe(_s)}),O3=Se({kind:ot("MergeCoins"),destination:_s,sources:Qe(_s)}),E3=Se({kind:ot("MakeMoveVec"),type:vr([Se({Some:Bh}),Se({None:xt(ot(!0))})]),objects:Qe(_s)}),A3=Se({kind:ot("Publish"),modules:Qe(Qe(Bt(er(),or()))),dependencies:Qe(lt())}),I3=Se({kind:ot("Upgrade"),modules:Qe(Qe(Bt(er(),or()))),dependencies:Qe(lt()),packageId:lt(),ticket:_s}),T3=[M3,S3,k3,O3,A3,I3,E3],x3=vr([...T3]),NK=Se({version:ot(1),sender:_r(lt()),expiration:ms(_3),gasConfig:b3,inputs:Qe(sv),transactions:Qe(x3)});function Rh(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(hr(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:_i.parseFromStr(r.MakeMoveVec.type)},objects:r.MakeMoveVec.elements.map(n=>gs(n,e))};if(r.MergeCoins)return{kind:"MergeCoins",destination:gs(r.MergeCoins.destination,e),sources:r.MergeCoins.sources.map(n=>gs(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=>gs(n,e))};if(r.Publish)return{kind:"Publish",modules:r.Publish.modules.map(n=>Array.from(hr(n))),dependencies:r.Publish.dependencies};if(r.SplitCoins)return{kind:"SplitCoins",coin:gs(r.SplitCoins.coin,e),amounts:r.SplitCoins.amounts.map(n=>gs(n,e))};if(r.TransferObjects)return{kind:"TransferObjects",objects:r.TransferObjects.objects.map(n=>gs(n,e)),address:gs(r.TransferObjects.address,e)};if(r.Upgrade)return{kind:"Upgrade",modules:r.Upgrade.modules.map(n=>Array.from(hr(n))),dependencies:r.Upgrade.dependencies,packageId:r.Upgrade.package,ticket:gs(r.Upgrade.ticket,e)};throw new Error(`Unknown transaction ${Object.keys(r)}`)})}}function gs(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 ov(t){return Ft(ka,{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(Ou(nv,e.value)){let r=Ft(nv,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:Qt(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?_i.tagToString(e.type.Some):null,elements:e.objects.map(r=>ys(r))}};case"MergeCoins":return{MergeCoins:{destination:ys(e.destination),sources:e.sources.map(r=>ys(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=>ys(s))}}}case"Publish":return{Publish:{modules:e.modules.map(r=>Qt(Uint8Array.from(r))),dependencies:e.dependencies}};case"SplitCoins":return{SplitCoins:{coin:ys(e.coin),amounts:e.amounts.map(r=>ys(r))}};case"TransferObjects":return{TransferObjects:{objects:e.objects.map(r=>ys(r)),address:ys(e.address)}};case"Upgrade":return{Upgrade:{modules:e.modules.map(r=>Qt(Uint8Array.from(r))),dependencies:e.dependencies,package:e.packageId,ticket:ys(e.ticket)}}}throw new Error(`Unknown transaction ${Object.keys(e)}`)})})}function ys(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 Au(t){return vr(Object.entries(t).map(([e,r])=>Se({[e]:r})))}var Mi=Au({GasCoin:ot(!0),Input:Bt(er(),or()),Result:Bt(er(),or()),NestedResult:Eu([Bt(er(),or()),Bt(er(),or())])}),P3=Se({budget:xt(Zr),price:xt(Zr),owner:xt(Vo),payment:xt(Qe(wi))}),C3=Se({package:ln,module:lt(),function:lt(),typeArguments:Qe(lt()),arguments:Qe(Mi)}),j3=Se({name:lt(),inputs:qo(lt(),vr([Mi,Qe(Mi)])),data:qo(lt(),zi())}),N3=Au({MoveCall:C3,TransferObjects:Se({objects:Qe(Mi),address:Mi}),SplitCoins:Se({coin:Mi,amounts:Qe(Mi)}),MergeCoins:Se({destination:Mi,sources:Qe(Mi)}),Publish:Se({modules:Qe(Ys),dependencies:Qe(ln)}),MakeMoveVec:Se({type:xt(lt()),elements:Qe(Mi)}),Upgrade:Se({modules:Qe(Ys),dependencies:Qe(ln),package:ln,ticket:Mi}),$Intent:j3}),D3=Au({ImmOrOwnedObject:wi,SharedObject:Se({objectId:ln,initialSharedVersion:Zr,mutable:$o()}),Receiving:wi}),B3=Au({Object:D3,Pure:Se({bytes:Ys}),UnresolvedPure:Se({value:zi()}),UnresolvedObject:Se({objectId:ln,version:_r(xt(Zr)),digest:_r(xt(lt())),initialSharedVersion:_r(xt(Zr))})}),R3=Au({None:ot(!0),Epoch:Zr}),av=Se({version:ot(2),sender:ms(Vo),expiration:ms(R3),gasData:P3,inputs:Qe(B3),commands:Qe(N3),digest:_r(xt(lt()))});var lv=t=>{throw TypeError(t)},fv=(t,e,r)=>e.has(t)||lv("Cannot "+r),Yr=(t,e,r)=>(fv(t,e,"read from private field"),r?r.call(t):e.get(t)),uv=(t,e,r)=>e.has(t)?lv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),cv=(t,e,r,n)=>(fv(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),zo,fn,U3=class dv{constructor({prefix:e,cache:r}={}){uv(this,zo),uv(this,fn),cv(this,zo,e??[]),cv(this,fn,r??new Map)}read(e,r){let n=[Yr(this,zo),...e].join(":");if(Yr(this,fn).has(n))return Yr(this,fn).get(n);let i=r();return Yr(this,fn).set(n,i),typeof i=="object"&&i!==null&&"then"in i?Promise.resolve(i).then(s=>(Yr(this,fn).set(n,s),s)).catch(s=>{throw Yr(this,fn).delete(n),s}):i}readSync(e,r){let n=[Yr(this,zo),...e].join(":");if(Yr(this,fn).has(n))return Yr(this,fn).get(n);let i=r();return Yr(this,fn).set(n,i),i}clear(e){let r=[...Yr(this,zo),...e??[]].join(":");if(!r){Yr(this,fn).clear();return}for(let n of Yr(this,fn).keys())n.startsWith(r)&&Yr(this,fn).delete(n)}scope(e){return new dv({prefix:[...Yr(this,zo),...Array.isArray(e)?e:[e]],cache:Yr(this,fn)})}};zo=new WeakMap;fn=new WeakMap;var yl=U3;var _l="1.34.0",hv="1.51.0";var mv=t=>{throw TypeError(t)},qh=(t,e,r)=>e.has(t)||mv("Cannot "+r),kr=(t,e,r)=>(qh(t,e,"read from private field"),r?r.call(t):e.get(t)),Iu=(t,e,r)=>e.has(t)?mv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),vl=(t,e,r,n)=>(qh(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),bl=(t,e,r)=>(qh(t,e,"access private method"),r),Tu,vs,xu,to,Gi,Uh,Lh,gv,yv,Vh,L3="/",$3={"Mvr-Source":`@mysten/sui@${_l}`},Oa=class{constructor({cache:e,url:r,pageSize:n=50,overrides:i}){Iu(this,Gi),Iu(this,Tu),Iu(this,vs),Iu(this,xu),Iu(this,to),vl(this,Tu,e),vl(this,vs,r),vl(this,xu,n),vl(this,to,{packages:i?.packages,types:i?.types}),F3(kr(this,to))}async resolvePackage({package:e}){return{package:await kr(this,Gi,Uh).load(e)}}async resolveType({type:e}){let r=[...$h(e)],n=await kr(this,Gi,Lh).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:Fh(e,i)}}async resolve({types:e=[],packages:r=[]}){let n=new Set;for(let p of e??[])$h(p,n);let i=[...n],[s,o]=await Promise.all([i.length>0?kr(this,Gi,Lh).loadMany(i):[],r.length>0?kr(this,Gi,Uh).loadMany(r):[]]),u={...kr(this,to)?.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 _=Fh(p,u);c[p]={type:_}}let d={};for(let[p,_]of(r??[]).entries()){let b=kr(this,to)?.packages?.[_]??o[p];if(b instanceof Error)throw b;d[_]={package:b}}return{types:c,packages:d}}};Tu=new WeakMap;vs=new WeakMap;xu=new WeakMap;to=new WeakMap;Gi=new WeakSet;Uh=function(){return kr(this,Tu).readSync(["#mvrPackageDataLoader",kr(this,vs)??""],()=>{let t=new ya(async r=>{if(!kr(this,vs))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await bl(this,Gi,gv).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve package: ${i}`))}),e=kr(this,to)?.packages;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};Lh=function(){return kr(this,Tu).readSync(["#mvrTypeDataLoader",kr(this,vs)??""],()=>{let t=new ya(async r=>{if(!kr(this,vs))throw new Error(`MVR Api URL is not set for the current client (resolving ${r.join(", ")})`);let n=await bl(this,Gi,yv).call(this,r);return r.map(i=>n[i]??new Error(`Failed to resolve type: ${i}`))}),e=kr(this,to)?.types;if(e)for(let[r,n]of Object.entries(e))t.prime(r,n);return t})};gv=async function(t){if(t.length===0)return{};let e=Vs(t,kr(this,xu)),r={};return await Promise.all(e.map(async n=>{let i=await bl(this,Gi,Vh).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};yv=async function(t){if(t.length===0)return{};let e=Vs(t,kr(this,xu)),r={};return await Promise.all(e.map(async n=>{let i=await bl(this,Gi,Vh).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};Vh=async function(t,e){if(!kr(this,vs))throw new Error("MVR Api URL is not set for the current client");let r=await fetch(`${kr(this,vs)}${t}`,{method:"POST",headers:{"Content-Type":"application/json",...$3},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 F3(t){if(t?.packages)for(let[e,r]of Object.entries(t.packages)){if(!Wr(e))throw new Error(`Invalid package name: ${e}`);if(!Kr(Ve(r)))throw new Error(`Invalid package ID: ${r}`)}if(t?.types)for(let[e,r]of Object.entries(t.types)){if(Li(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=Li(r);if(!Kr(n.address))throw new Error(`Invalid type: ${r}`)}}function $h(t,e=new Set){if(typeof t=="string"&&!dn(t))return e;let r=_v(t)?t:Li(t);dn(r.address)&&e.add(`${r.address}::${r.module}::${r.name}`);for(let n of r.typeParams)$h(n,e);return e}function Fh(t,e){let r=_v(t)?t:Li(t),n=`${r.address}::${r.module}::${r.name}`,i=e[n];return Ro({...r,address:i?i.split("::")[0]:r.address,typeParams:r.typeParams.map(s=>Fh(s,e))})}function dn(t){return t.includes(L3)||t.includes("@")||t.includes(".sui")}function _v(t){return typeof t=="object"&&"address"in t&&"module"in t&&"name"in t&&"typeParams"in t}function vv(t){let e=new Set,r=new Set;for(let n of t.commands)switch(n.$kind){case"MakeMoveVec":n.MakeMoveVec.type&&pv([n.MakeMoveVec.type]).forEach(o=>{r.add(o)});break;case"MoveCall":let i=n.MoveCall,s=i.package.split("::")[0];if(dn(s)){if(!Wr(s))throw new Error(`Invalid package name: ${s}`);e.add(s)}pv(i.typeArguments??[]).forEach(o=>{r.add(o)});break;default:break}return{packages:[...e],types:[...r]}}function bv(t,e){for(let r of t.commands){if(r.MakeMoveVec?.type){if(!dn(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(dn(s)&&!e.packages[s])throw new Error(`No address found for package: ${s}`);dn(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(dn(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 pv(t){let e=new Set;for(let r of t)if(dn(r)){if(!p_(r))throw new Error(`Invalid type with names: ${r}`);e.add(r)}return e}var zh=new WeakMap,wv=t=>{let e;if(t){let r=t.overrides??{packages:{},types:{}};zh.has(r)||zh.set(r,new yl),e=new Oa({cache:zh.get(r),url:t.url,pageSize:t.pageSize,overrides:r})}return async(r,n,i)=>{let s=vv(r);if(s.types.length===0&&s.packages.length===0)return i();let o=await(e||q3(n).core.mvr).resolve({types:s.types,packages:s.packages});bv(r,o),await i()}};function q3(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 V3=50,z3=1000n,G3=5e10;function wl(t){return async function(r,n,i){return await J3(r,t),await X3(r,t),n.onlyTransactionKind||(await H3(r,t),await W3(r,t),await K3(r,t)),await i()}}async function H3(t,e){t.gasConfig.price||(t.gasConfig.price=String(await e.getReferenceGasPrice()))}async function W3(t,e){if(t.gasConfig.budget)return;let r=await e.dryRunTransactionBlock({transactionBlock:t.build({overrides:{gasData:{budget:String(G3),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=z3*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 K3(t,e){if(!t.gasConfig.payment){let n=(await e.getCoins({owner:t.gasConfig.owner||t.sender,coinType:Hd})).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=>Ft(wi,i))}}async function X3(t,e){let r=t.inputs.filter(p=>p.UnresolvedObject&&!(p.UnresolvedObject.version||p.UnresolvedObject?.initialSharedVersion)),n=[...new Set(r.map(p=>Nr(p.UnresolvedObject.objectId)))],i=n.length?Vs(n,V3):[],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=Ve(_.UnresolvedObject.objectId),T=d.get(O);_.UnresolvedObject.initialSharedVersion??T?.initialSharedVersion?b=Ln.SharedObjectRef({objectId:O,initialSharedVersion:_.UnresolvedObject.initialSharedVersion||T?.initialSharedVersion,mutable:Z3(t,p)}):Y3(t,p)&&(b=Ln.ReceivingRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})),t.inputs[t.inputs.indexOf(_)]=b??Ln.ObjectRef({objectId:O,digest:_.UnresolvedObject.digest??T?.digest,version:_.UnresolvedObject.version??T?.version})}}async function J3(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=>Q_(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&&Y_(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=ml(_.body);if(F){O.type="pure",r[r.indexOf(T)]=Ln.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 Z3(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 Y3(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=Q3(i.MoveCall._argumentTypes[s])||r}}),r}function Q3(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 Gh(t,e){return!!(t.inputs.some(r=>r.UnresolvedObject||r.UnresolvedPure)||!e.onlyTransactionKind&&(!t.gasConfig.price||!t.gasConfig.budget||!t.gasConfig.payment))}async function kv(t,e,r){if(tP(t),!Gh(t,e))return await Mv(t),r();let n=eP(e),i=n.core?.resolveTransactionPlugin()??wl(n);return wv()(t,e,async()=>{await i(t,e,async()=>{await Mv(t),await r()})})}function Mv(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 eP(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 tP(t){for(let e of t.commands)switch(e.$kind){case"SplitCoins":e.SplitCoins.amounts.forEach(r=>{Sv(r,it.U64,t)});break;case"TransferObjects":Sv(e.TransferObjects.address,it.Address,t);break}}function Sv(t,e,r){if(t.$kind!=="Input")return;let n=r.inputs[t.Input];n.$kind==="UnresolvedPure"&&(r.inputs[t.Input]=Ln.Pure(e.serialize(n.UnresolvedPure.value)))}function Ov(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 Ev(t){function e(r,n){if(typeof r=="string")return t(wa(r).serialize(n));if(r instanceof Uint8Array||va(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(it.U8.serialize(r)),e.u16=r=>t(it.U16.serialize(r)),e.u32=r=>t(it.U32.serialize(r)),e.u64=r=>t(it.U64.serialize(r)),e.u128=r=>t(it.U128.serialize(r)),e.u256=r=>t(it.U256.serialize(r)),e.bool=r=>t(it.Bool.serialize(r)),e.string=r=>t(it.String.serialize(r)),e.address=r=>t(it.Address.serialize(r)),e.id=e.address,e.vector=(r,n)=>t(it.vector(wa(r)).serialize(n)),e.option=(r,n)=>t(it.option(wa(r)).serialize(n)),e}function Av(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),il(n,{dkLen:32})}function Iv(t){return Ve(t).replace("0x","")}var $n=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=it.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=it.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(Ft(ka,e)):new t(Ft(ka,ov(e)))}static getDigestFromBytes(e){let r=Av("TransactionData",e);return gi(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 it.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:Iv(c),expiration:u||{None:!0},gasData:{payment:d.payment,owner:Iv(this.gasData.owner??c),price:BigInt(d.price),budget:BigInt(d.budget)},kind:{ProgrammableTransaction:{inputs:i,commands:s}}};return it.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 Ft(ka,this)}shallowClone(){return new t({version:this.version,sender:this.sender,expiration:this.expiration,gasData:{...this.gasData},inputs:[...this.inputs],commands:[...this.commands]})}};function Hh(t){if(typeof t=="string")return Ve(t);if(t.Object)return t.Object.ImmOrOwnedObject?Ve(t.Object.ImmOrOwnedObject.objectId):t.Object.Receiving?Ve(t.Object.Receiving.objectId):Ve(t.Object.SharedObject.objectId);if(t.UnresolvedObject)return Ve(t.UnresolvedObject.objectId)}var xv=t=>{throw TypeError(t)},Zh=(t,e,r)=>e.has(t)||xv("Cannot "+r),ye=(t,e,r)=>(Zh(t,e,"read from private field"),r?r.call(t):e.get(t)),Hi=(t,e,r)=>e.has(t)?xv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),rr=(t,e,r,n)=>(Zh(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),Or=(t,e,r)=>(Zh(t,e,"access private method"),r),Go,Ho,bs,Wi,Fn,qn,Si,ro,Ze,gr,Pv,Ml,Sl,kl,Ol,Xh,Yh,Cv,jv;function Wh(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 Nv=Symbol.for("@mysten/transaction");function El(t){return!!t&&typeof t=="object"&&t[Nv]===!0}var Tv={buildPlugins:new Map,serializationPlugins:new Map},Kh=Symbol.for("@mysten/transaction/registry");function Pu(){try{let t=globalThis;return t[Kh]||(t[Kh]=Tv),t[Kh]}catch{return Tv}}var Dv=class Jh{constructor(){Hi(this,gr),Hi(this,Go),Hi(this,Ho),Hi(this,bs,new Map),Hi(this,Wi,[]),Hi(this,Fn,[]),Hi(this,qn,new Set),Hi(this,Si,new Set),Hi(this,ro,new Map),Hi(this,Ze),this.object=Ov(r=>{if(typeof r=="function")return this.object(this.add(r));if(typeof r=="object"&&Ou(tr,r))return r;let n=Hh(r),i=ye(this,Ze).inputs.find(s=>n===Hh(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,Ze).inputs.indexOf(i),type:"object"}:Or(this,gr,Sl).call(this,"object",typeof r=="string"?{$kind:"UnresolvedObject",UnresolvedObject:{objectId:Ve(r)}}:r)});let e=Pu();rr(this,Ze,new $n),rr(this,Ho,[...e.buildPlugins.values()]),rr(this,Go,[...e.serializationPlugins.values()])}static fromKind(e){let r=new Jh;return rr(r,Ze,$n.fromKindBytes(typeof e=="string"?hr(e):e)),rr(r,Wi,ye(r,Ze).inputs.slice()),rr(r,Fn,ye(r,Ze).commands.slice()),rr(r,qn,new Set(ye(r,Fn).map((n,i)=>i))),r}static from(e){let r=new Jh;return El(e)?rr(r,Ze,new $n(e.getData())):typeof e!="string"||!e.startsWith("{")?rr(r,Ze,$n.fromBytes(typeof e=="string"?hr(e):e)):rr(r,Ze,$n.restore(JSON.parse(e))),rr(r,Wi,ye(r,Ze).inputs.slice()),rr(r,Fn,ye(r,Ze).commands.slice()),rr(r,qn,new Set(ye(r,Fn).map((n,i)=>i))),r}static registerGlobalSerializationPlugin(e,r){Pu().serializationPlugins.set(e,r??e)}static unregisterGlobalSerializationPlugin(e){Pu().serializationPlugins.delete(e)}static registerGlobalBuildPlugin(e,r){Pu().buildPlugins.set(e,r??e)}static unregisterGlobalBuildPlugin(e){Pu().buildPlugins.delete(e)}addSerializationPlugin(e){ye(this,Go).push(e)}addBuildPlugin(e){ye(this,Ho).push(e)}addIntentResolver(e,r){if(ye(this,bs).has(e)&&ye(this,bs).get(e)!==r)throw new Error(`Intent resolver for ${e} already exists`);ye(this,bs).set(e,r)}setSender(e){ye(this,Ze).sender=e}setSenderIfNotSet(e){ye(this,Ze).sender||(ye(this,Ze).sender=e)}setExpiration(e){ye(this,Ze).expiration=e?Ft(Nh,e):null}setGasPrice(e){ye(this,Ze).gasConfig.price=String(e)}setGasBudget(e){ye(this,Ze).gasConfig.budget=String(e)}setGasBudgetIfNotSet(e){ye(this,Ze).gasData.budget==null&&(ye(this,Ze).gasConfig.budget=String(e))}setGasOwner(e){ye(this,Ze).gasConfig.owner=e}setGasPayment(e){ye(this,Ze).gasConfig.payment=e.map(r=>Ft(wi,r))}get blockData(){return Rh(ye(this,Ze).snapshot())}getData(){return ye(this,Ze).snapshot()}get[Nv](){return!0}get pure(){return Object.defineProperty(this,"pure",{enumerable:!1,value:Ev(e=>va(e)?Or(this,gr,Sl).call(this,"pure",{$kind:"Pure",Pure:{bytes:e.toBase64()}}):Or(this,gr,Sl).call(this,"pure",Ou(jh,e)?Ft(jh,e):e instanceof Uint8Array?Ln.Pure(e):{$kind:"UnresolvedPure",UnresolvedPure:{value:e}}))}),this.pure}get gas(){return{$kind:"GasCoin",GasCoin:!0}}objectRef(...e){return this.object(Ln.ObjectRef(...e))}receivingRef(...e){return this.object(Ln.ReceivingRef(...e))}sharedObjectRef(...e){return this.object(Ln.SharedObjectRef(...e))}add(e){if(typeof e=="function"){if(ye(this,ro).has(e))return ye(this,ro).get(e);let r=Or(this,gr,Pv).call(this),n=e(r);if(!(n&&typeof n=="object"&&"then"in n))return rr(this,qn,ye(r,qn)),ye(this,ro).set(e,n),n;let i=Or(this,gr,Ml).call(this,{$kind:"$Intent",$Intent:{name:"AsyncTransactionThunk",inputs:{},data:{resultIndex:ye(this,Ze).commands.length,result:null}}});ye(this,Si).add(Promise.resolve(n).then(o=>{i.$Intent.data.result=o}));let s=Wh(()=>i.$Intent.data.resultIndex);return ye(this,ro).set(e,s),s}else Or(this,gr,Ml).call(this,e);return Wh(ye(this,Ze).commands.length-1)}splitCoins(e,r){let n=eo.SplitCoins(typeof e=="string"?this.object(e):Or(this,gr,Ol).call(this,e),r.map(i=>typeof i=="number"||typeof i=="bigint"||typeof i=="string"?this.pure.u64(i):Or(this,gr,kl).call(this,i)));return Or(this,gr,Ml).call(this,n),Wh(ye(this,Ze).commands.length-1,r.length)}mergeCoins(e,r){return this.add(eo.MergeCoins(this.object(e),r.map(n=>this.object(n))))}publish({modules:e,dependencies:r}){return this.add(eo.Publish({modules:e,dependencies:r}))}upgrade({modules:e,dependencies:r,package:n,ticket:i}){return this.add(eo.Upgrade({modules:e,dependencies:r,package:n,ticket:this.object(i)}))}moveCall({arguments:e,...r}){return this.add(eo.MoveCall({...r,arguments:e?.map(n=>Or(this,gr,kl).call(this,n))}))}transferObjects(e,r){return this.add(eo.TransferObjects(e.map(n=>this.object(n)),typeof r=="string"?this.pure.address(r):Or(this,gr,kl).call(this,r)))}makeMoveVec({type:e,elements:r}){return this.add(eo.MakeMoveVec({type:e,elements:r.map(n=>this.object(n))}))}serialize(){return JSON.stringify(Rh(ye(this,Ze).snapshot()))}async toJSON(e={}){await this.prepareForSerialization(e);let r=this.isFullyResolved();return JSON.stringify(Ft(av,r?{...ye(this,Ze).snapshot(),digest:ye(this,Ze).getDigest()}:ye(this,Ze).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,Ze).sender||ye(this,Si).size>0||ye(this,Ze).commands.some(e=>e.$Intent)||Gh(ye(this,Ze),{}))}async build(e={}){return await this.prepareForSerialization(e),await Or(this,gr,Xh).call(this,e),ye(this,Ze).build({onlyTransactionKind:e.onlyTransactionKind})}async getDigest(e={}){return await Or(this,gr,Xh).call(this,e),ye(this,Ze).getDigest()}async prepareForSerialization(e){await Or(this,gr,Cv).call(this),Or(this,gr,jv).call(this);let r=new Set;for(let i of ye(this,Ze).commands)i.$Intent&&r.add(i.$Intent.name);let n=[...ye(this,Go)];for(let i of r)if(!e.supportedIntents?.includes(i)){if(!ye(this,bs).has(i))throw new Error(`Missing intent resolver for ${i}`);n.push(ye(this,bs).get(i))}await Or(this,gr,Yh).call(this,n,e)}};Go=new WeakMap;Ho=new WeakMap;bs=new WeakMap;Wi=new WeakMap;Fn=new WeakMap;qn=new WeakMap;Si=new WeakMap;ro=new WeakMap;Ze=new WeakMap;gr=new WeakSet;Pv=function(){let t=new Dv;return rr(t,Ze,ye(this,Ze)),rr(t,Go,ye(this,Go)),rr(t,Ho,ye(this,Ho)),rr(t,bs,ye(this,bs)),rr(t,Si,ye(this,Si)),rr(t,qn,new Set(ye(this,qn))),rr(t,ro,ye(this,ro)),ye(this,Wi).push(ye(t,Wi)),ye(this,Fn).push(ye(t,Fn)),t};Ml=function(t){let e=ye(this,Ze).commands.length;return ye(this,Fn).push(t),ye(this,qn).add(e),ye(this,Ze).commands.push(t),ye(this,Ze).mapCommandArguments(e,r=>{if(r.$kind==="Result"&&!ye(this,qn).has(r.Result))throw new Error(`Result { Result: ${r.Result} } is not available to use the current transaction`);if(r.$kind==="NestedResult"&&!ye(this,qn).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,Ze).inputs.length)throw new Error(`Input { Input: ${r.Input} } references an input that does not exist in the current transaction`);return r}),t};Sl=function(t,e){return ye(this,Wi).push(e),ye(this,Ze).addInput(t,e)};kl=function(t){return va(t)?this.pure(t):Or(this,gr,Ol).call(this,t)};Ol=function(t){if(typeof t=="function"){let e=this.add(t);return typeof e=="function"?Or(this,gr,Ol).call(this,e):Ft(tr,e)}return Ft(tr,t)};Xh=async function(t){if(!t.onlyTransactionKind&&!ye(this,Ze).sender)throw new Error("Missing transaction sender");await Or(this,gr,Yh).call(this,[...ye(this,Ho),kv],t)};Yh=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,Ze),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)(),rr(this,Wi,ye(this,Ze).inputs.slice()),rr(this,Fn,ye(this,Ze).commands.slice())};Cv=async function(){for(;ye(this,Si).size>0;){let t=Promise.all(ye(this,Si));ye(this,Si).clear(),ye(this,Si).add(t),await t,ye(this,Si).delete(t)}};jv=function(){let t=ye(this,Ze).commands,e=ye(this,Ze).inputs,r=ye(this,Fn).flat(1/0),n=ye(this,Wi).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,Ze).commands=i,ye(this,Ze).inputs=n,rr(this,Fn,i),rr(this,Wi,n),rr(this,qn,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,Ze).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 ft=Dv;var Ea=require("@cetusprotocol/common-sdk"),Bv=t=>{let e=[];return t.forEach(r=>{e.push(Qh(r))}),e},Qh=t=>{let e=(0,Ea.getObjectFields)(t);return{marketId:e.id.id,baseToken:(0,Ea.addHexPrefix)(e.base_token.fields.name),quoteToken:(0,Ea.addHexPrefix)(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}},ep=t=>{let e=(0,Ea.getObjectFields)(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}};var Rv=require("@suilend/sdk/parsers/obligation"),Uv=require("@suilend/sdk/_generated/suilend/lending-market/functions"),Al=class{constructor(e){this.getLeverageConfig=async()=>{let e=(0,he.getPackagerConfigs)(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=(0,he.getPackagerConfigs)(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}),_=Bv(p);return this._sdk.updateCache(r,_,he.CACHE_TIME_5MIN),_};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=Qh(i);return this._sdk.updateCache(r,s,he.CACHE_TIME_5MIN),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}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),i=await this._sdk.SuiLendModule.getSuilendClient(r,n),s=[];for(let o=0;o<e.data.length;o++){let u=ep(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=ep(r.data[0]),{lendingMarketId:i,lendingMarketType:s}=(0,he.getPackagerConfigs)(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{...(0,Rv.parseObligation)(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}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),p=new ft,{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,pe;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=he.CoinAssist.buildCoinWithBalance(BigInt(i.toString()),z,p);pe=await this.routerSwap({router:ce.route_obj,slippage:o,inputCoin:E,txb:p}),te=pe}}else te=he.CoinAssist.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=(0,he.d)(A).mul(T).toString(),{balanceA:N,balanceB:k,receipt:m}=this.flashLoan({amount:(0,he.d)(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,(0,he.d)(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=(0,he.d)(h?.amount_out||0),v;h&&(v=await this.routerSwap({router:h.route_obj,inputCoin:C?he.CoinAssist.fromBalance(N,x,p):he.CoinAssist.fromBalance(k,F,p),slippage:o,txb:p}));let M=(0,he.d)(y).add(ae).mul(1-_).toDP(0,Vi.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=ds(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=(0,he.d)(A).add(D).toDP(0,Vi.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:(0,he.d)(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=he.CoinAssist.mintBalanceZero(C?F:x,p);return this.repayFlashLoan({tx:p,clmmPool:s,repayBase:C?he.CoinAssist.intoBalance(S,x,p):V,repayQuote:C?V:he.CoinAssist.intoBalance(S,F,p),receipt:m,clmmPoolCoinTypeA:x,clmmPoolCoinTypeB:F}),p.transferObjects([w],p.pure.address(this._sdk.getSenderAddress())),he.CoinAssist.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}=(0,he.getPackagerConfigs)(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 ft,ae=T[0].reserveArrayIndex.toString(),te=x[0].reserveArrayIndex.toString(),pe=i&&O||!i&&!O,A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",pe);let I;if(pe){let S=i&&O?b:_,V=i&&O?_:b,z=await this.findRouters(S,V,s,!0,[o]);if(z){let Z=he.CoinAssist.buildCoinWithBalance(BigInt(s.toString()),S,ee);I=await this.routerSwap({router:z.route_obj,inputCoin:Z,slippage:u,txb:ee}),A=I}}else A=he.CoinAssist.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=(0,he.d)(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:(0,he.d)(D),clmmPool:o,clmmPoolCoinTypeA:H,clmmPoolCoinTypeB:J,flashLoanCoin:C,tx:ee}),h=O?b:_,y=O?_:b,v=await this.findRouters(h,y,(0,he.d)(D),!0,[o]),M;v&&(M=await this.routerSwap({router:v.route_obj,inputCoin:k?he.CoinAssist.fromBalance(m,H,ee):he.CoinAssist.fromBalance(a,J,ee),slippage:u,txb:ee})),ee.mergeCoins(M,[A]);for(let S=0;S<F.length;S++){let V=ds(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=(0,he.d)(D).add(N).toDP(0,Vi.ROUND_UP).toString(),g=this.borrowAsset({positionId:n,reserveArrayIndex:te,borrowAmount:(0,he.d)(w),baseToken:_,quoteToken:b,isLong:O,lendingMarketId:p},ee),f=he.CoinAssist.mintBalanceZero(k?J:H,ee);return this.repayFlashLoan({tx:ee,clmmPool:o,repayBase:k?he.CoinAssist.intoBalance(g,H,ee):f,repayQuote:k?f:he.CoinAssist.intoBalance(g,J,ee),receipt:l,clmmPoolCoinTypeA:H,clmmPoolCoinTypeB:J}),he.CoinAssist.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:_}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),b=o||new ft,{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=ds(new Uint8Array(H[M].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(b,w,BigInt(H[M].arrayIndex))}let{token:te}=R[0].reserve,pe=(0,he.d)(F[0].depositedCtokenAmount.toString()).div((0,he.d)(d)).toDP(0,Vi.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",pe);let A=(0,he.d)(ee).div((0,he.d)(pe)).toString(),I=(0,he.d)(R[0].borrowedAmount.toString()).mul(10**te.decimals).toString(),C=(0,he.d)(I).mul(A).toDP(0,Vi.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:pe});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:(0,he.d)(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,(0,he.d)(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:(0,he.d)(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}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:H}=b[0].reserve,J=new ft,ee=(0,he.d)(b[0].borrowedAmount.toString()).mul((0,he.d)(o).sub((0,he.d)(s))).mul(10**H.decimals).toDP(0,Vi.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:pe,balanceB:A,receipt:I}=this.flashLoan({tx:J,amount:(0,he.d)(ae),clmmPool:u,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:x,flashLoanCoin:te}),C=i?p:d,D=i?d:p,N=await this.findRouters(C,D,(0,he.d)(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?he.CoinAssist.fromBalance(A,x,J):he.CoinAssist.fromBalance(pe,T,J),slippage:c,txb:J});for(let y=0;y<O.length;y++){let v=ds(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=(0,he.d)(ae).mul((0,he.d)(1).add(F)).toDP(0,Vi.ROUND_UP).toString(),a=await this.borrowAsset({positionId:n,reserveArrayIndex:b[0].reserveArrayIndex.toString(),borrowAmount:(0,he.d)(m),baseToken:d,quoteToken:p,isLong:i,lendingMarketId:R},J),l=he.CoinAssist.mintBalanceZero(i?d:p,J),h=T===te;return this.repayFlashLoan({tx:J,clmmPool:u,repayBase:i?l:he.CoinAssist.intoBalance(a,d,J),repayQuote:i?he.CoinAssist.intoBalance(a,p,J):l,receipt:I,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:x}),he.CoinAssist.destroyBalanceZero(h?A:pe,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}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),R=new ft,H=(0,he.d)(b[0].depositedCtokenAmount.toString()).mul((0,he.d)(s).sub((0,he.d)(o))).toString(),J=(0,he.d)(H).toDP(0,Vi.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=ds(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 pe=this.withdrawAsset({marketId:r,positionId:n,withdrawAmount:(0,he.d)(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,(0,he.d)(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:pe,slippage:c,txb:R});return this.repay({txb:R,positionId:n,repayReserveArrayIndex:O[0].reserveArrayIndex.toString(),repayCoin:D,repayCoinType:i?p:d,repayAmount:(0,he.d)(0)}),D&&R.transferObjects([D],this._sdk.getSenderAddress()),R};this.leveragePositionClose=async(e,r)=>{let n=r||new ft,{marketId:i,positionId:s}=e,{leverage:o}=this._sdk.sdkOptions,{global_config_id:u}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:c,lendingMarketId:d}=(0,he.getPackagerConfigs)(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=(0,Uv.obligation)(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(he.CLOCK_ADDRESS)]}),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}=(0,he.getPackagerConfigs)(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}=(0,he.getPackagerConfigs)(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}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return he.CoinAssist.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(Zc),r.object(he.CLOCK_ADDRESS)]}):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(he.CLOCK_ADDRESS)]})};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}=(0,he.getPackagerConfigs)(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 he.CoinAssist.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(Zc),r.object(he.CLOCK_ADDRESS)]}):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(he.CLOCK_ADDRESS)]})};this.repay=e=>{let{leverage:r}=this._sdk.sdkOptions,{lendingMarketId:n,lendingMarketType:i}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:s,positionId:o,repayAmount:u,repayCoinType:c,repayCoin:d,repayReserveArrayIndex:p}=e,_=s||new ft,b=d||he.CoinAssist.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(he.CLOCK_ADDRESS)]})};this.routerSwap=async e=>{let{slippage:r,txb:n,inputCoin:i,router:s}=e,o=n||new ft;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,(0,he.d)(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[(0,he.removeHexPrefix)(s)]?.price,p=c[(0,he.removeHexPrefix)(i)]?.price,_=r?(0,he.d)(p).div((0,he.d)(d)).toString():(0,he.d)(d).div((0,he.d)(p)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",o.toString(),r,_,d,p),{flashAmount:(0,he.d)(o).mul(n-1).mul(_).toDP(0,Vi.ROUND_UP).toString(),rate:_,quotePrice:d,basePrice:p}}createLeveragePosition(e){let{lendingMarketId:r,lendingMarketType:n}=(0,he.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:i}=(0,he.getPackagerConfigs)(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(he.CLOCK_ADDRESS)],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}=(0,he.getPackagerConfigs)(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(he.CLOCK_ADDRESS)]}),r}async findRouters(e,r,n,i,s){let{providers:o}=this._sdk.sdkOptions;try{let u={from:e,target:r,amount:new tp.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 tp.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 Pc=Nc(H6());var ez={"-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"},sd=class extends Error{},iu=class extends sd{constructor(e,r){super(e),this.code=r,this.type=ez[r]??"ServerError"}},od=class extends sd{constructor(e,r,n){super(e),this.status=r,this.statusText=n}};var W6=t=>{throw TypeError(t)},gy=(t,e,r)=>e.has(t)||W6("Cannot "+r),fr=(t,e,r)=>(gy(t,e,"read from private field"),r?r.call(t):e.get(t)),da=(t,e,r)=>e.has(t)?W6("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),su=(t,e,r,n)=>(gy(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),K6=(t,e,r)=>(gy(t,e,"access private method"),r),tz=(t,e,r,n)=>({set _(i){su(t,e,i,r)},get _(){return fr(t,e,n)}}),Ao,Sc,Ds,ha,kc,pa,ad,X6,J6;function rz(t){let e=new URL(t);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var nz={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},ud=class{constructor(e,r={}){if(da(this,ad),da(this,Ao,0),da(this,Sc,0),da(this,Ds,null),da(this,ha,null),da(this,kc,new Set),da(this,pa,new Map),this.endpoint=e,this.options={...nz,...r},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=rz(this.endpoint))}async makeRequest(e,r,n){let i=await K6(this,ad,X6).call(this);return new Promise((s,o)=>{su(this,Ao,fr(this,Ao)+1),fr(this,pa).set(fr(this,Ao),{resolve:s,reject:o,timeout:setTimeout(()=>{fr(this,pa).delete(fr(this,Ao)),o(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n?.addEventListener("abort",()=>{fr(this,pa).delete(fr(this,Ao)),o(n.reason)}),i.send(JSON.stringify({jsonrpc:"2.0",id:fr(this,Ao),method:e,params:r}))}).then(({error:s,result:o})=>{if(s)throw new iu(s.message,s.code);return o})}async subscribe(e){let r=new my(e);return fr(this,kc).add(r),await r.subscribe(this),()=>r.unsubscribe(this)}};Ao=new WeakMap;Sc=new WeakMap;Ds=new WeakMap;ha=new WeakMap;kc=new WeakMap;pa=new WeakMap;ad=new WeakSet;X6=function(){return fr(this,ha)?fr(this,ha):(su(this,ha,new Promise(t=>{fr(this,Ds)?.close(),su(this,Ds,new this.options.WebSocketConstructor(this.endpoint)),fr(this,Ds).addEventListener("open",()=>{su(this,Sc,0),t(fr(this,Ds))}),fr(this,Ds).addEventListener("close",()=>{tz(this,Sc)._++,fr(this,Sc)<=this.options.maxReconnects&&setTimeout(()=>{K6(this,ad,J6).call(this)},this.options.reconnectTimeout)}),fr(this,Ds).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&&fr(this,pa).has(r.id)){let{resolve:n,timeout:i}=fr(this,pa).get(r.id);clearTimeout(i),n(r)}else if("params"in r){let{params:n}=r;fr(this,kc).forEach(i=>{i.subscriptionId===n.subscription&&n.subscription===i.subscriptionId&&i.onMessage(n.result)})}})})),fr(this,ha))};J6=async function(){return fr(this,Ds)?.close(),su(this,ha,null),Promise.allSettled([...fr(this,kc)].map(t=>t.subscribe(this)))};var my=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 Z6=t=>{throw TypeError(t)},vy=(t,e,r)=>e.has(t)||Z6("Cannot "+r),Jn=(t,e,r)=>(vy(t,e,"read from private field"),r?r.call(t):e.get(t)),cd=(t,e,r)=>e.has(t)?Z6("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),yy=(t,e,r,n)=>(vy(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),iz=(t,e,r)=>(vy(t,e,"access private method"),r),Oc,Ni,Ec,_y,Y6,ld=class{constructor(e){cd(this,_y),cd(this,Oc,0),cd(this,Ni),cd(this,Ec),yy(this,Ni,e)}fetch(e,r){let n=Jn(this,Ni).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){yy(this,Oc,Jn(this,Oc)+1);let r=await this.fetch(Jn(this,Ni).rpc?.url??Jn(this,Ni).url,{method:"POST",signal:e.signal,headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":_l,"Client-Target-Api-Version":hv,"Client-Request-Method":e.method,...Jn(this,Ni).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:Jn(this,Oc),method:e.method,params:e.params})});if(!r.ok)throw new od(`Unexpected status code: ${r.status}`,r.status,r.statusText);let n=await r.json();if("error"in n&&n.error!=null)throw new iu(n.error.message,n.error.code);return n.result}async subscribe(e){let r=await iz(this,_y,Y6).call(this).subscribe(e);return e.signal&&(e.signal.throwIfAborted(),e.signal.addEventListener("abort",()=>{r()})),async()=>!!await r()}};Oc=new WeakMap;Ni=new WeakMap;Ec=new WeakMap;_y=new WeakSet;Y6=function(){if(!Jn(this,Ec)){let t=Jn(this,Ni).WebSocketConstructor??WebSocket;if(!t)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");yy(this,Ec,new ud(Jn(this,Ni).websocket?.url??Jn(this,Ni).url,{WebSocketConstructor:t,...Jn(this,Ni).websocket}))}return Jn(this,Ec)};var ou=class{constructor({network:e,base:r}){this.cache=new yl,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 fd=class extends ou{constructor(e){super(e),this.core=this,this.mvr=new Oa({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=N_(e.parentId,_i.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=Li(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]:Ro(i.typeParams[0]),bcs:e.name.bcs},value:{type:typeof i.typeParams[1]=="string"?i.typeParams[1]:Ro(i.typeParams[1]),bcs:s.slice(Bo+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 by=class extends Error{},Ac=class t extends by{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 Q6(t){return{...$n.fromBytes(t).snapshot(),bcs:t}}function eI(t){let e=it.TransactionEffects.parse(t);switch(e.$kind){case"V1":return sz({bytes:t,effects:e.V1});case"V2":return oz({bytes:t,effects:e.V2});default:throw new Error(`Unknown transaction effects version: ${e.$kind}`)}}function sz(t){throw new Error("V1 effects are not supported yet")}function oz({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 nI=t=>{throw TypeError(t)},iI=(t,e,r)=>e.has(t)||nI("Cannot "+r),Nn=(t,e,r)=>(iI(t,e,"read from private field"),r?r.call(t):e.get(t)),az=(t,e,r)=>e.has(t)?nI("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),uz=(t,e,r,n)=>(iI(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),on,dd=class extends fd{constructor({jsonRpcClient:e,mvr:r}){super({network:e.network,base:e,mvr:r}),az(this,on),uz(this,on,e)}async getObjects(e){let r=Vs(e.objectIds,50),n=[];for(let i of r){let s=await Nn(this,on).multiGetObjects({ids:i,options:{showOwner:!0,showType:!0,showBcs:!0},signal:e.signal});for(let[o,u]of s.entries())u.error?n.push(Ac.fromResponse(u.error,i[o])):n.push(tI(u.data))}return{objects:n}}async getOwnedObjects(e){let r=await Nn(this,on).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 Ac.fromResponse(n.error);return tI(n.data)}),hasNextPage:r.hasNextPage,cursor:r.nextCursor??null}}async getCoins(e){let r=await Nn(this,on).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(fz.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 Nn(this,on).getBalance({owner:e.address,coinType:e.coinType,signal:e.signal});return{balance:{coinType:r.coinType,balance:r.totalBalance}}}async getAllBalances(e){return{balances:(await Nn(this,on).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 Nn(this,on).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 Nn(this,on).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=ft.from(e.transaction),n=await Nn(this,on).dryRunTransactionBlock({transactionBlock:e.transaction,signal:e.signal}),{effects:i,objectTypes:s}=cz({effects:n.effects,objectChanges:n.objectChanges});return{transaction:{digest:await r.getDigest(),epoch:null,effects:i,objectTypes:Promise.resolve(s),signatures:[],transaction:Q6(e.transaction)}}}async getReferenceGasPrice(e){let r=await Nn(this,on).getReferenceGasPrice({signal:e?.signal});return{referenceGasPrice:String(r)}}async getDynamicFields(e){let r=await Nn(this,on).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:hr(n.bcsName)}})),hasNextPage:r.hasNextPage,cursor:r.nextCursor}}async verifyZkLoginSignature(e){let r=await Nn(this,on).verifyZkLoginSignature({bytes:e.bytes,signature:e.signature,intentScope:e.intentScope,author:e.author});return{success:r.success,errors:r.errors}}resolveNameServiceNames(e){return Nn(this,on).resolveNameServiceNames(e)}resolveTransactionPlugin(){return wl(Nn(this,on))}};on=new WeakMap;function tI(t){return{id:t.objectId,version:t.version,digest:t.digest,type:t.type,content:Promise.resolve(t.bcs?.dataType==="moveObject"?hr(t.bcs.bcsBytes):new Uint8Array),owner:au(t.owner)}}function au(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=it.SenderSignedData.parse(hr(t.rawTransaction))[0],r={};t.objectChanges?.forEach(s=>{s.type!=="published"&&(r[s.objectId]=s.objectType)});let n=it.TransactionData.serialize(e.intentMessage.value).toBytes(),i=$n.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:eI(new Uint8Array(t.rawEffects)),objectTypes:Promise.resolve(r),transaction:{...i,bcs:n},signatures:e.txSignatures}}function cz({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:au(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:au(o.owner),outputState:"ObjectWrite",outputVersion:o.version,outputDigest:o.digest,outputOwner:au(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:au(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:au(e.gasObject.owner),idOperation:"None"},eventsDigest:e.eventsDigest??null,dependencies:e.dependencies??[],lamportVersion:e.gasObject.reference.version,changedObjects:n,unchangedSharedObjects:i,auxiliaryDataDigest:null}}}var lz=it.struct("Balance",{value:it.u64()}),fz=it.struct("Coin",{id:it.Address,balance:lz});var dz=Symbol.for("@mysten/SuiClient");var Bs=class extends ou{constructor(e){super({network:e.network??"unknown"}),this.jsonRpc=this,this.transport=e.transport??new ld({url:e.url}),this.core=new dd({jsonRpcClient:this,mvr:e.mvr})}get[dz](){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||!Kr(Ve(r)))throw new Error("Invalid Sui address");return e&&dn(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||!Kr(Ve(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||!Kr(Ve(e)))throw new Error("Invalid Sui address");return r&&dn(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||!Kr(Ve(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&&dn(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&&dn(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&&Wr(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&&Wr(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&&Wr(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&&Wr(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&&Wr(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||!Kr(Ve(e.owner)))throw new Error("Invalid Sui address");let r=e.filter?{...e.filter}:void 0;return r&&"MoveModule"in r&&Wr(r.MoveModule.package)?r.MoveModule={module:r.MoveModule.module,package:(await this.core.mvr.resolvePackage({package:r.MoveModule.package})).package}:r&&"StructType"in r&&dn(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||!Gs(Nr(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||!Gs(Nr(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&&Wr(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(!Xc(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(!Xc(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:Qt(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||!Kr(Ve(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||!Gs(Nr(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&&dn(e.MoveEventType)&&(e={...e,MoveEventType:(await this.core.mvr.resolveType({type:e.MoveEventType})).type}),e&&"MoveEventModule"in e&&Wr(e.MoveEventModule.package)&&(e={...e,MoveEventModule:{module:e.MoveEventModule.module,package:(await this.core.mvr.resolvePackage({package:e.MoveEventModule.package})).package}}),"MoveModule"in e&&Wr(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(El(e.transactionBlock))e.transactionBlock.setSenderIfNotSet(e.sender),r=Qt(await e.transactionBlock.build({client:this,onlyTransactionKind:!0}));else if(typeof e.transactionBlock=="string")r=e.transactionBlock;else if(e.transactionBlock instanceof Uint8Array)r=Qt(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:Qt(e.transactionBlock)]})}async getDynamicFields(e){if(!e.parentId||!Gs(Nr(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=En(r.digest);return cn(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=>d_(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 gI=require("@cetusprotocol/common-sdk");var Xe=require("@cetusprotocol/common-sdk"),xI=require("@cetusprotocol/common-sdk");var It=require("@cetusprotocol/common-sdk");var Ct=require("@cetusprotocol/common-sdk");var Ut=require("@cetusprotocol/common-sdk"),ut=require("@cetusprotocol/common-sdk"),ve=require("@cetusprotocol/common-sdk"),Hr=require("@cetusprotocol/common-sdk");var Ae=require("@cetusprotocol/common-sdk");var Lt=require("@cetusprotocol/common-sdk");var sr=require("@cetusprotocol/common-sdk"),an=require("@cetusprotocol/common-sdk");var GI=require("@cetusprotocol/common-sdk"),HI=require("@cetusprotocol/common-sdk"),KI=require("@cetusprotocol/common-sdk"),hz=Object.create,mI=Object.defineProperty,pz=Object.getOwnPropertyDescriptor,mz=Object.getOwnPropertyNames,gz=Object.getPrototypeOf,yz=Object.prototype.hasOwnProperty,_z=(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')}),vz=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),bz=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mz(e))!yz.call(t,i)&&i!==r&&mI(t,i,{get:()=>e[i],enumerable:!(n=pz(e,i))||n.enumerable});return t},Ls=(t,e,r)=>(r=t!=null?hz(gz(t)):{},bz(e||!t||!t.__esModule?mI(r,"default",{value:t,enumerable:!0}):r,t)),$s=vz((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=_z("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,me=ie>>>13,ze=y[6]|0,be=ze&8191,Pe=ze>>>13,qe=y[7]|0,ge=qe&8191,Fe=qe>>>13,Nt=y[8]|0,Te=Nt&8191,st=Nt>>>13,Tt=y[9]|0,Ie=Tt&8191,He=Tt>>>13,Et=v[0]|0,we=Et&8191,mt=Et>>>13,zt=v[1]|0,Ce=zt&8191,gt=zt>>>13,Gt=v[2]|0,je=Gt&8191,yt=Gt>>>13,Ht=v[3]|0,Ne=Ht&8191,_t=Ht>>>13,Wt=v[4]|0,De=Wt&8191,vt=Wt>>>13,Kt=v[5]|0,Be=Kt&8191,bt=Kt>>>13,Xt=v[6]|0,Re=Xt&8191,wt=Xt>>>13,Jt=v[7]|0,Ue=Jt&8191,Mt=Jt>>>13,Zt=v[8]|0,Le=Zt&8191,St=Zt>>>13,Yt=v[9]|0,$e=Yt&8191,pt=Yt>>>13;h.negative=a.negative^l.negative,h.length=19,g=Math.imul(z,we),f=Math.imul(z,mt),f=f+Math.imul(Z,we)|0,S=Math.imul(Z,mt);var Zn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Zn>>>26)|0,Zn&=67108863,g=Math.imul(E,we),f=Math.imul(E,mt),f=f+Math.imul(P,we)|0,S=Math.imul(P,mt),g=g+Math.imul(z,Ce)|0,f=f+Math.imul(z,gt)|0,f=f+Math.imul(Z,Ce)|0,S=S+Math.imul(Z,gt)|0;var Yn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Yn>>>26)|0,Yn&=67108863,g=Math.imul(L,we),f=Math.imul(L,mt),f=f+Math.imul(U,we)|0,S=Math.imul(U,mt),g=g+Math.imul(E,Ce)|0,f=f+Math.imul(E,gt)|0,f=f+Math.imul(P,Ce)|0,S=S+Math.imul(P,gt)|0,g=g+Math.imul(z,je)|0,f=f+Math.imul(z,yt)|0,f=f+Math.imul(Z,je)|0,S=S+Math.imul(Z,yt)|0;var Qn=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(Qn>>>26)|0,Qn&=67108863,g=Math.imul(q,we),f=Math.imul(q,mt),f=f+Math.imul($,we)|0,S=Math.imul($,mt),g=g+Math.imul(L,Ce)|0,f=f+Math.imul(L,gt)|0,f=f+Math.imul(U,Ce)|0,S=S+Math.imul(U,gt)|0,g=g+Math.imul(E,je)|0,f=f+Math.imul(E,yt)|0,f=f+Math.imul(P,je)|0,S=S+Math.imul(P,yt)|0,g=g+Math.imul(z,Ne)|0,f=f+Math.imul(z,_t)|0,f=f+Math.imul(Z,Ne)|0,S=S+Math.imul(Z,_t)|0;var ei=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,g=Math.imul(G,we),f=Math.imul(G,mt),f=f+Math.imul(K,we)|0,S=Math.imul(K,mt),g=g+Math.imul(q,Ce)|0,f=f+Math.imul(q,gt)|0,f=f+Math.imul($,Ce)|0,S=S+Math.imul($,gt)|0,g=g+Math.imul(L,je)|0,f=f+Math.imul(L,yt)|0,f=f+Math.imul(U,je)|0,S=S+Math.imul(U,yt)|0,g=g+Math.imul(E,Ne)|0,f=f+Math.imul(E,_t)|0,f=f+Math.imul(P,Ne)|0,S=S+Math.imul(P,_t)|0,g=g+Math.imul(z,De)|0,f=f+Math.imul(z,vt)|0,f=f+Math.imul(Z,De)|0,S=S+Math.imul(Z,vt)|0;var ti=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,g=Math.imul(oe,we),f=Math.imul(oe,mt),f=f+Math.imul(me,we)|0,S=Math.imul(me,mt),g=g+Math.imul(G,Ce)|0,f=f+Math.imul(G,gt)|0,f=f+Math.imul(K,Ce)|0,S=S+Math.imul(K,gt)|0,g=g+Math.imul(q,je)|0,f=f+Math.imul(q,yt)|0,f=f+Math.imul($,je)|0,S=S+Math.imul($,yt)|0,g=g+Math.imul(L,Ne)|0,f=f+Math.imul(L,_t)|0,f=f+Math.imul(U,Ne)|0,S=S+Math.imul(U,_t)|0,g=g+Math.imul(E,De)|0,f=f+Math.imul(E,vt)|0,f=f+Math.imul(P,De)|0,S=S+Math.imul(P,vt)|0,g=g+Math.imul(z,Be)|0,f=f+Math.imul(z,bt)|0,f=f+Math.imul(Z,Be)|0,S=S+Math.imul(Z,bt)|0;var ri=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(be,we),f=Math.imul(be,mt),f=f+Math.imul(Pe,we)|0,S=Math.imul(Pe,mt),g=g+Math.imul(oe,Ce)|0,f=f+Math.imul(oe,gt)|0,f=f+Math.imul(me,Ce)|0,S=S+Math.imul(me,gt)|0,g=g+Math.imul(G,je)|0,f=f+Math.imul(G,yt)|0,f=f+Math.imul(K,je)|0,S=S+Math.imul(K,yt)|0,g=g+Math.imul(q,Ne)|0,f=f+Math.imul(q,_t)|0,f=f+Math.imul($,Ne)|0,S=S+Math.imul($,_t)|0,g=g+Math.imul(L,De)|0,f=f+Math.imul(L,vt)|0,f=f+Math.imul(U,De)|0,S=S+Math.imul(U,vt)|0,g=g+Math.imul(E,Be)|0,f=f+Math.imul(E,bt)|0,f=f+Math.imul(P,Be)|0,S=S+Math.imul(P,bt)|0,g=g+Math.imul(z,Re)|0,f=f+Math.imul(z,wt)|0,f=f+Math.imul(Z,Re)|0,S=S+Math.imul(Z,wt)|0;var ni=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(ge,we),f=Math.imul(ge,mt),f=f+Math.imul(Fe,we)|0,S=Math.imul(Fe,mt),g=g+Math.imul(be,Ce)|0,f=f+Math.imul(be,gt)|0,f=f+Math.imul(Pe,Ce)|0,S=S+Math.imul(Pe,gt)|0,g=g+Math.imul(oe,je)|0,f=f+Math.imul(oe,yt)|0,f=f+Math.imul(me,je)|0,S=S+Math.imul(me,yt)|0,g=g+Math.imul(G,Ne)|0,f=f+Math.imul(G,_t)|0,f=f+Math.imul(K,Ne)|0,S=S+Math.imul(K,_t)|0,g=g+Math.imul(q,De)|0,f=f+Math.imul(q,vt)|0,f=f+Math.imul($,De)|0,S=S+Math.imul($,vt)|0,g=g+Math.imul(L,Be)|0,f=f+Math.imul(L,bt)|0,f=f+Math.imul(U,Be)|0,S=S+Math.imul(U,bt)|0,g=g+Math.imul(E,Re)|0,f=f+Math.imul(E,wt)|0,f=f+Math.imul(P,Re)|0,S=S+Math.imul(P,wt)|0,g=g+Math.imul(z,Ue)|0,f=f+Math.imul(z,Mt)|0,f=f+Math.imul(Z,Ue)|0,S=S+Math.imul(Z,Mt)|0;var ii=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,g=Math.imul(Te,we),f=Math.imul(Te,mt),f=f+Math.imul(st,we)|0,S=Math.imul(st,mt),g=g+Math.imul(ge,Ce)|0,f=f+Math.imul(ge,gt)|0,f=f+Math.imul(Fe,Ce)|0,S=S+Math.imul(Fe,gt)|0,g=g+Math.imul(be,je)|0,f=f+Math.imul(be,yt)|0,f=f+Math.imul(Pe,je)|0,S=S+Math.imul(Pe,yt)|0,g=g+Math.imul(oe,Ne)|0,f=f+Math.imul(oe,_t)|0,f=f+Math.imul(me,Ne)|0,S=S+Math.imul(me,_t)|0,g=g+Math.imul(G,De)|0,f=f+Math.imul(G,vt)|0,f=f+Math.imul(K,De)|0,S=S+Math.imul(K,vt)|0,g=g+Math.imul(q,Be)|0,f=f+Math.imul(q,bt)|0,f=f+Math.imul($,Be)|0,S=S+Math.imul($,bt)|0,g=g+Math.imul(L,Re)|0,f=f+Math.imul(L,wt)|0,f=f+Math.imul(U,Re)|0,S=S+Math.imul(U,wt)|0,g=g+Math.imul(E,Ue)|0,f=f+Math.imul(E,Mt)|0,f=f+Math.imul(P,Ue)|0,S=S+Math.imul(P,Mt)|0,g=g+Math.imul(z,Le)|0,f=f+Math.imul(z,St)|0,f=f+Math.imul(Z,Le)|0,S=S+Math.imul(Z,St)|0;var si=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(Ie,we),f=Math.imul(Ie,mt),f=f+Math.imul(He,we)|0,S=Math.imul(He,mt),g=g+Math.imul(Te,Ce)|0,f=f+Math.imul(Te,gt)|0,f=f+Math.imul(st,Ce)|0,S=S+Math.imul(st,gt)|0,g=g+Math.imul(ge,je)|0,f=f+Math.imul(ge,yt)|0,f=f+Math.imul(Fe,je)|0,S=S+Math.imul(Fe,yt)|0,g=g+Math.imul(be,Ne)|0,f=f+Math.imul(be,_t)|0,f=f+Math.imul(Pe,Ne)|0,S=S+Math.imul(Pe,_t)|0,g=g+Math.imul(oe,De)|0,f=f+Math.imul(oe,vt)|0,f=f+Math.imul(me,De)|0,S=S+Math.imul(me,vt)|0,g=g+Math.imul(G,Be)|0,f=f+Math.imul(G,bt)|0,f=f+Math.imul(K,Be)|0,S=S+Math.imul(K,bt)|0,g=g+Math.imul(q,Re)|0,f=f+Math.imul(q,wt)|0,f=f+Math.imul($,Re)|0,S=S+Math.imul($,wt)|0,g=g+Math.imul(L,Ue)|0,f=f+Math.imul(L,Mt)|0,f=f+Math.imul(U,Ue)|0,S=S+Math.imul(U,Mt)|0,g=g+Math.imul(E,Le)|0,f=f+Math.imul(E,St)|0,f=f+Math.imul(P,Le)|0,S=S+Math.imul(P,St)|0,g=g+Math.imul(z,$e)|0,f=f+Math.imul(z,pt)|0,f=f+Math.imul(Z,$e)|0,S=S+Math.imul(Z,pt)|0;var oi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(Ie,Ce),f=Math.imul(Ie,gt),f=f+Math.imul(He,Ce)|0,S=Math.imul(He,gt),g=g+Math.imul(Te,je)|0,f=f+Math.imul(Te,yt)|0,f=f+Math.imul(st,je)|0,S=S+Math.imul(st,yt)|0,g=g+Math.imul(ge,Ne)|0,f=f+Math.imul(ge,_t)|0,f=f+Math.imul(Fe,Ne)|0,S=S+Math.imul(Fe,_t)|0,g=g+Math.imul(be,De)|0,f=f+Math.imul(be,vt)|0,f=f+Math.imul(Pe,De)|0,S=S+Math.imul(Pe,vt)|0,g=g+Math.imul(oe,Be)|0,f=f+Math.imul(oe,bt)|0,f=f+Math.imul(me,Be)|0,S=S+Math.imul(me,bt)|0,g=g+Math.imul(G,Re)|0,f=f+Math.imul(G,wt)|0,f=f+Math.imul(K,Re)|0,S=S+Math.imul(K,wt)|0,g=g+Math.imul(q,Ue)|0,f=f+Math.imul(q,Mt)|0,f=f+Math.imul($,Ue)|0,S=S+Math.imul($,Mt)|0,g=g+Math.imul(L,Le)|0,f=f+Math.imul(L,St)|0,f=f+Math.imul(U,Le)|0,S=S+Math.imul(U,St)|0,g=g+Math.imul(E,$e)|0,f=f+Math.imul(E,pt)|0,f=f+Math.imul(P,$e)|0,S=S+Math.imul(P,pt)|0;var ai=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(Ie,je),f=Math.imul(Ie,yt),f=f+Math.imul(He,je)|0,S=Math.imul(He,yt),g=g+Math.imul(Te,Ne)|0,f=f+Math.imul(Te,_t)|0,f=f+Math.imul(st,Ne)|0,S=S+Math.imul(st,_t)|0,g=g+Math.imul(ge,De)|0,f=f+Math.imul(ge,vt)|0,f=f+Math.imul(Fe,De)|0,S=S+Math.imul(Fe,vt)|0,g=g+Math.imul(be,Be)|0,f=f+Math.imul(be,bt)|0,f=f+Math.imul(Pe,Be)|0,S=S+Math.imul(Pe,bt)|0,g=g+Math.imul(oe,Re)|0,f=f+Math.imul(oe,wt)|0,f=f+Math.imul(me,Re)|0,S=S+Math.imul(me,wt)|0,g=g+Math.imul(G,Ue)|0,f=f+Math.imul(G,Mt)|0,f=f+Math.imul(K,Ue)|0,S=S+Math.imul(K,Mt)|0,g=g+Math.imul(q,Le)|0,f=f+Math.imul(q,St)|0,f=f+Math.imul($,Le)|0,S=S+Math.imul($,St)|0,g=g+Math.imul(L,$e)|0,f=f+Math.imul(L,pt)|0,f=f+Math.imul(U,$e)|0,S=S+Math.imul(U,pt)|0;var ui=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ui>>>26)|0,ui&=67108863,g=Math.imul(Ie,Ne),f=Math.imul(Ie,_t),f=f+Math.imul(He,Ne)|0,S=Math.imul(He,_t),g=g+Math.imul(Te,De)|0,f=f+Math.imul(Te,vt)|0,f=f+Math.imul(st,De)|0,S=S+Math.imul(st,vt)|0,g=g+Math.imul(ge,Be)|0,f=f+Math.imul(ge,bt)|0,f=f+Math.imul(Fe,Be)|0,S=S+Math.imul(Fe,bt)|0,g=g+Math.imul(be,Re)|0,f=f+Math.imul(be,wt)|0,f=f+Math.imul(Pe,Re)|0,S=S+Math.imul(Pe,wt)|0,g=g+Math.imul(oe,Ue)|0,f=f+Math.imul(oe,Mt)|0,f=f+Math.imul(me,Ue)|0,S=S+Math.imul(me,Mt)|0,g=g+Math.imul(G,Le)|0,f=f+Math.imul(G,St)|0,f=f+Math.imul(K,Le)|0,S=S+Math.imul(K,St)|0,g=g+Math.imul(q,$e)|0,f=f+Math.imul(q,pt)|0,f=f+Math.imul($,$e)|0,S=S+Math.imul($,pt)|0;var ci=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(ci>>>26)|0,ci&=67108863,g=Math.imul(Ie,De),f=Math.imul(Ie,vt),f=f+Math.imul(He,De)|0,S=Math.imul(He,vt),g=g+Math.imul(Te,Be)|0,f=f+Math.imul(Te,bt)|0,f=f+Math.imul(st,Be)|0,S=S+Math.imul(st,bt)|0,g=g+Math.imul(ge,Re)|0,f=f+Math.imul(ge,wt)|0,f=f+Math.imul(Fe,Re)|0,S=S+Math.imul(Fe,wt)|0,g=g+Math.imul(be,Ue)|0,f=f+Math.imul(be,Mt)|0,f=f+Math.imul(Pe,Ue)|0,S=S+Math.imul(Pe,Mt)|0,g=g+Math.imul(oe,Le)|0,f=f+Math.imul(oe,St)|0,f=f+Math.imul(me,Le)|0,S=S+Math.imul(me,St)|0,g=g+Math.imul(G,$e)|0,f=f+Math.imul(G,pt)|0,f=f+Math.imul(K,$e)|0,S=S+Math.imul(K,pt)|0;var li=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(li>>>26)|0,li&=67108863,g=Math.imul(Ie,Be),f=Math.imul(Ie,bt),f=f+Math.imul(He,Be)|0,S=Math.imul(He,bt),g=g+Math.imul(Te,Re)|0,f=f+Math.imul(Te,wt)|0,f=f+Math.imul(st,Re)|0,S=S+Math.imul(st,wt)|0,g=g+Math.imul(ge,Ue)|0,f=f+Math.imul(ge,Mt)|0,f=f+Math.imul(Fe,Ue)|0,S=S+Math.imul(Fe,Mt)|0,g=g+Math.imul(be,Le)|0,f=f+Math.imul(be,St)|0,f=f+Math.imul(Pe,Le)|0,S=S+Math.imul(Pe,St)|0,g=g+Math.imul(oe,$e)|0,f=f+Math.imul(oe,pt)|0,f=f+Math.imul(me,$e)|0,S=S+Math.imul(me,pt)|0;var fi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(Ie,Re),f=Math.imul(Ie,wt),f=f+Math.imul(He,Re)|0,S=Math.imul(He,wt),g=g+Math.imul(Te,Ue)|0,f=f+Math.imul(Te,Mt)|0,f=f+Math.imul(st,Ue)|0,S=S+Math.imul(st,Mt)|0,g=g+Math.imul(ge,Le)|0,f=f+Math.imul(ge,St)|0,f=f+Math.imul(Fe,Le)|0,S=S+Math.imul(Fe,St)|0,g=g+Math.imul(be,$e)|0,f=f+Math.imul(be,pt)|0,f=f+Math.imul(Pe,$e)|0,S=S+Math.imul(Pe,pt)|0;var di=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(Ie,Ue),f=Math.imul(Ie,Mt),f=f+Math.imul(He,Ue)|0,S=Math.imul(He,Mt),g=g+Math.imul(Te,Le)|0,f=f+Math.imul(Te,St)|0,f=f+Math.imul(st,Le)|0,S=S+Math.imul(st,St)|0,g=g+Math.imul(ge,$e)|0,f=f+Math.imul(ge,pt)|0,f=f+Math.imul(Fe,$e)|0,S=S+Math.imul(Fe,pt)|0;var hi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(Ie,Le),f=Math.imul(Ie,St),f=f+Math.imul(He,Le)|0,S=Math.imul(He,St),g=g+Math.imul(Te,$e)|0,f=f+Math.imul(Te,pt)|0,f=f+Math.imul(st,$e)|0,S=S+Math.imul(st,pt)|0;var pi=(w+g|0)+((f&8191)<<13)|0;w=(S+(f>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(Ie,$e),f=Math.imul(Ie,pt),f=f+Math.imul(He,$e)|0,S=Math.imul(He,pt);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]=Yn,M[2]=Qn,M[3]=ei,M[4]=ti,M[5]=ri,M[6]=ni,M[7]=ii,M[8]=si,M[9]=oi,M[10]=ai,M[11]=ui,M[12]=ci,M[13]=li,M[14]=fi,M[15]=di,M[16]=hi,M[17]=pi,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 pe={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(pe[a])return pe[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 pe[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)}),yI="3.7.8",wz=yI,gu=typeof Buffer=="function",sI=typeof TextDecoder=="function"?new TextDecoder:void 0,oI=typeof TextEncoder=="function"?new TextEncoder:void 0,Mz="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Ic=Array.prototype.slice.call(Mz),hd=(t=>{let e={};return t.forEach((r,n)=>e[r]=n),e})(Ic),Sz=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,zr=String.fromCharCode.bind(String),aI=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),_I=t=>t.replace(/=/g,"").replace(/[+\/]/g,e=>e=="+"?"-":"_"),vI=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),bI=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+=Ic[e>>18&63]+Ic[e>>12&63]+Ic[e>>6&63]+Ic[e&63]}return o?s.slice(0,o-3)+"===".substring(o):s},jy=typeof btoa=="function"?t=>btoa(t):gu?t=>Buffer.from(t,"binary").toString("base64"):bI,Oy=gu?t=>Buffer.from(t).toString("base64"):t=>{let e=[];for(let r=0,n=t.length;r<n;r+=4096)e.push(zr.apply(null,t.subarray(r,r+4096)));return jy(e.join(""))},gd=(t,e=!1)=>e?_I(Oy(t)):Oy(t),kz=t=>{if(t.length<2){var e=t.charCodeAt(0);return e<128?t:e<2048?zr(192|e>>>6)+zr(128|e&63):zr(224|e>>>12&15)+zr(128|e>>>6&63)+zr(128|e&63)}else{var e=65536+(t.charCodeAt(0)-55296)*1024+(t.charCodeAt(1)-56320);return zr(240|e>>>18&7)+zr(128|e>>>12&63)+zr(128|e>>>6&63)+zr(128|e&63)}},Oz=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,wI=t=>t.replace(Oz,kz),uI=gu?t=>Buffer.from(t,"utf8").toString("base64"):oI?t=>Oy(oI.encode(t)):t=>jy(wI(t)),fu=(t,e=!1)=>e?_I(uI(t)):uI(t),cI=t=>fu(t,!0),Ez=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Az=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 zr((r>>>10)+55296)+zr((r&1023)+56320);case 3:return zr((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return zr((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},MI=t=>t.replace(Ez,Az),SI=t=>{if(t=t.replace(/\s+/g,""),!Sz.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=hd[t.charAt(s++)]<<18|hd[t.charAt(s++)]<<12|(r=hd[t.charAt(s++)])<<6|(n=hd[t.charAt(s++)]),r===64?i.push(zr(e>>16&255)):n===64?i.push(zr(e>>16&255,e>>8&255)):i.push(zr(e>>16&255,e>>8&255,e&255));return i.join("")},Ny=typeof atob=="function"?t=>atob(vI(t)):gu?t=>Buffer.from(t,"base64").toString("binary"):SI,kI=gu?t=>aI(Buffer.from(t,"base64")):t=>aI(Ny(t).split("").map(e=>e.charCodeAt(0))),OI=t=>kI(EI(t)),Iz=gu?t=>Buffer.from(t,"base64").toString("utf8"):sI?t=>sI.decode(kI(t)):t=>MI(Ny(t)),EI=t=>vI(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),Ey=t=>Iz(EI(t)),Tz=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)},AI=t=>({value:t,enumerable:!1,writable:!0,configurable:!0}),II=function(){let t=(e,r)=>Object.defineProperty(String.prototype,e,AI(r));t("fromBase64",function(){return Ey(this)}),t("toBase64",function(e){return fu(this,e)}),t("toBase64URI",function(){return fu(this,!0)}),t("toBase64URL",function(){return fu(this,!0)}),t("toUint8Array",function(){return OI(this)})},TI=function(){let t=(e,r)=>Object.defineProperty(Uint8Array.prototype,e,AI(r));t("toBase64",function(e){return gd(this,e)}),t("toBase64URI",function(){return gd(this,!0)}),t("toBase64URL",function(){return gd(this,!0)})},xz=()=>{II(),TI()},wy={version:yI,VERSION:wz,atob:Ny,atobPolyfill:SI,btoa:jy,btoaPolyfill:bI,fromBase64:Ey,toBase64:fu,encode:fu,encodeURI:cI,encodeURL:cI,utob:wI,btou:MI,decode:Ey,isValid:Tz,fromUint8Array:gd,toUint8Array:OI,extendString:II,extendUint8Array:TI,extendBuiltins:xz},Pz=(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))(Pz||{}),Cz=(t=>(t.InvalidTickEvent="InvalidTickEvent",t.InvalidPositionObject="InvalidPositionObject",t.InvalidPositionRewardObject="InvalidPositionRewardObject",t.InvalidParams="InvalidParams",t.FetchError="FetchError",t))(Cz||{}),jz=(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))(jz||{}),Nz=(t=>(t.ClmmVestNotSet="ClmmVestNotSet",t.ClmmVestFetchError="ClmmVestFetchError",t))(Nz||{}),Dz=(t=>(t.NotFoundPartnerObject="NotFoundPartnerObject",t.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",t))(Dz||{}),Bz=(t=>(t.InvalidConfig="InvalidConfig",t.InvalidConfigHandle="InvalidConfigHandle",t.InvalidSimulateAccount="InvalidSimulateAccount",t))(Bz||{}),Rz=(t=>(t.InvalidSendAddress="InvalidSendAddress",t.InvalidRecipientAddress="InvalidRecipientAddress",t.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",t.InsufficientBalance="InsufficientBalance",t.InvalidTarget="InvalidTarget",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t))(Rz||{}),Uz=(t=>(t.InvalidCoin="InvalidCoin",t.NotFoundPath="NotFoundPath",t.NoDowngradeNeedParams="NoDowngradeNeedParams",t.InvalidSwapCountUrl="InvalidSwapCountUrl",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t.InvalidServerResponse="InvalidServerResponse",t))(Uz||{}),Lz=(t=>(t.InvalidType="InvalidType",t))(Lz||{}),PI=class extends xI.BaseError{constructor(t,e,r){super(t,e||"UnknownError",r)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},Us=(t,e,r)=>{throw new PI(e.message,t,r)},At=(t,e,r)=>{throw new PI(e,t,r)},$z=class{constructor(t){this._cache={},this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=(0,Xe.getPackagerConfigs)(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}=(0,Xe.getPackagerConfigs)(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((0,Xe.normalizeCoinType)(u)===(0,Xe.normalizeCoinType)(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,Xe.CACHE_TIME_24H)}else console.log(`not found ${o}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:r}=(0,Xe.getPackagerConfigs)(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")&&At("FetchError",`when getCoinConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[Xe.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let d=this.buildCoinConfig(c,e);this.updateCache(`${r}_${d.address}_getCoinConfig`,d,Xe.CACHE_TIME_24H),u.push({...d})}),this.updateCache(n,u,Xe.CACHE_TIME_24H),u}async getCoinConfig(t,e=!1,r=!0){let{coin_list_handle:n}=(0,Xe.getPackagerConfigs)(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:(0,Xe.fixCoinType)(t)}}});(o.error!=null||o.data?.content?.dataType!=="moveObject")&&At("FetchError",`when getCoinConfig get object error: ${o.error}, please check the rpc and contracts address config.`,{[Xe.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let u=this.buildCoinConfig(o,r);return this.updateCache(i,u,Xe.CACHE_TIME_24H),u}buildCoinConfig(t,e=!0){let r=(0,Xe.getObjectFields)(t);r=r.value.fields;let n={...r};return n.id=(0,Xe.getObjectId)(t),n.address=(0,Xe.extractStructTagFromType)(r.coin_type.fields.name).full_address,r.pyth_id&&(n.pyth_id=Nr(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}=(0,Xe.getPackagerConfigs)(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")&&At("FetchError",`when getClmmPoolsConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[Xe.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let d=this.buildClmmPoolConfig(c,e);this.updateCache(`${d.pool_address}_getClmmPoolConfig`,d,Xe.CACHE_TIME_24H),u.push({...d})}),this.updateCache(n,u,Xe.CACHE_TIME_24H),u}async getClmmPoolConfig(t,e=!1,r=!0){let{clmm_pools_handle:n}=(0,Xe.getPackagerConfigs)(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,Xe.CACHE_TIME_24H),u}buildClmmPoolConfig(t,e=!0){let r=(0,Xe.getObjectFields)(t);r=r.value.fields;let n={...r};return n.id=(0,Xe.getObjectId)(t),n.pool_address=Nr(r.pool_address),this.transformExtensions(n,r.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:r}=(0,Xe.getPackagerConfigs)(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")&&At("FetchError",`when getCoinConfigs get objects error: ${c.error}, please check the rpc and contracts address config.`,{[Xe.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let d=this.buildLaunchpadPoolConfig(c,e);this.updateCache(`${d.pool_address}_getLaunchpadPoolConfig`,d,Xe.CACHE_TIME_24H),u.push({...d})}),this.updateCache(n,u,Xe.CACHE_TIME_24H),u}async getLaunchpadPoolConfig(t,e=!1,r=!0){let{launchpad_pools_handle:n}=(0,Xe.getPackagerConfigs)(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,Xe.CACHE_TIME_24H),u}buildLaunchpadPoolConfig(t,e=!0){let r=(0,Xe.getObjectFields)(t);r=r.value.fields;let n={...r};n.id=(0,Xe.getObjectId)(t),n.pool_address=Nr(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(wy.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=wy.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(wy.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=(0,Xe.getObjectPreviousTransactionDigest)(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((0,Xe.extractStructTagFromType)(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,Xe.CACHE_TIME_24H),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")&&At("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${r.error}, please check the rpc and contracts address config.`,{[Xe.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let n=(0,Xe.getObjectFields)(r),i=(0,Xe.getObjectType)(r);switch((0,Xe.extractStructTagFromType)(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=Xe.CACHE_TIME_5MIN){let n=this._cache[t];n?(n.overdue_time=(0,Xe.getFutureTime)(r),n.value=e):n=new Xe.CachedContent(e,(0,Xe.getFutureTime)(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}}},Fz=Ls($s()),qz="position_liquidity_snapshot",Vz=(t=>(t.Deleted="Deleted",t.Exists="Exists",t.NotExists="NotExists",t))(Vz||{}),zz=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],us=Ls($s()),Gz=Ls($s()),Hz="partner",pd="pool_script",du="pool_script_v2",CI="pool_script_v3",jI="router",Wz="router_with_partner",pu="fetcher_script";var Kz="utils";var Xz=Ls($s()),lu=9e15,Co=1e9,Ay="0123456789abcdef",bd="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",wd="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Iy={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-lu,maxE:lu,crypto:!1},NI,Rs,ht=!0,kd="[DecimalError] ",Po=kd+"Invalid argument: ",DI=kd+"Precision limit exceeded",BI=kd+"crypto unavailable",RI="[object Decimal]",un=Math.floor,Cr=Math.pow,Jz=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Zz=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Yz=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,UI=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Bi=1e7,nt=7,Qz=9007199254740991,eG=bd.length-1,Ty=wd.length-1,de={toStringTag:RI};de.absoluteValue=de.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),Je(t)};de.ceil=function(){return Je(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())+nt,n.rounding=1,r=tG(n,VI(n,r)),n.precision=t,n.rounding=e,Je(Rs==2||Rs==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(ht=!1,s=p.s*Cr(p.s*p,1/3),!s||Math.abs(s)==1/0?(r=Gr(p.d),t=p.e,(s=(t-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=Cr(r,1/3),t=un((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=Vt(d.plus(p).times(u),d.plus(c),o+2,1),Gr(u.d).slice(0,o)===(r=Gr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(Je(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")&&(Je(n,t+1,1),e=!n.times(n).times(n).eq(p));break}return ht=!0,Je(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-un(this.e/nt))*nt,t=e[t],t)for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r};de.dividedBy=de.div=function(t){return Vt(this,new this.constructor(t))};de.dividedToIntegerBy=de.divToInt=function(t){var e=this,r=e.constructor;return Je(Vt(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 Je(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/Ed(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),s=mu(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 Je(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=mu(s,2,i,i,!0);else{t=1.4*Math.sqrt(n),t=t>16?16:t|0,i=i.times(1/Ed(5,t)),i=mu(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,Je(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,Vt(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()?cs(e,n,i):new e(0):new e(NaN):t.isZero()?cs(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,ht=!1,r=r.times(r).minus(1).sqrt().plus(r),ht=!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,ht=!1,r=r.times(r).plus(1).sqrt().plus(r),ht=!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?Je(new s(i),t,e,!0):(s.precision=r=n-i.e,i=Vt(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=cs(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<=Ty)return o=cs(p,_+4,b).times(.25),o.s=d.s,o}else{if(!d.s)return new p(NaN);if(_+4<=Ty)return o=cs(p,_+4,b).times(.5),o.s=d.s,o}for(p.precision=u=_+10,p.rounding=1,r=Math.min(28,u/nt+2|0),t=r;t;--t)d=d.div(d.times(d).plus(1).sqrt().plus(1));for(ht=!1,e=Math.ceil(u/nt),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)),ht=!0,Je(o,p.precision=_,p.rounding=b,!0)};de.isFinite=function(){return!!this.d};de.isInteger=de.isInt=function(){return!!this.d&&un(this.e/nt)>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(ht=!1,u=_+O,o=xo(d,u),n=e?Md(p,u+10):xo(t,u),c=Vt(o,n,u,1),Tc(c.d,i=_,b))do if(u+=10,o=xo(d,u),n=e?Md(p,u+10):xo(t,u),c=Vt(o,n,u,1),!s){+Gr(c.d).slice(i+1,i+15)+1==1e14&&(c=Je(c,_+1,0));break}while(Tc(c.d,i+=10,b));return ht=!0,Je(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 ht?Je(t,u,c):t}if(r=un(t.e/nt),p=un(O.e/nt),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/nt),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]=Bi-1;--d[i],d[n]+=Bi}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=Od(d,r),ht?Je(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]?Je(new n(r),n.precision,n.rounding):(ht=!1,n.modulo==9?(e=Vt(r,t.abs(),0,3,1),e.s*=t.s):e=Vt(r,t,0,n.modulo,1),e=e.times(t),ht=!0,r.minus(e))};de.naturalExponential=de.exp=function(){return xy(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,Je(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(_)),ht?Je(t,u,c):t;if(s=un(_.e/nt),n=un(t.e/nt),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/nt),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)/Bi|0,d[i]%=Bi;for(e&&(d.unshift(e),++n),o=d.length;d[--o]==0;)d.pop();return t.d=d,t.e=Od(d,n),ht?Je(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=LI(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e};de.round=function(){var t=this,e=t.constructor;return Je(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())+nt,n.rounding=1,r=nG(n,VI(n,r)),n.precision=t,n.rounding=e,Je(Rs>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(ht=!1,d=Math.sqrt(+o),d==0||d==1/0?(e=Gr(u),(e.length+c)%2==0&&(e+="0"),d=Math.sqrt(e),c=un((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(Vt(o,s,r+2,1)).times(.5),Gr(s.d).slice(0,r)===(e=Gr(n.d)).slice(0,r))if(e=e.slice(r-3,r+1),e=="9999"||!i&&e=="4999"){if(!i&&(Je(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")&&(Je(n,c+1,1),t=!n.times(n).eq(o));break}return ht=!0,Je(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=Vt(r,new n(1).minus(r.times(r)).sqrt(),t+10,0),n.precision=t,n.rounding=e,Je(Rs==2||Rs==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=un(p.e/nt)+un(t.e/nt),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%Bi|0,e=u/Bi|0;s[i]=(s[i]+e)%Bi|0}for(;!s[--o];)s.pop();return e?++r:s.shift(),t.d=s,t.e=Od(s,r),ht?Je(t,_.precision,_.rounding):t};de.toBinary=function(t,e){return Dy(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:(On(t,0,Co),e===void 0?e=n.rounding:On(e,0,8),Je(r,t+r.e+1,e))};de.toExponential=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ls(n,!0):(On(t,0,Co),e===void 0?e=i.rounding:On(e,0,8),n=Je(new i(n),t+1,e),r=ls(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=ls(i):(On(t,0,Co),e===void 0?e=s.rounding:On(e,0,8),n=Je(new s(i),t+i.e+1,e),r=ls(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=LI(T)-O.e-1,o=s%nt,e.d[0]=Cr(10,o<0?nt+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(ht=!1,u=new x(Gr(T)),p=x.precision,x.precision=s=T.length*nt*2;_=Vt(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=Vt(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=Vt(d,n,s,1).minus(O).abs().cmp(Vt(c,r,s,1).minus(O).abs())<1?[d,n]:[c,r],x.precision=p,ht=!0,b};de.toHexadecimal=de.toHex=function(t,e){return Dy(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:On(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]?(ht=!1,r=Vt(r,t,0,e,1).times(t),ht=!0,Je(r)):(t.s=r.s,r=t),r};de.toNumber=function(){return+this};de.toOctal=function(t,e){return Dy(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(Cr(+u,d));if(u=new c(u),u.eq(1))return u;if(n=c.precision,s=c.rounding,t.eq(1))return Je(u,n,s);if(e=un(t.e/nt),e>=t.d.length-1&&(r=d<0?-d:d)<=Qz)return i=$I(c,u,r,n),t.s<0?new c(1).div(i):Je(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=Cr(+u,d),e=r==0||!isFinite(r)?un(d*(Math.log("0."+Gr(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):(ht=!1,c.rounding=u.s=1,r=Math.min(12,(e+"").length),i=xy(t.times(xo(u,n+r)),n),i.d&&(i=Je(i,n+5,1),Tc(i.d,n,s)&&(e=n+10,i=Je(xy(t.times(xo(u,e+r)),e),e+5,1),+Gr(i.d).slice(n+1,n+15)+1==1e14&&(i=Je(i,n+1,0)))),i.s=o,ht=!0,c.rounding=s,Je(i,n,s))};de.toPrecision=function(t,e){var r,n=this,i=n.constructor;return t===void 0?r=ls(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(On(t,1,Co),e===void 0?e=i.rounding:On(e,0,8),n=Je(new i(n),t,e),r=ls(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):(On(t,1,Co),e===void 0?e=n.rounding:On(e,0,8)),Je(new n(r),t,e)};de.toString=function(){var t=this,e=t.constructor,r=ls(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r};de.truncated=de.trunc=function(){return Je(new this.constructor(this),this.e+1,1)};de.valueOf=de.toJSON=function(){var t=this,e=t.constructor,r=ls(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};function Gr(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=nt-n.length,r&&(s+=To(r)),s+=n;o=t[e],n=o+"",r=nt-n.length,r&&(s+=To(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function On(t,e,r){if(t!==~~t||t<e||t>r)throw Error(Po+t)}function Tc(t,e,r,n){var i,s,o,u;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=nt,i=0):(i=Math.ceil((e+1)/nt),e%=nt),s=Cr(10,nt-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)==Cr(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)==Cr(10,e-3)-1,o}function yd(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]+=Ay.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 tG(t,e){var r,n,i;if(e.isZero())return e;n=e.d.length,n<32?(r=Math.ceil(n/3),i=(1/Ed(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),t.precision+=r,e=mu(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 Vt=(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,pe,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=Bi,O=nt,p=un(n.e/O)-un(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--;_++)pe=b*c+(a[_]||0),H[_]=pe/l|0,b=pe%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,NI=T;else{for(_=1,b=H[0];b>=10;b/=10)_++;R.e=_+p*O-1,Je(R,u?s+R.e+1:s,o,T)}return R}})();function Je(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+=nt,o=e,p=_[b=0],c=p/Cr(10,i-o-1)%10|0;else if(b=Math.ceil((s+1)/nt),u=_.length,b>=u)if(n){for(;u++<=b;)_.push(0);p=c=0,i=1,s%=nt,o=s-nt+1}else break e;else{for(p=u=_[b],i=1;u>=10;u/=10)i++;s%=nt,o=s-nt+i,c=o<0?0:p/Cr(10,i-o-1)%10|0}if(n=n||e<0||_[b+1]!==void 0||(o<0?p:p%Cr(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/Cr(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]=Cr(10,(nt-e%nt)%nt),t.e=-e||0):_[0]=t.e=0,t;if(s==0?(_.length=b,u=1,b--):(_.length=b+1,u=Cr(10,nt-s),_[b]=o>0?(p/Cr(10,i-o)%Cr(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]==Bi&&(_[0]=1));break}else{if(_[b]+=u,_[b]!=Bi)break;_[b--]=0,u=1}for(s=_.length;_[--s]===0;)_.pop()}return ht&&(t.e>O.maxE?(t.d=null,t.e=NaN):t.e<O.minE&&(t.e=0,t.d=[0])),t}function ls(t,e,r){if(!t.isFinite())return qI(t);var n,i=t.e,s=Gr(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 Od(t,e){var r=t[0];for(e*=nt;r>=10;r/=10)e++;return e}function Md(t,e,r){if(e>eG)throw ht=!0,r&&(t.precision=r),Error(DI);return Je(new t(bd),e,1,!0)}function cs(t,e,r){if(e>Ty)throw Error(DI);return Je(new t(wd),e,r,!0)}function LI(t){var e=t.length-1,r=e*nt+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 $I(t,e,r,n){var i,s=new t(1),o=Math.ceil(n/nt+4);for(ht=!1;;){if(r%2&&(s=s.times(e),fI(s.d,o)&&(i=!0)),r=un(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}e=e.times(e),fI(e.d,o)}return ht=!0,s}function lI(t){return t.d[t.d.length-1]&1}function FI(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 xy(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?(ht=!1,c=T):c=e,u=new b(.03125);t.e>-2;)t=t.times(u),_+=5;for(n=Math.log(Cr(2,_))/Math.LN10*2+5|0,c+=n,r=s=o=new b(1),b.precision=c;;){if(s=Je(s.times(t),c,1),r=r.times(++p),u=o.plus(Vt(s,r,c,1)),Gr(u.d).slice(0,c)===Gr(o.d).slice(0,c)){for(i=_;i--;)o=Je(o.times(o),c,1);if(e==null)if(d<3&&Tc(o.d,c-n,O,d))b.precision=c+=10,r=s=u=new b(1),p=0,d++;else return Je(o,b.precision=T,O,ht=!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?(ht=!1,p=J):p=e,R.precision=p+=T,r=Gr(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=Gr(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=Md(R,p+2,J).times(s+""),x=xo(new R(n+"."+r.slice(1)),p-T).plus(d),R.precision=J,e==null?Je(x,J,H,ht=!0):x;for(_=x,c=o=x=Vt(x.minus(1),x.plus(1),p,1),b=Je(x.times(x),p,1),i=3;;){if(o=Je(o.times(b),p,1),d=c.plus(Vt(o,new R(i),p,1)),Gr(d.d).slice(0,p)===Gr(c.d).slice(0,p))if(c=c.times(2),s!==0&&(c=c.plus(Md(R,p+2,J).times(s+""))),c=Vt(c,new R(O),p,1),e==null)if(Tc(c.d,p-T,H,u))R.precision=p+=T,d=o=x=Vt(_.minus(1),_.plus(1),p,1),b=Je(x.times(x),p,1),i=u=1;else return Je(c,R.precision=J,H,ht=!0);else return R.precision=J,c;c=d,i+=2}}function qI(t){return String(t.s*t.s/0)}function _d(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)%nt,r<0&&(n+=nt),n<i){for(n&&t.d.push(+e.slice(0,n)),i-=nt;n<i;)t.d.push(+e.slice(n,n+=nt));e=e.slice(n),n=nt-e.length}else n-=i;for(;n--;)e+="0";t.d.push(+e),ht&&(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 rG(t,e){var r,n,i,s,o,u,c,d,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),UI.test(e))return _d(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(Zz.test(e))r=16,e=e.toLowerCase();else if(Jz.test(e))r=2;else if(Yz.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=$I(n,new n(r),s,s*2)),d=yd(e,r,Bi),p=d.length-1,s=p;d[s]===0;--s)d.pop();return s<0?new n(t.s*0):(t.e=Od(d,p),t.d=d,ht=!1,o&&(t=Vt(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?Cr(2,c):xc.pow(2,c))),ht=!0,t)}function nG(t,e){var r,n=e.d.length;if(n<3)return e.isZero()?e:mu(t,2,e,e);r=1.4*Math.sqrt(n),r=r>16?16:r|0,e=e.times(1/Ed(5,r)),e=mu(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 mu(t,e,r,n,i){var s,o,u,c,d=1,p=t.precision,_=Math.ceil(p/nt);for(ht=!1,c=r.times(r),u=new t(n);;){if(o=Vt(u.times(c),new t(e++*e++),p,1),u=i?n.plus(o):n.minus(o),n=Vt(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 ht=!0,o.d.length=_+1,o}function Ed(t,e){for(var r=t;--e;)r*=t;return r}function VI(t,e){var r,n=e.s<0,i=cs(t,t.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return Rs=n?4:1,e;if(r=e.divToInt(i),r.isZero())Rs=n?3:2;else{if(e=e.minus(r.times(i)),e.lte(s))return Rs=lI(r)?n?2:3:n?4:1,e;Rs=lI(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?(On(r,1,Co),n===void 0?n=O.rounding:On(n,0,8)):(r=O.precision,n=O.rounding),!t.isFinite())p=qI(t);else{for(p=ls(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=yd(ls(b),10,i),b.e=b.d.length),_=yd(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=Vt(t,b,r,n,0,i),_=t.d,s=t.e,d=NI),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+=Ay.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(_=yd(p,i,e),c=_.length;!_[c-1];--c);for(o=1,p="1.";o<c;o++)p+=Ay.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 fI(t,e){if(t.length>e)return t.length=e,!0}function iG(t){return new this(t).abs()}function sG(t){return new this(t).acos()}function oG(t){return new this(t).acosh()}function aG(t,e){return new this(t).plus(e)}function uG(t){return new this(t).asin()}function cG(t){return new this(t).asinh()}function lG(t){return new this(t).atan()}function fG(t){return new this(t).atanh()}function dG(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=cs(this,s,1).times(e.s>0?.25:.75),r.s=t.s):!e.d||t.isZero()?(r=e.s<0?cs(this,n,i):new this(0),r.s=t.s):!t.d||e.isZero()?(r=cs(this,s,1).times(.5),r.s=t.s):e.s<0?(this.precision=s,this.rounding=1,r=this.atan(Vt(t,e,s,1)),e=cs(this,s,1),this.precision=n,this.rounding=i,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(Vt(t,e,s,1)),r}function hG(t){return new this(t).cbrt()}function pG(t){return Je(t=new this(t),t.e+1,2)}function mG(t,e,r){return new this(t).clamp(e,r)}function gG(t){if(!t||typeof t!="object")throw Error(kd+"Object expected");var e,r,n,i=t.defaults===!0,s=["precision",1,Co,"rounding",0,8,"toExpNeg",-lu,0,"toExpPos",0,lu,"maxE",0,lu,"minE",-lu,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],i&&(this[r]=Iy[r]),(n=t[r])!==void 0)if(un(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]=Iy[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(BI);else this[r]=!1;else throw Error(Po+r+": "+n);return this}function yG(t){return new this(t).cos()}function _G(t){return new this(t).cosh()}function zI(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,dI(s)){d.s=s.s,ht?!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++;ht?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 _d(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),UI.test(s)?_d(d,s):rG(d,s);if(c==="bigint")return s<0?(s=-s,d.s=-1):d.s=1,_d(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=gG,i.clone=zI,i.isDecimal=dI,i.abs=iG,i.acos=sG,i.acosh=oG,i.add=aG,i.asin=uG,i.asinh=cG,i.atan=lG,i.atanh=fG,i.atan2=dG,i.cbrt=hG,i.ceil=pG,i.clamp=mG,i.cos=yG,i.cosh=_G,i.div=vG,i.exp=bG,i.floor=wG,i.hypot=MG,i.ln=SG,i.log=kG,i.log10=EG,i.log2=OG,i.max=AG,i.min=IG,i.mod=TG,i.mul=xG,i.pow=PG,i.random=CG,i.round=jG,i.sign=NG,i.sin=DG,i.sinh=BG,i.sqrt=RG,i.sub=UG,i.sum=LG,i.tan=$G,i.tanh=FG,i.trunc=qG,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 vG(t,e){return new this(t).div(e)}function bG(t){return new this(t).exp()}function wG(t){return Je(t=new this(t),t.e+1,3)}function MG(){var t,e,r=new this(0);for(ht=!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 ht=!0,new this(1/0);r=e}return ht=!0,r.sqrt()}function dI(t){return t instanceof xc||t&&t.toStringTag===RI||!1}function SG(t){return new this(t).ln()}function kG(t,e){return new this(t).log(e)}function OG(t){return new this(t).log(2)}function EG(t){return new this(t).log(10)}function AG(){return FI(this,arguments,-1)}function IG(){return FI(this,arguments,1)}function TG(t,e){return new this(t).mod(e)}function xG(t,e){return new this(t).mul(e)}function PG(t,e){return new this(t).pow(e)}function CG(t){var e,r,n,i,s=0,o=new this(1),u=[];if(t===void 0?t=this.precision:On(t,1,Co),n=Math.ceil(t/nt),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(BI);else for(;s<n;)u[s++]=Math.random()*1e7|0;for(n=u[--s],t%=nt,n&&t&&(i=Cr(10,nt-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-=nt)u.shift();for(n=1,i=u[0];i>=10;i/=10)n++;n<nt&&(r-=nt-n)}return o.e=r,o.d=u,o}function jG(t){return Je(t=new this(t),t.e+1,this.rounding)}function NG(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function DG(t){return new this(t).sin()}function BG(t){return new this(t).sinh()}function RG(t){return new this(t).sqrt()}function UG(t,e){return new this(t).sub(e)}function LG(){var t=0,e=arguments,r=new this(e[t]);for(ht=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return ht=!0,Je(r,this.precision,this.rounding)}function $G(t){return new this(t).tan()}function FG(t){return new this(t).tanh()}function qG(t){return Je(t=new this(t),t.e+1,1)}de[Symbol.for("nodejs.util.inspect.custom")]=de.toString;de[Symbol.toStringTag]="Decimal";var xc=de.constructor=zI(Iy);bd=new xc(bd);wd=new xc(wd);var Br=xc;function Sd(t){let e=Ut.CoinAssist.isSuiCoin(t.coin_type_a),r=Ut.CoinAssist.isSuiCoin(t.coin_type_b);return{is_adjust_coin_a:e,is_adjust_coin_b:r}}function VG(t,e){return Br.ceil(Br(t).div(1+e)).toString()}var ma=class{static createCollectRewarderAndFeeParams(t,e,r,n,i,s){i===void 0&&(i=[...n]),s===void 0&&(s=[...n]);let o=(0,Ut.normalizeCoinType)(r.coin_type_a),u=(0,Ut.normalizeCoinType)(r.coin_type_b);if(r.collect_fee){let d=Ut.CoinAssist.buildCoinForAmount(e,i,BigInt(0),o,!1);i=d.remain_coins;let p=Ut.CoinAssist.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((0,Ut.normalizeCoinType)(d)){case o:c.push(Ut.CoinAssist.buildCoinForAmount(e,i,BigInt(0),d,!1).target_coin);break;case u:c.push(Ut.CoinAssist.buildCoinForAmount(e,s,BigInt(0),d,!1).target_coin);break;default:c.push(Ut.CoinAssist.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=Ut.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,r).selected_coins,s=Ut.CoinAssist.calculateTotalBalance(e);if(i.length===0&&At("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${s}`),s-r>1e9)return{fixAmount:r};let o=await t.FullClient.calculationTxGas(ft.from(n));if(Ut.CoinAssist.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&&At("InsufficientBalance","gas Insufficient balance");let c=new ft;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}=Sd(r),c=u?r.amount_a:r.amount_b,d=await this.adjustTransactionForGas(t,Ut.CoinAssist.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 ft;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?Ut.CoinAssist.buildCoinForAmountInterval(t,s,{amount_second:BigInt(VG(r,n)),amount_first:BigInt(r)},i,o,u):Ut.CoinAssist.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=Ut.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new Xz.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=(0,Ut.getPackagerConfigs)(c),_=n.is_open?[t.object(p.global_config_id),t.object(n.pool_id),t.pure.u32(Number((0,Ut.asUintN)(BigInt(n.tick_lower)).toString())),t.pure.u32(Number((0,Ut.asUintN)(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(Ut.CLOCK_ADDRESS)]:[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(Ut.CLOCK_ADDRESS)];return t.moveCall({target:`${d.published_at}::${du}::${u}`,typeArguments:o,arguments:_}),t}static checkCoinThreshold(t,e,r,n,i,s){e&&r.moveCall({target:`${t.sdkOptions.integrate.published_at}::${jI}::check_coin_threshold`,typeArguments:[s],arguments:[n,r.pure.u64(i)]})}},cu=class Io{static getDefaultSqrtPriceLimit(e){return new Gz.default(e?Ct.MIN_SQRT_PRICE:Ct.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(e){return e?Ct.ZERO:Ct.U64_MAX}static async buildSwapTransactionForGas(e,r,n,i){let s=this.buildSwapTransaction(e,r,n);s.setSender(e.getSenderAddress());let o=await this.adjustTransactionForGas(e,Ct.CoinAssist.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=Ct.CoinAssist.buildCoinForAmount(s,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a),p=Ct.CoinAssist.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}=(0,Ct.getPackagerConfigs)(o);p===void 0&&At("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(Ct.CLOCK_ADDRESS)]:[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(Ct.CLOCK_ADDRESS)];return e.moveCall({target:`${u.published_at}::${du}::${b}`,typeArguments:d,arguments:O}),e}static async adjustTransactionForGas(e,r,n,i){i.setSender(e.getSenderAddress());let s=Ct.CoinAssist.selectCoinAssetGreaterThanOrEqual(r,n).selected_coins,o=Ct.CoinAssist.calculateTotalBalance(r);if(s.length===0&&At("InsufficientBalance",`Insufficient balance exceed amount ${n} real amount ${o}`),o-n>1e9)return{fixAmount:n};let u=await e.FullClient.calculationTxGas(i);if(Ct.CoinAssist.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&&At("InsufficientBalance","gas Insufficient balance");let d=new ft;return{fixAmount:n,newTx:d}}}return{fixAmount:n}}static buildSwapTransaction(e,r,n){let i=new ft;i.setSender(e.getSenderAddress());let s=Ct.CoinAssist.buildCoinForAmount(i,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1),o=Ct.CoinAssist.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=(0,Ct.adjustForSlippage)(o,n.slippage,!n.by_amount_in);r.amount_limit=u.toString()}catch(s){Us("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,Ct.CoinAssist.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=Ct.CoinAssist.buildCoinForAmount(s,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1,!0),_=Ct.CoinAssist.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 ft;i.setSender(e.getSenderAddress());let s=Ct.CoinAssist.buildCoinForAmount(i,n,r.a2b?BigInt(r.by_amount_in?r.amount:r.amount_limit):BigInt(0),r.coin_type_a,!1,!0),o=Ct.CoinAssist.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}=(0,Ct.getPackagerConfigs)(u);p===void 0&&At("InvalidConfig","clmm.config.global_config_id is undefined");let _=n.swap_partner!==void 0,b=_?"swap_with_partner":"swap",O=_?Wz:jI,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(Ct.CLOCK_ADDRESS)]:[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(Ct.CLOCK_ADDRESS)],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);ma.checkCoinThreshold(e,n.by_amount_in,r,H,J,R)}return{tx:r,txRes:F}}};function zG(t){return{coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,current_sqrt_price:new us.default(t.current_sqrt_price),current_tick_index:t.current_tick_index,fee_growth_global_a:new us.default(t.fee_growth_global_a),fee_growth_global_b:new us.default(t.fee_growth_global_b),fee_protocol_coin_a:new us.default(t.fee_protocol_coin_a),fee_protocol_coin_b:new us.default(t.fee_protocol_coin_b),fee_rate:new us.default(t.fee_rate),liquidity:new us.default(t.liquidity),tick_indexes:[],tick_spacing:Number(t.tick_spacing),ticks:[],collection_name:""}}function GG(t,e,r,n,i,s){if(r===It.ZERO)return{amount_in:It.ZERO,amount_out:It.ZERO,next_sqrt_price:e,fee_amount:It.ZERO};let o=t.gte(e),u,c,d,p;if(s){let _=It.MathUtil.checkMulDivFloor(n,It.MathUtil.checkUnsignedSub(It.FEE_RATE_DENOMINATOR,i),It.FEE_RATE_DENOMINATOR,64),b=(0,It.getDeltaUpFromInput)(t,e,r,o);b.gt(_)?(u=_,p=It.MathUtil.checkUnsignedSub(n,_),d=(0,It.getNextSqrtPriceFromInput)(t,r,_,o)):(u=b,p=It.MathUtil.checkMulDivCeil(u,i,It.FEE_RATE_DENOMINATOR.sub(i),64),d=e),c=(0,It.getDeltaDownFromOutput)(t,d,r,o)}else{let _=(0,It.getDeltaDownFromOutput)(t,e,r,o);_.gt(n)?(c=n,d=(0,It.getNextSqrtPriceFromOutput)(t,r,n,o)):(c=_,d=e),u=(0,It.getDeltaUpFromInput)(t,d,r,o),p=It.MathUtil.checkMulDivCeil(u,i,It.FEE_RATE_DENOMINATOR.sub(i),64)}return{amount_in:u,amount_out:c,next_sqrt_price:d,fee_amount:p}}function HG(t,e,r,n,i){let s=r,o=n.liquidity,{current_sqrt_price:u}=n,c={amount_in:It.ZERO,amount_out:It.ZERO,fee_amount:It.ZERO,ref_amount:It.ZERO,next_sqrt_price:It.ZERO,cross_tick_num:0},d,p,_=cu.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=GG(u,d,o,s,n.fee_rate,e);if(O.amount_in.eq(It.ZERO)||(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 us.default(-1)),t?It.MathUtil.is_neg(p)?o=o.add(new us.default((0,It.asUintN)(BigInt(p.toString()),128))):o=o.add(p):It.MathUtil.is_neg(p)?o=o.sub(new us.default((0,It.asUintN)(BigInt(p.toString()),128))):o=o.sub(p),u=b.sqrt_price):u=O.next_sqrt_price,c.cross_tick_num+=1,s.eq(It.ZERO))break}return c.amount_in=c.amount_in.add(c.fee_amount),c.next_sqrt_price=u,c}var Di=Ls($s());function WG(t,e,r){let n=(0,ut.extractStructTagFromType)(t).name,i=(0,ut.extractStructTagFromType)(e).name;return`${n}-${i}[${r}]`}function My(t){let e=(0,ut.getMoveObjectType)(t),r=(0,ut.extractStructTagFromType)(e),n=(0,ut.getObjectFields)(t);n==null&&At("InvalidPoolObject",`Pool id ${(0,ut.getObjectId)(t)} not exists.`,{[ut.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let i=[];n.rewarder_manager.fields.rewarders.forEach(c=>{let{emissions_per_second:d}=c.fields,p=ut.MathUtil.fromX64(new Di.default(d)),_=Math.floor(p.toNumber()*60*60*24);i.push({emissions_per_second:d,coin_type:(0,ut.extractStructTagFromType)(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:(0,ut.getObjectId)(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:(0,ut.asIntN)(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=WG(u.coin_type_a,u.coin_type_b,u.tick_spacing),u}function Sy(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&At("InvalidPositionObject",`Position not exists. Get Position error:${t.error}`,{[ut.DETAILS_KEYS.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=(0,ut.getObjectFields)(t);if(n){let o=(0,ut.getMoveObjectType)(t),u=(0,ut.getObjectOwner)(t);"nft"in n?(n=n.nft.fields,e.description=n.description,e.name=n.name,e.link=n.url):e=(0,ut.buildNFT)(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:(0,ut.asIntN)(BigInt(n.tick_lower_index.fields.bits)),tick_upper_index:(0,ut.asIntN)(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=(0,ut.getObjectDeletedResponse)(t);i&&(r.pos_object_id=i.objectId,r.position_status="Deleted");let s=(0,ut.getObjectNotExistsResponse)(t);return s&&(r.pos_object_id=s,r.position_status="NotExists"),r}function Py(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:(0,ut.asIntN)(BigInt(r)),tick_upper_index:(0,ut.asIntN)(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 ky(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&At("InvalidTickObject",`Tick not exists. Get tick data error:${t.error}`,{[ut.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let e=(0,ut.getObjectFields)(t).value.fields.value.fields;return{object_id:(0,ut.getObjectId)(t),index:(0,ut.asIntN)(BigInt(e.index.fields.bits)),sqrt_price:new Di.default(e.sqrt_price),liquidity_net:new Di.default(e.liquidity_net.fields.bits),liquidity_gross:new Di.default(e.liquidity_gross),fee_growth_outside_a:new Di.default(e.fee_growth_outside_a),fee_growth_outside_b:new Di.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function KG(t){(!t||!t.index||!t.sqrt_price||!t.liquidity_net||!t.liquidity_gross||!t.fee_growth_outside_a||!t.fee_growth_outside_b)&&At("InvalidTickFields","Invalid tick fields.",{[ut.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let e=(0,ut.asIntN)(BigInt(t.index.bits)),r=new Di.default(t.sqrt_price),n=new Di.default(t.liquidity_net.bits),i=new Di.default(t.liquidity_gross),s=new Di.default(t.fee_growth_outside_a),o=new Di.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 XG(t,e,r){let n=[],{timestampMs:i,events:s}=t,o=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((u,c)=>{let d=(0,ut.extractStructTagFromType)(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)&&((0,ut.d)(p.parsed_json.amount_a).gt(0)||(0,ut.d)(p.parsed_json.amount_b).gt(0))&&n.push(p);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":((0,ut.d)(p.parsed_json.amount_a).gt(0)||(0,ut.d)(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))&&(0,ut.d)(p.parsed_json.amount).gt(0)&&n.push(p);break;default:break}}}),n}function JG(t,e,r,n){let i=[],{timestampMs:s,events:o}=t;return o?.forEach((u,c)=>{let{name:d,address:p}=(0,ut.extractStructTagFromType)(u.type);if(zz.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 Cy(t,e,r,n){e.moveCall({target:`${t.sdkOptions.integrate.published_at}::${Kz}::transfer_coin_to_sender`,typeArguments:[n],arguments:[r]})}function ZG(t,e,r,n,i){i!=null?e.transferObjects([r],e.pure.address(i)):Cy(t,e,r,n)}var YG=1e4,hu=class{static parseClmmVestInfo(t){let e=(0,Hr.getObjectFields)(t),r=(0,Hr.getObjectType)(t),n=(0,Hr.extractStructTagFromType)(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:(0,Hr.d)(s.fields.percentage).div(YG).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:(0,Hr.fixCoinType)(t.coin_a.name,!1),coin_type_b:(0,Hr.fixCoinType)(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let e=(0,Hr.getObjectFields)(t);return{current_sqrt_price:e.current_sqrt_price,remove_percent:(0,Hr.d)(e.remove_percent).div(1e6).toString(),snapshots:{id:e.snapshots.fields.id.id,size:e.snapshots.fields.size}}}static parsePositionSnapshot(t){let e=(0,Hr.getObjectFields)(t),r=e.value.fields.value.fields;return{position_id:e.name,liquidity:r.liquidity,tick_lower_index:(0,Hr.asIntN)(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:(0,Hr.asIntN)(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}}},QG=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&&At("InvalidConfig",`when getPositionList get position objects error: ${o.error}, please check the rpc, contracts address config and position id.`,{[ve.DETAILS_KEYS.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:(0,ve.extractStructTagFromType)(p.coin_type_a).full_address,coin_type_b:(0,ve.extractStructTagFromType)(p.coin_type_b).full_address})})}catch(u){return Us("FetchError",u,{[ve.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return i.data=n,s&&this._sdk.updateCache(`${r}_getPoolImmutables`,n,ve.CACHE_TIME_24H),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")&&At("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let o=My(s);r.data.push(o);let u=`${o.id}_getPoolObject`;this._sdk.updateCache(u,o,ve.CACHE_TIME_24H)}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:qz}}),n=hu.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=hu.parsePositionSnapshot(u);o.push(c)}),n.position_snapshots=o}}return n}catch(r){return Us("InvalidPoolObject",r,{[ve.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[ve.DETAILS_KEYS.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=hu.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")&&At("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let i=My(n);e.push(i);let s=`${i.id}_getPoolObject`;this._sdk.updateCache(s,i,ve.CACHE_TIME_24H)}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")&&At("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getPool"});let o=My(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||At("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[ve.DETAILS_KEYS.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){Us("FetchError",u,{[ve.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[ve.DETAILS_KEYS.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((0,ve.isSortedSymbols)(Ve(t.coin_type_a),Ve(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((0,ve.isSortedSymbols)(Ve(t.coin_type_a),Ve(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=(0,ve.getObjectPreviousTransactionDigest)(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((0,ve.extractStructTagFromType)(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,ve.CACHE_TIME_24H)),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=(0,ve.createFullClient)(new Bs({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=JG(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=ve.TickMath.priceToSqrtPriceX64(s==="coin_a"?(0,ve.d)(e):(0,ve.d)(1).div(e),o,u),d=0,p=0;if(i.is_full_range)d=ve.TickUtil.getMinIndex(n),p=ve.TickUtil.getMaxIndex(n);else{let{min_price:H,max_price:J}=i;d=ve.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,ve.d)(H):(0,ve.d)(1).div(J),o,u,n),p=ve.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,ve.d)(J):(0,ve.d)(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}=ve.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(d,p,new Fz.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 ft,e.setSender(this.sdk.getSenderAddress());let{integrate:r,clmm_pool:n}=this.sdk.sdkOptions,i=(0,ve.getPackagerConfigs)(n),s=i.global_config_id,o=i.pools_id,u=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=ve.CoinAssist.buildCoinForAmount(e,u,BigInt(t.amount_a),t.coin_type_a,!1,!0),d=ve.CoinAssist.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((0,ve.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,ve.asUintN)(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(ve.CLOCK_ADDRESS)];return e.moveCall({target:`${r.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:p}),Cy(this._sdk,e,c.target_coin,t.coin_type_a),Cy(this._sdk,e,d.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new ft;let{clmm_pool:r}=this.sdk.sdkOptions,n=(0,ve.getPackagerConfigs)(r),i=n.global_config_id,s=n.pools_id,o=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),u=ve.CoinAssist.buildCoinForAmount(e,o,BigInt(t.amount_a),t.coin_type_a,!1,!0),c=ve.CoinAssist.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((0,ve.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,ve.asUintN)(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(ve.CLOCK_ADDRESS)],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 At("FetchError",`fetch coin ${r} metadata failed`,{[ve.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[ve.DETAILS_KEYS.REQUEST_PARAMS]:t});if(R===null)return At("FetchError",`fetch coin ${n} metadata failed`,{[ve.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[ve.DETAILS_KEYS.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 At("FetchError",`fetch coin ${e} metadata failed`,{[ve.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[ve.DETAILS_KEYS.REQUEST_PARAMS]:t});if(F===null)return At("FetchError",`fetch coin ${r} metadata failed`,{[ve.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[ve.DETAILS_KEYS.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((0,ve.asUintN)(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 ft,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}::${pu}::fetch_ticks`,arguments:o,typeArguments:n});let u=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:Ve("0x0")});return u.error!=null&&At("InvalidTickObjectId",`getTicks error code: ${u.error??"unknown error"}, please check config and tick object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getTicks",[ve.DETAILS_KEYS.REQUEST_PARAMS]:t}),u.events?.forEach(c=>{(0,ve.extractStructTagFromType)(c.type).name==="FetchTicksResultEvent"&&c.parsedJson.ticks.forEach(d=>{r.push(KG(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 ft,u=o.pure.vector("id",n.map(_=>_)),c=[o.object(t.pool_id),u,o.pure.u64(i)];o.moveCall({target:`${e.published_at}::${pu}::fetch_positions`,arguments:c,typeArguments:s});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:o,sender:Ve("0x0")});d.error!=null&&At("InvalidPositionRewardObject",`fetch position info error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[ve.DETAILS_KEYS.REQUEST_PARAMS]:t});let p=[];if(d?.events?.forEach(_=>{(0,ve.extractStructTagFromType)(_.type).name==="FetchPositionsEvent"&&_.parsedJson.positions.forEach(b=>{let O=Py(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=>{(0,ve.extractStructTagFromType)(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")&&At("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let i=ky(n);i!=null&&e.push(i)}return e}async getTickDataByIndex(t,e){let r={type:"u64",value:(0,ve.asUintN)(BigInt((0,ve.tickScore)(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:r});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&At("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),ky(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")&&At("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[ve.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),ky(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"&&At("NotFoundPartnerObject",`get partner by object id: ${t} error: ${r[0].error}`,{[ve.DETAILS_KEYS.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")&&At("InvalidPartnerRefFeeFields",`get coin by object id: ${u.data.objectId} error: ${u.error}`,{[ve.DETAILS_KEYS.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 ft,{clmm_pool:i}=this.sdk.sdkOptions,{global_config_id:s}=(0,ve.getPackagerConfigs)(i),o=[r],u=[n.object(s),n.object(t),n.object(e)];return n.moveCall({target:`${i.published_at}::${Hz}::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=(0,ve.getObjectFields)(e).position.fields.status;if(r)return r}catch(e){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",e)}}},md=Ls($s()),eH=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=(0,Ae.createFullClient)(new Bs({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=XG(p,_,o);c.data=[...c.data,...b]}),c.has_next_page=d.has_next_page,c.next_cursor=d.next_cursor,c}catch(d){Us("FetchError",d,{[Ae.DETAILS_KEYS.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((0,Ae.extractStructTagFromType)(o.data.type).full_address===this.buildPositionType()){let u=Sy(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=Sy(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=Sy(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=(0,Ae.getObjectFields)(r.data).value.fields.value;return Py(n)}catch(r){return Us("FetchError",r,{[Ae.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[Ae.DETAILS_KEYS.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=(0,Ae.deriveDynamicFieldIdByType)(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=(0,Ae.getObjectFields)(n.data).value.fields.value,s=Py(i);e.push(s)}catch(i){console.log("getPositionInfoList error",i)}}),e)}catch(e){return Us("FetchError",e,{[Ae.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[Ae.DETAILS_KEYS.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((0,Ae.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${pu}::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 ft;for(let u of t)this.buildFetchPosFee(u,n);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:Ve("0x0")});i.error!=null&&At("InvalidPoolObject",`fetch position fee error code: ${i.error??"unknown error"}, please check config and position and pool object ids`,{[Ae.DETAILS_KEYS.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}=Sd(t);if(t=t,t.fix_amount_a&&o||!t.fix_amount_a&&u)return r=await ma.buildAddLiquidityFixTokenForGas(this._sdk,s,t,e,r,n,i),r}return ma.buildAddLiquidityFixToken(this._sdk,s,t,r,n,i)}async createAddLiquidityPayload(t,e,r,n){let{integrate:i,clmm_pool:s}=this._sdk.sdkOptions,o=(0,Ae.asUintN)(BigInt(t.tick_lower)).toString(),u=(0,Ae.asUintN)(BigInt(t.tick_upper)).toString(),c=[t.coin_type_a,t.coin_type_b];e=e||new ft;let d=!Gs(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=Ae.CoinAssist.buildCoinForAmount(e,T,p,t.coin_type_a,!1,!0),O=Ae.CoinAssist.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}::${du}::open_position_with_liquidity`,typeArguments:c,arguments:[e.object((0,Ae.getPackagerConfigs)(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(Ae.CLOCK_ADDRESS)]});else{let T=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=ma.createCollectRewarderAndFeeParams(this._sdk,e,t,T,b.remain_coins,O.remain_coins),e.moveCall({target:`${i.published_at}::${du}::add_liquidity`,typeArguments:c,arguments:[e.object((0,Ae.getPackagerConfigs)(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(Ae.CLOCK_ADDRESS)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,i="remove_liquidity";e=e||new ft;let s=[t.coin_type_a,t.coin_type_b],o=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=ma.createCollectRewarderAndFeeParams(this._sdk,e,t,o);let u=[e.object((0,Ae.getPackagerConfigs)(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(Ae.CLOCK_ADDRESS)];return e.moveCall({target:`${n.published_at}::${pd}::${i}`,typeArguments:s,arguments:u}),e}async closePositionPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;e=e||new ft;let i=[t.coin_type_a,t.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=ma.createCollectRewarderAndFeeParams(this._sdk,e,t,s),e.moveCall({target:`${n.published_at}::${pd}::close_position`,typeArguments:i,arguments:[e.object((0,Ae.getPackagerConfigs)(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(Ae.CLOCK_ADDRESS)]}),e}openPositionPayload(t,e){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;e=e||new ft;let i=[t.coin_type_a,t.coin_type_b],s=(0,Ae.asUintN)(BigInt(t.tick_lower)).toString(),o=(0,Ae.asUintN)(BigInt(t.tick_upper)).toString(),u=[e.object((0,Ae.getPackagerConfigs)(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}::${pd}::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 ft;let s=await this.sdk.Pool.getPool(r,!1),o=Number(s.tick_spacing),u=0,c=0;if(t.is_full_range)u=Ae.TickUtil.getMinIndex(o),c=Ae.TickUtil.getMaxIndex(o);else{let{price_base_coin:_,min_price:b,max_price:O}=t;u=Ae.TickMath.priceToInitializeTickIndex(_==="coin_a"?(0,Ae.d)(b):(0,Ae.d)(1).div(O),t.coin_decimals_a,t.coin_decimals_b,o),c=Ae.TickMath.priceToInitializeTickIndex(_==="coin_a"?(0,Ae.d)(O):(0,Ae.d)(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((0,Ae.getPackagerConfigs)(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number((0,Ae.asUintN)(BigInt(u)))),e.pure.u32(Number((0,Ae.asUintN)(BigInt(c))))];return e.moveCall({target:`${i.published_at}::${pd}::open_position`,typeArguments:d,arguments:p}),e}async collectFeePayload(t,e,r,n){e=e||new ft;let i=r||Ae.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),s=n||Ae.CoinAssist.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((0,Ae.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),r,n];return e.moveCall({target:`${s.published_at}::${du}::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=Ae.TickUtil.getMinIndex(o),c=Ae.TickUtil.getMaxIndex(o);else{let{price_base_coin:F,min_price:R,max_price:H}=i;u=Ae.TickMath.priceToInitializeTickIndex(F==="coin_a"?(0,Ae.d)(R):(0,Ae.d)(1).div(H),i.coin_decimals_a,i.coin_decimals_b,o),c=Ae.TickMath.priceToInitializeTickIndex(F==="coin_a"?(0,Ae.d)(H):(0,Ae.d)(1).div(R),i.coin_decimals_a,i.coin_decimals_b,o)}if("liquidity"in t){let{liquidity:F}=t,R=Ae.TickMath.tickIndexToSqrtPriceX64(u),H=Ae.TickMath.tickIndexToSqrtPriceX64(c),{coin_amount_a:J,coin_amount_b:ee}=Ae.ClmmPoolUtil.getCoinAmountFromLiquidity(new md.default(F),new md.default(s.current_sqrt_price),R,H,!1),ae=(0,Ae.d)(J).mul(1+r).toFixed(0,Br.ROUND_UP),te=(0,Ae.d)(ee).mul(1+r).toFixed(0,Br.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}=Ae.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(u,c,new md.default(d),p,!0,r,new md.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 ft;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 At("InvalidParams","fix_amount_a is undefined",{[Ae.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[Ae.DETAILS_KEYS.REQUEST_PARAMS]:t});e=e||new ft;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((0,Ae.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),r,n];return e.moveCall({target:`${s.published_at}::${CI}::collect_fee`,typeArguments:o,arguments:u}),e}},hI=Ls($s()),tH=class{constructor(t){this._sdk=t,this.growthGlobal=[Lt.ZERO,Lt.ZERO,Lt.ZERO]}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=Lt.MathUtil.fromX64(new hI.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((0,Lt.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Lt.CLOCK_ADDRESS)];e.moveCall({target:`${n.published_at}::${pu}::fetch_position_rewards`,arguments:s,typeArguments:i})}async fetchPosRewardersAmount(t){let e=new ft;for(let s of t)this.buildFetchPosReward(s,e);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:Ve("0x")});r.error!=null&&At("InvalidConfig",`fetch position rewards error code: ${r.error??"unknown error"}, please check config and params`,{[Lt.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[Lt.DETAILS_KEYS.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=[Lt.ZERO,Lt.ZERO,Lt.ZERO];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 hI.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 ft;return r=ma.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 ft;let s={};return t.forEach(o=>{let u=(0,Lt.normalizeCoinType)(o.coin_type_a),c=(0,Lt.normalizeCoinType)(o.coin_type_b);if(o.collect_fee){let p=s[u];p==null&&(r==null?p=Lt.CoinAssist.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?_=Lt.CoinAssist.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 _=(0,Lt.normalizeCoinType)(p),b=s[p];b===void 0&&(b=Lt.CoinAssist.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&&ZG(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=(0,Lt.getPackagerConfigs)(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}::${du}::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(Lt.CLOCK_ADDRESS)]})}),e}createCollectRewarderNoSendPayload(t,e,r){let{clmm_pool:n,integrate:i}=this.sdk.sdkOptions,s=(0,Lt.getPackagerConfigs)(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}::${CI}::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(Lt.CLOCK_ADDRESS)]})}),e}},uu=Ls($s());var rH=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=(0,sr.d)(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 Br(i.fee_rate).div(10**6):new Br(i.fee_rate).div(10**9),o=(0,sr.d)(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 Br(1).div(i.current_price),d=u.direction?u.current_price:new Br(1).div(u.current_price),p=u.label==="Cetus"?new Br(u.fee_rate).div(10**6):new Br(u.fee_rate).div(10**9),_=(0,sr.d)(u.output_amount).div(10**u.to_decimal).mul(p).div(c.mul(d));e=e.add(_)}}}),e.toString()}calculateSwapPriceImpact(t){let e=(0,sr.d)(0);return t.forEach(r=>{let n=r.base_paths.length;if(n===1){let i=r.base_paths[0],s=(0,sr.d)(i.output_amount).div(10**i.to_decimal),o=(0,sr.d)(i.input_amount).div(10**i.from_decimal),u=s.div(o),c=i.direction?new Br(i.current_price):new Br(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 Br(i.current_price):new Br(1).div(i.current_price),u=s.direction?new Br(s.current_price):new Br(1).div(s.current_price),c=o.mul(u),d=new Br(s.output_amount).div(10**s.to_decimal),p=new Br(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 ft,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}::${pu}::calculate_swap_result`,arguments:d,typeArguments:n})}let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:Ve("0x0")});i.error!=null&&At("InvalidConfig",`pre swap with multi pools error code: ${i.error??"unknown error"}, please check config and params`,{[sr.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[sr.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let s=i.events?.filter(c=>(0,sr.extractStructTagFromType)(c.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==t.pool_ids.length&&At("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[sr.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[sr.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let o=t.by_amount_in?sr.ZERO:sr.U64_MAX,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 uu.default(s[c].parsedJson.data.amount_out);d.gt(o)&&(u=c,o=d)}else{let d=new uu.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 ft,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}::${pu}::calculate_swap_result`,arguments:i,typeArguments:n});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:Ve("0x0")});if(s.error!=null)return At("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[sr.DETAILS_KEYS.METHOD_NAME]:"preSwap",[sr.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let o=s.events?.filter(u=>(0,sr.extractStructTagFromType)(u.type).name==="CalculatedSwapResultEvent");return o.length===0?At("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[sr.DETAILS_KEYS.METHOD_NAME]:"preSwap",[sr.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,o[0].parsedJson.data)}transformSwapData(t,e){let r=e.amount_in&&e.fee_amount?new uu.default(e.amount_in).add(new uu.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 uu.default(r.amount_in).add(new uu.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=zG(e),n;t.a2b?n=t.swap_ticks.sort((_,b)=>b.index-_.index):n=t.swap_ticks.sort((_,b)=>_.index-b.index);let i=HG(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=cu.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=sr.TickMath.sqrtPriceX64ToPrice(r.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),d=sr.TickMath.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}=Sd(t);if(t.a2b&&n||!t.a2b&&i)return await cu.buildSwapTransactionForGas(this._sdk,t,r,e)}return cu.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}=Sd(t);if(t.a2b&&n||!t.a2b&&i)return await cu.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,r,e)}return cu.buildSwapTransactionWithoutTransferCoins(this.sdk,t,r)}},nH=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 At("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[an.DETAILS_KEYS.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=hu.parseClmmVestInfo(i),o=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(o,s),e.push(s)}),e}catch(r){Us("ClmmVestFetchError",r,{[an.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return At("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[an.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:r}=(0,an.getPackagerConfigs)(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=hu.parseClmmVestInfo(s);return this._sdk.updateCache(n,o),o}catch(s){return Us("ClmmVestFetchError",s,{[an.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[an.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:r}})}}async getPositionVesting(t){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return At("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[an.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:r}=(0,an.getPackagerConfigs)(e),n=new ft;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:Ve("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=>hu.parsePositionVesting(c)))}}),s}buildRedeemPayload(t,e){let{clmm_vest:r}=this._sdk.sdkOptions;if(r===void 0)return At("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[an.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:n,clmm_vest_id:i,cetus_coin_type:s}=(0,an.getPackagerConfigs)(r);return e=e||new ft,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(an.CLOCK_ADDRESS)],typeArguments:[d,p]}),O=an.CoinAssist.fromBalance(b,s,e);e.transferObjects([O],this._sdk.getSenderAddress())}),e}},pI={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"}},iH={env:"mainnet",full_rpc_url:GI.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:pI.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:pI.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"}}},sH={env:"testnet",full_rpc_url:HI.FullRpcUrlTestnet,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"}}},WI=class vd extends gI.SdkWrapper{constructor(e){super(e),this._swap=new rH(this),this._pool=new QG(this),this._position=new eH(this),this._config=new $z(this),this._rewarder=new tH(this),this._vest=new nH(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"?vd.createCustomSDK({...iH,...e}):vd.createCustomSDK({...sH,...e})}static createCustomSDK(e){return new vd(e)}},Ad=Ls($s()),rQ=new Ad.default(365),nQ=new Ad.default(24),iQ=new Ad.default(3600),sQ=new Ad.default(.5);var JI=require("@pythnetwork/pyth-sui-js"),Cc=class t extends XI.SdkWrapper{constructor(e,r){super(e),this._suilendModule=new ol(this),this._leverageModules=new Al(this),this._aggregatorClient=new Pc.AggregatorClient({signer:Ve("0x0"),client:e.sui_client||new Bs({url:e.full_rpc_url}),env:e.env==="testnet"?Pc.Env.Testnet:Pc.Env.Mainnet,pythUrls:e.pyth_urls}),this._clmmSDK=r||WI.createSDK({env:e.env,full_rpc_url:e.full_rpc_url}),this._pythConnection=new JI.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(e){return t.createCustomSDK({...Id,...e})}static createCustomSDK(e){return new t(e)}};var oH=Cc;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
1
+ "use strict";var su=Object.create;var Gr=Object.defineProperty;var au=Object.getOwnPropertyDescriptor;var lu=Object.getOwnPropertyNames;var uu=Object.getPrototypeOf,cu=Object.prototype.hasOwnProperty;var ur=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),du=(e,t)=>{for(var i in t)Gr(e,i,{get:t[i],enumerable:!0})},ms=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of lu(t))!cu.call(e,n)&&n!==i&&Gr(e,n,{get:()=>t[n],enumerable:!(r=au(t,n))||r.enumerable});return e};var Vr=(e,t,i)=>(i=e!=null?su(uu(e)):{},ms(t||!e||!e.__esModule?Gr(i,"default",{value:e,enumerable:!0}):i,e)),hu=e=>ms(Gr({},"__esModule",{value:!0}),e);var Zs=ur((Vs,fo)=>{"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=require("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,ue=d[6]|0,Te=ue&8191,he=ue>>>13,_e=d[7]|0,ke=_e&8191,ce=_e>>>13,Ie=d[8]|0,st=Ie&8191,ge=Ie>>>13,Be=d[9]|0,rt=Be&8191,me=Be>>>13,Oe=m[0]|0,et=Oe&8191,fe=Oe>>>13,Ge=m[1]|0,ht=Ge&8191,ve=Ge>>>13,Ve=m[2]|0,ft=Ve&8191,we=Ve>>>13,Ze=m[3]|0,pt=Ze&8191,be=Ze>>>13,Ke=m[4]|0,mt=Ke&8191,ye=Ke>>>13,We=m[5]|0,gt=We&8191,Me=We>>>13,ze=m[6]|0,_t=ze&8191,Ae=ze>>>13,Xe=m[7]|0,vt=Xe&8191,Se=Xe>>>13,Je=m[8]|0,wt=Je&8191,Ce=Je>>>13,Ye=m[9]|0,bt=Ye&8191,Ee=Ye>>>13;l.negative=h.negative^o.negative,l.length=19,w=Math.imul(q,et),f=Math.imul(q,fe),f=f+Math.imul($,et)|0,u=Math.imul($,fe);var He=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(He>>>26)|0,He&=67108863,w=Math.imul(ie,et),f=Math.imul(ie,fe),f=f+Math.imul(C,et)|0,u=Math.imul(C,fe),w=w+Math.imul(q,ht)|0,f=f+Math.imul(q,ve)|0,f=f+Math.imul($,ht)|0,u=u+Math.imul($,ve)|0;var Jt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,w=Math.imul(x,et),f=Math.imul(x,fe),f=f+Math.imul(F,et)|0,u=Math.imul(F,fe),w=w+Math.imul(ie,ht)|0,f=f+Math.imul(ie,ve)|0,f=f+Math.imul(C,ht)|0,u=u+Math.imul(C,ve)|0,w=w+Math.imul(q,ft)|0,f=f+Math.imul(q,we)|0,f=f+Math.imul($,ft)|0,u=u+Math.imul($,we)|0;var Yt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,w=Math.imul(G,et),f=Math.imul(G,fe),f=f+Math.imul(B,et)|0,u=Math.imul(B,fe),w=w+Math.imul(x,ht)|0,f=f+Math.imul(x,ve)|0,f=f+Math.imul(F,ht)|0,u=u+Math.imul(F,ve)|0,w=w+Math.imul(ie,ft)|0,f=f+Math.imul(ie,we)|0,f=f+Math.imul(C,ft)|0,u=u+Math.imul(C,we)|0,w=w+Math.imul(q,pt)|0,f=f+Math.imul(q,be)|0,f=f+Math.imul($,pt)|0,u=u+Math.imul($,be)|0;var Qt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,w=Math.imul(Z,et),f=Math.imul(Z,fe),f=f+Math.imul(H,et)|0,u=Math.imul(H,fe),w=w+Math.imul(G,ht)|0,f=f+Math.imul(G,ve)|0,f=f+Math.imul(B,ht)|0,u=u+Math.imul(B,ve)|0,w=w+Math.imul(x,ft)|0,f=f+Math.imul(x,we)|0,f=f+Math.imul(F,ft)|0,u=u+Math.imul(F,we)|0,w=w+Math.imul(ie,pt)|0,f=f+Math.imul(ie,be)|0,f=f+Math.imul(C,pt)|0,u=u+Math.imul(C,be)|0,w=w+Math.imul(q,mt)|0,f=f+Math.imul(q,ye)|0,f=f+Math.imul($,mt)|0,u=u+Math.imul($,ye)|0;var ei=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(ee,et),f=Math.imul(ee,fe),f=f+Math.imul(te,et)|0,u=Math.imul(te,fe),w=w+Math.imul(Z,ht)|0,f=f+Math.imul(Z,ve)|0,f=f+Math.imul(H,ht)|0,u=u+Math.imul(H,ve)|0,w=w+Math.imul(G,ft)|0,f=f+Math.imul(G,we)|0,f=f+Math.imul(B,ft)|0,u=u+Math.imul(B,we)|0,w=w+Math.imul(x,pt)|0,f=f+Math.imul(x,be)|0,f=f+Math.imul(F,pt)|0,u=u+Math.imul(F,be)|0,w=w+Math.imul(ie,mt)|0,f=f+Math.imul(ie,ye)|0,f=f+Math.imul(C,mt)|0,u=u+Math.imul(C,ye)|0,w=w+Math.imul(q,gt)|0,f=f+Math.imul(q,Me)|0,f=f+Math.imul($,gt)|0,u=u+Math.imul($,Me)|0;var ti=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(Te,et),f=Math.imul(Te,fe),f=f+Math.imul(he,et)|0,u=Math.imul(he,fe),w=w+Math.imul(ee,ht)|0,f=f+Math.imul(ee,ve)|0,f=f+Math.imul(te,ht)|0,u=u+Math.imul(te,ve)|0,w=w+Math.imul(Z,ft)|0,f=f+Math.imul(Z,we)|0,f=f+Math.imul(H,ft)|0,u=u+Math.imul(H,we)|0,w=w+Math.imul(G,pt)|0,f=f+Math.imul(G,be)|0,f=f+Math.imul(B,pt)|0,u=u+Math.imul(B,be)|0,w=w+Math.imul(x,mt)|0,f=f+Math.imul(x,ye)|0,f=f+Math.imul(F,mt)|0,u=u+Math.imul(F,ye)|0,w=w+Math.imul(ie,gt)|0,f=f+Math.imul(ie,Me)|0,f=f+Math.imul(C,gt)|0,u=u+Math.imul(C,Me)|0,w=w+Math.imul(q,_t)|0,f=f+Math.imul(q,Ae)|0,f=f+Math.imul($,_t)|0,u=u+Math.imul($,Ae)|0;var ii=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(ke,et),f=Math.imul(ke,fe),f=f+Math.imul(ce,et)|0,u=Math.imul(ce,fe),w=w+Math.imul(Te,ht)|0,f=f+Math.imul(Te,ve)|0,f=f+Math.imul(he,ht)|0,u=u+Math.imul(he,ve)|0,w=w+Math.imul(ee,ft)|0,f=f+Math.imul(ee,we)|0,f=f+Math.imul(te,ft)|0,u=u+Math.imul(te,we)|0,w=w+Math.imul(Z,pt)|0,f=f+Math.imul(Z,be)|0,f=f+Math.imul(H,pt)|0,u=u+Math.imul(H,be)|0,w=w+Math.imul(G,mt)|0,f=f+Math.imul(G,ye)|0,f=f+Math.imul(B,mt)|0,u=u+Math.imul(B,ye)|0,w=w+Math.imul(x,gt)|0,f=f+Math.imul(x,Me)|0,f=f+Math.imul(F,gt)|0,u=u+Math.imul(F,Me)|0,w=w+Math.imul(ie,_t)|0,f=f+Math.imul(ie,Ae)|0,f=f+Math.imul(C,_t)|0,u=u+Math.imul(C,Ae)|0,w=w+Math.imul(q,vt)|0,f=f+Math.imul(q,Se)|0,f=f+Math.imul($,vt)|0,u=u+Math.imul($,Se)|0;var ri=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(st,et),f=Math.imul(st,fe),f=f+Math.imul(ge,et)|0,u=Math.imul(ge,fe),w=w+Math.imul(ke,ht)|0,f=f+Math.imul(ke,ve)|0,f=f+Math.imul(ce,ht)|0,u=u+Math.imul(ce,ve)|0,w=w+Math.imul(Te,ft)|0,f=f+Math.imul(Te,we)|0,f=f+Math.imul(he,ft)|0,u=u+Math.imul(he,we)|0,w=w+Math.imul(ee,pt)|0,f=f+Math.imul(ee,be)|0,f=f+Math.imul(te,pt)|0,u=u+Math.imul(te,be)|0,w=w+Math.imul(Z,mt)|0,f=f+Math.imul(Z,ye)|0,f=f+Math.imul(H,mt)|0,u=u+Math.imul(H,ye)|0,w=w+Math.imul(G,gt)|0,f=f+Math.imul(G,Me)|0,f=f+Math.imul(B,gt)|0,u=u+Math.imul(B,Me)|0,w=w+Math.imul(x,_t)|0,f=f+Math.imul(x,Ae)|0,f=f+Math.imul(F,_t)|0,u=u+Math.imul(F,Ae)|0,w=w+Math.imul(ie,vt)|0,f=f+Math.imul(ie,Se)|0,f=f+Math.imul(C,vt)|0,u=u+Math.imul(C,Se)|0,w=w+Math.imul(q,wt)|0,f=f+Math.imul(q,Ce)|0,f=f+Math.imul($,wt)|0,u=u+Math.imul($,Ce)|0;var ni=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(rt,et),f=Math.imul(rt,fe),f=f+Math.imul(me,et)|0,u=Math.imul(me,fe),w=w+Math.imul(st,ht)|0,f=f+Math.imul(st,ve)|0,f=f+Math.imul(ge,ht)|0,u=u+Math.imul(ge,ve)|0,w=w+Math.imul(ke,ft)|0,f=f+Math.imul(ke,we)|0,f=f+Math.imul(ce,ft)|0,u=u+Math.imul(ce,we)|0,w=w+Math.imul(Te,pt)|0,f=f+Math.imul(Te,be)|0,f=f+Math.imul(he,pt)|0,u=u+Math.imul(he,be)|0,w=w+Math.imul(ee,mt)|0,f=f+Math.imul(ee,ye)|0,f=f+Math.imul(te,mt)|0,u=u+Math.imul(te,ye)|0,w=w+Math.imul(Z,gt)|0,f=f+Math.imul(Z,Me)|0,f=f+Math.imul(H,gt)|0,u=u+Math.imul(H,Me)|0,w=w+Math.imul(G,_t)|0,f=f+Math.imul(G,Ae)|0,f=f+Math.imul(B,_t)|0,u=u+Math.imul(B,Ae)|0,w=w+Math.imul(x,vt)|0,f=f+Math.imul(x,Se)|0,f=f+Math.imul(F,vt)|0,u=u+Math.imul(F,Se)|0,w=w+Math.imul(ie,wt)|0,f=f+Math.imul(ie,Ce)|0,f=f+Math.imul(C,wt)|0,u=u+Math.imul(C,Ce)|0,w=w+Math.imul(q,bt)|0,f=f+Math.imul(q,Ee)|0,f=f+Math.imul($,bt)|0,u=u+Math.imul($,Ee)|0;var oi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(rt,ht),f=Math.imul(rt,ve),f=f+Math.imul(me,ht)|0,u=Math.imul(me,ve),w=w+Math.imul(st,ft)|0,f=f+Math.imul(st,we)|0,f=f+Math.imul(ge,ft)|0,u=u+Math.imul(ge,we)|0,w=w+Math.imul(ke,pt)|0,f=f+Math.imul(ke,be)|0,f=f+Math.imul(ce,pt)|0,u=u+Math.imul(ce,be)|0,w=w+Math.imul(Te,mt)|0,f=f+Math.imul(Te,ye)|0,f=f+Math.imul(he,mt)|0,u=u+Math.imul(he,ye)|0,w=w+Math.imul(ee,gt)|0,f=f+Math.imul(ee,Me)|0,f=f+Math.imul(te,gt)|0,u=u+Math.imul(te,Me)|0,w=w+Math.imul(Z,_t)|0,f=f+Math.imul(Z,Ae)|0,f=f+Math.imul(H,_t)|0,u=u+Math.imul(H,Ae)|0,w=w+Math.imul(G,vt)|0,f=f+Math.imul(G,Se)|0,f=f+Math.imul(B,vt)|0,u=u+Math.imul(B,Se)|0,w=w+Math.imul(x,wt)|0,f=f+Math.imul(x,Ce)|0,f=f+Math.imul(F,wt)|0,u=u+Math.imul(F,Ce)|0,w=w+Math.imul(ie,bt)|0,f=f+Math.imul(ie,Ee)|0,f=f+Math.imul(C,bt)|0,u=u+Math.imul(C,Ee)|0;var si=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(rt,ft),f=Math.imul(rt,we),f=f+Math.imul(me,ft)|0,u=Math.imul(me,we),w=w+Math.imul(st,pt)|0,f=f+Math.imul(st,be)|0,f=f+Math.imul(ge,pt)|0,u=u+Math.imul(ge,be)|0,w=w+Math.imul(ke,mt)|0,f=f+Math.imul(ke,ye)|0,f=f+Math.imul(ce,mt)|0,u=u+Math.imul(ce,ye)|0,w=w+Math.imul(Te,gt)|0,f=f+Math.imul(Te,Me)|0,f=f+Math.imul(he,gt)|0,u=u+Math.imul(he,Me)|0,w=w+Math.imul(ee,_t)|0,f=f+Math.imul(ee,Ae)|0,f=f+Math.imul(te,_t)|0,u=u+Math.imul(te,Ae)|0,w=w+Math.imul(Z,vt)|0,f=f+Math.imul(Z,Se)|0,f=f+Math.imul(H,vt)|0,u=u+Math.imul(H,Se)|0,w=w+Math.imul(G,wt)|0,f=f+Math.imul(G,Ce)|0,f=f+Math.imul(B,wt)|0,u=u+Math.imul(B,Ce)|0,w=w+Math.imul(x,bt)|0,f=f+Math.imul(x,Ee)|0,f=f+Math.imul(F,bt)|0,u=u+Math.imul(F,Ee)|0;var ai=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,w=Math.imul(rt,pt),f=Math.imul(rt,be),f=f+Math.imul(me,pt)|0,u=Math.imul(me,be),w=w+Math.imul(st,mt)|0,f=f+Math.imul(st,ye)|0,f=f+Math.imul(ge,mt)|0,u=u+Math.imul(ge,ye)|0,w=w+Math.imul(ke,gt)|0,f=f+Math.imul(ke,Me)|0,f=f+Math.imul(ce,gt)|0,u=u+Math.imul(ce,Me)|0,w=w+Math.imul(Te,_t)|0,f=f+Math.imul(Te,Ae)|0,f=f+Math.imul(he,_t)|0,u=u+Math.imul(he,Ae)|0,w=w+Math.imul(ee,vt)|0,f=f+Math.imul(ee,Se)|0,f=f+Math.imul(te,vt)|0,u=u+Math.imul(te,Se)|0,w=w+Math.imul(Z,wt)|0,f=f+Math.imul(Z,Ce)|0,f=f+Math.imul(H,wt)|0,u=u+Math.imul(H,Ce)|0,w=w+Math.imul(G,bt)|0,f=f+Math.imul(G,Ee)|0,f=f+Math.imul(B,bt)|0,u=u+Math.imul(B,Ee)|0;var li=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(li>>>26)|0,li&=67108863,w=Math.imul(rt,mt),f=Math.imul(rt,ye),f=f+Math.imul(me,mt)|0,u=Math.imul(me,ye),w=w+Math.imul(st,gt)|0,f=f+Math.imul(st,Me)|0,f=f+Math.imul(ge,gt)|0,u=u+Math.imul(ge,Me)|0,w=w+Math.imul(ke,_t)|0,f=f+Math.imul(ke,Ae)|0,f=f+Math.imul(ce,_t)|0,u=u+Math.imul(ce,Ae)|0,w=w+Math.imul(Te,vt)|0,f=f+Math.imul(Te,Se)|0,f=f+Math.imul(he,vt)|0,u=u+Math.imul(he,Se)|0,w=w+Math.imul(ee,wt)|0,f=f+Math.imul(ee,Ce)|0,f=f+Math.imul(te,wt)|0,u=u+Math.imul(te,Ce)|0,w=w+Math.imul(Z,bt)|0,f=f+Math.imul(Z,Ee)|0,f=f+Math.imul(H,bt)|0,u=u+Math.imul(H,Ee)|0;var ui=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ui>>>26)|0,ui&=67108863,w=Math.imul(rt,gt),f=Math.imul(rt,Me),f=f+Math.imul(me,gt)|0,u=Math.imul(me,Me),w=w+Math.imul(st,_t)|0,f=f+Math.imul(st,Ae)|0,f=f+Math.imul(ge,_t)|0,u=u+Math.imul(ge,Ae)|0,w=w+Math.imul(ke,vt)|0,f=f+Math.imul(ke,Se)|0,f=f+Math.imul(ce,vt)|0,u=u+Math.imul(ce,Se)|0,w=w+Math.imul(Te,wt)|0,f=f+Math.imul(Te,Ce)|0,f=f+Math.imul(he,wt)|0,u=u+Math.imul(he,Ce)|0,w=w+Math.imul(ee,bt)|0,f=f+Math.imul(ee,Ee)|0,f=f+Math.imul(te,bt)|0,u=u+Math.imul(te,Ee)|0;var ci=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ci>>>26)|0,ci&=67108863,w=Math.imul(rt,_t),f=Math.imul(rt,Ae),f=f+Math.imul(me,_t)|0,u=Math.imul(me,Ae),w=w+Math.imul(st,vt)|0,f=f+Math.imul(st,Se)|0,f=f+Math.imul(ge,vt)|0,u=u+Math.imul(ge,Se)|0,w=w+Math.imul(ke,wt)|0,f=f+Math.imul(ke,Ce)|0,f=f+Math.imul(ce,wt)|0,u=u+Math.imul(ce,Ce)|0,w=w+Math.imul(Te,bt)|0,f=f+Math.imul(Te,Ee)|0,f=f+Math.imul(he,bt)|0,u=u+Math.imul(he,Ee)|0;var di=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(di>>>26)|0,di&=67108863,w=Math.imul(rt,vt),f=Math.imul(rt,Se),f=f+Math.imul(me,vt)|0,u=Math.imul(me,Se),w=w+Math.imul(st,wt)|0,f=f+Math.imul(st,Ce)|0,f=f+Math.imul(ge,wt)|0,u=u+Math.imul(ge,Ce)|0,w=w+Math.imul(ke,bt)|0,f=f+Math.imul(ke,Ee)|0,f=f+Math.imul(ce,bt)|0,u=u+Math.imul(ce,Ee)|0;var hi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(hi>>>26)|0,hi&=67108863,w=Math.imul(rt,wt),f=Math.imul(rt,Ce),f=f+Math.imul(me,wt)|0,u=Math.imul(me,Ce),w=w+Math.imul(st,bt)|0,f=f+Math.imul(st,Ee)|0,f=f+Math.imul(ge,bt)|0,u=u+Math.imul(ge,Ee)|0;var fi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(fi>>>26)|0,fi&=67108863,w=Math.imul(rt,bt),f=Math.imul(rt,Ee),f=f+Math.imul(me,bt)|0,u=Math.imul(me,Ee);var pi=(b+w|0)+((f&8191)<<13)|0;return b=(u+(f>>>13)|0)+(pi>>>26)|0,pi&=67108863,_[0]=He,_[1]=Jt,_[2]=Yt,_[3]=Qt,_[4]=ei,_[5]=ti,_[6]=ii,_[7]=ri,_[8]=ni,_[9]=oi,_[10]=si,_[11]=ai,_[12]=li,_[13]=ui,_[14]=ci,_[15]=di,_[16]=hi,_[17]=fi,_[18]=pi,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 le(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(le,Y),le.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},le.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 le;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 fo>"u"||fo,Vs)});var _o=ur((Xs,un)=>{"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,le,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=le(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},le=(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,ue,Te,he=x.indexOf("."),_e=R,ke=N;for(he>=0&&(V=_,_=0,x=x.replace(".",""),Te=new u(F),te=Te.pow(x.length-he),_=V,Te.c=T(Q(P(te.c),te.e,"0"),10,L,C),Te.e=Te.c.length),ue=T(x,F,L,B?(D=w,C):(D=C,w)),H=V=ue.length;ue[--V]==0;ue.pop());if(!ue[0])return D.charAt(0);if(he<0?--H:(te.c=ue,te.e=H,te.s=G,te=Y(te,Te,_e,ke,L),ue=te.c,ee=te.r,H=te.e),Z=H+_e+1,he=ue[Z],V=L/2,ee=ee||Z<0||ue[Z+1]!=null,ee=ke<4?(he!=null||ee)&&(ke==0||ke==(te.s<0?3:2)):he>V||he==V&&(ke==4||ee||ke==6&&ue[Z-1]&1||ke==(te.s<0?8:7)),Z<1||!ue[0])x=ee?Q(D.charAt(1),-_e,D.charAt(0)):D.charAt(0);else{if(ue.length=Z,ee)for(--L;++ue[--Z]>L;)ue[Z]=0,Z||(++H,ue=[1].concat(ue));for(V=ue.length;!ue[--V];);for(he=0,x="";he<=V;x+=D.charAt(ue[he++]));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,ue=L/y|0;for(F=F.slice();ee--;)Z=F[ee]%y,H=F[ee]/y|0,B=ue*Z+H*te,D=te*Z+B%y*y+V,V=(D/G|0)+(B/y|0)+ue*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,ue,Te,he,_e,ke,ce,Ie,st,ge,Be,rt,me,Oe=F.s==L.s?1:-1,et=F.c,fe=L.c;if(!et||!et[0]||!fe||!fe[0])return new u(!F.s||!L.s||(et?fe&&et[0]==fe[0]:!fe)?NaN:et&&et[0]==0||!fe?Oe*0:Oe/0);for(he=new u(Oe),_e=he.c=[],H=F.e-L.e,Oe=G+H+1,D||(D=c,H=U(F.e/p)-U(L.e/p),Oe=Oe/p|0),V=0;fe[V]==(et[V]||0);V++);if(fe[V]>(et[V]||0)&&H--,Oe<0)_e.push(1),ee=!0;else{for(ge=et.length,rt=fe.length,V=0,Oe+=2,te=n(D/(fe[0]+1)),te>1&&(fe=C(fe,te,D),et=C(et,te,D),rt=fe.length,ge=et.length),st=rt,ke=et.slice(0,rt),ce=ke.length;ce<rt;ke[ce++]=0);me=fe.slice(),me=[0].concat(me),Be=fe[0],fe[1]>=D/2&&Be++;do{if(te=0,Z=T(fe,ke,rt,ce),Z<0){if(Ie=ke[0],rt!=ce&&(Ie=Ie*D+(ke[1]||0)),te=n(Ie/Be),te>1)for(te>=D&&(te=D-1),ue=C(fe,te,D),Te=ue.length,ce=ke.length;T(ue,ke,Te,ce)==1;)te--,x(ue,rt<Te?me:fe,Te,D),Te=ue.length,Z=1;else te==0&&(Z=te=1),ue=fe.slice(),Te=ue.length;if(Te<ce&&(ue=[0].concat(ue)),x(ke,ue,ce,D),ce=ke.length,Z==-1)for(;T(fe,ke,rt,ce)<1;)te++,x(ke,rt<ce?me:fe,ce,D),ce=ke.length}else Z===0&&(te++,ke=[0]);_e[V++]=te,ke[0]?ke[ce++]=et[st]||0:(ke=[et[st]],ce=1)}while((st++<ge||ke[0]!=null)&&Oe--);ee=ke[0]!=null,_e[0]||_e.splice(0,1)}if(D==c){for(V=1,Oe=_e[0];Oe>=10;Oe/=10,V++);z(he,G+(he.e=V+H*p-1)+1,B,ee)}else he.e=H,he.r=+ee;return he}})();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,ue){return H=(ue=ue.toLowerCase())=="x"?16:ue=="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,ue,Te,he,_e,ke=this,ce=ke.c,Ie=(C=new u(C,T)).c;if(!ce||!Ie||!ce[0]||!Ie[0])return!ke.s||!C.s||ce&&!ce[0]&&!Ie||Ie&&!Ie[0]&&!ce?C.c=C.e=C.s=null:(C.s*=ke.s,!ce||!Ie?C.c=C.e=null:(C.c=[0],C.e=0)),C;for(F=U(ke.e/p)+U(C.e/p),C.s*=ke.s,Z=ce.length,ee=Ie.length,Z<ee&&(Te=ce,ce=Ie,Ie=Te,L=Z,Z=ee,ee=L),L=Z+ee,Te=[];L--;Te.push(0));for(he=c,_e=y,L=ee;--L>=0;){for(x=0,te=Ie[L]%_e,ue=Ie[L]/_e|0,B=Z,G=L+B;G>L;)H=ce[--B]%_e,V=ce[B]/_e|0,D=ue*H+V*te,H=te*H+D%_e*_e+Te[G]+x,x=(H/he|0)+(D/_e|0)+ue*V,Te[G--]=H%he;Te[G]=x}return x?++F:Te.splice(0,1),$(C,Te,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,ue=te?V.slice(1):V,Te=ue.length;if(Z&&(G=D,D=Z,Z=G,Te-=G),D>0&&Te>0){for(G=Te%D||D,V=ue.substr(0,G);G<Te;G+=D)V+=H+ue.substr(G,D);Z>0&&(V+=H+ue.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,ue=this,Te=ue.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(!Te)return new u(ue);for(T=new u(O),H=x=new u(O),F=Z=new u(O),te=P(Te),G=T.e=te.length-ue.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=ue.s,G=G*2,ee=Y(H,F,G,N).minus(ue).abs().comparedTo(Y(Z,x,G,N).minus(ue).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=le(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,le,E=1,I=se.length,O=se[0]+"";E<I;){for(Y=se[E++]+"",le=p-Y.length;le--;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 le,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(le=I&&!I[0],E=O&&!O[0],le||E)return le?E?0:-N:R;if(R!=N)return R;if(le=R<0,E=S==h,!I||!O)return E?0:!I^le?1:-1;if(!E)return S>h^le?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]^le?1:-1;return S==h?0:S>h^le?1:-1}function j(se,Y,le,E){if(se<Y||se>le||se!==n(se))throw Error(s+(E||"Argument")+(typeof se=="number"?se<Y||se>le?" 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,le){var E,I;if(Y<0){for(I=le+".";++Y;I+=le);se=I+se}else if(E=se.length,++Y>E){for(I=le,Y-=E;--Y;I+=le);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 un<"u"&&un.exports?un.exports=t:(e||(e=typeof self<"u"&&self?self:window),e.BigNumber=t)})(Xs)});var ea=ur((Nm,Qs)=>{"use strict";var Js=_o(),Ys=Qs.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 Js||Js.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 Ys.stringify!="function"&&(Ys.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 ia=ur((Rm,ta)=>{"use strict";var cn=null,u0=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,c0=/(?: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)/,d0=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 cn==null&&(cn=_o()),W.length>15?t.storeAsString?W:t.useNativeBigInt?BigInt(W):new cn(W):t.alwaysParseAsBig?t.useNativeBigInt?BigInt(P):new cn(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+'"'),u0.test(P)===!0?t.protoAction==="error"?a("Object contains forbidden prototype property"):t.protoAction==="ignore"?A():W[P]=A():c0.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,le=X[Q];return le&&typeof le=="object"&&Object.keys(le).forEach(function(E){Y=K(le,E),Y!==void 0?le[E]=Y:delete le[E]}),W.call(X,Q,le)})({"":j},""):j}};ta.exports=d0});var oa=ur((Lm,dn)=>{"use strict";var ra=ea().stringify,na=ia();dn.exports=function(e){return{parse:na(e),stringify:ra}};dn.exports.parse=na();dn.exports.stringify=ra});var al=ur(J=>{"use strict";var vo=require("@mysten/sui/transactions"),h0=oa(),yt=require("@mysten/sui/utils"),sa=require("@mysten/sui/client"),aa=require("@pythnetwork/pyth-sui-js");function f0(e){return e&&e.__esModule?e:{default:e}}var p0=f0(h0),m0=Object.create,Io=Object.defineProperty,g0=Object.defineProperties,_0=Object.getOwnPropertyDescriptor,v0=Object.getOwnPropertyDescriptors,Ma=Object.getOwnPropertyNames,la=Object.getOwnPropertySymbols,w0=Object.getPrototypeOf,Aa=Object.prototype.hasOwnProperty,b0=Object.prototype.propertyIsEnumerable,ua=(e,t,i)=>t in e?Io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,xr=(e,t)=>{for(var i in t||(t={}))Aa.call(t,i)&&ua(e,i,t[i]);if(la)for(var i of la(t))b0.call(t,i)&&ua(e,i,t[i]);return e},pn=(e,t)=>g0(e,v0(t)),y0=(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')}),M0=(e,t)=>function(){return t||(0,e[Ma(e)[0]])((t={exports:{}}).exports,t),t.exports},A0=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ma(t))!Aa.call(e,n)&&n!==i&&Io(e,n,{get:()=>t[n],enumerable:!(r=_0(t,n))||r.enumerable});return e},vr=(e,t,i)=>(i=e!=null?m0(w0(e)):{},A0(!e||!e.__esModule?Io(i,"default",{value:e,enumerable:!0}):i,e)),Nt=(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())}),wr=M0({"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=y0("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,ue=ee>>>13,Te=m[6]|0,he=Te&8191,_e=Te>>>13,ke=m[7]|0,ce=ke&8191,Ie=ke>>>13,st=m[8]|0,ge=st&8191,Be=st>>>13,rt=m[9]|0,me=rt&8191,Oe=rt>>>13,et=_[0]|0,fe=et&8191,Ge=et>>>13,ht=_[1]|0,ve=ht&8191,Ve=ht>>>13,ft=_[2]|0,we=ft&8191,Ze=ft>>>13,pt=_[3]|0,be=pt&8191,Ke=pt>>>13,mt=_[4]|0,ye=mt&8191,We=mt>>>13,gt=_[5]|0,Me=gt&8191,ze=gt>>>13,_t=_[6]|0,Ae=_t&8191,Xe=_t>>>13,vt=_[7]|0,Se=vt&8191,Je=vt>>>13,wt=_[8]|0,Ce=wt&8191,Ye=wt>>>13,bt=_[9]|0,Ee=bt&8191,He=bt>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,fe),u=Math.imul($,Ge),u=u+Math.imul(z,fe)|0,M=Math.imul(z,Ge);var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(C,fe),u=Math.imul(C,Ge),u=u+Math.imul(T,fe)|0,M=Math.imul(T,Ge),f=f+Math.imul($,ve)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,Ve)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(F,fe),u=Math.imul(F,Ge),u=u+Math.imul(L,fe)|0,M=Math.imul(L,Ge),f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ze)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(B,fe),u=Math.imul(B,Ge),u=u+Math.imul(D,fe)|0,M=Math.imul(D,Ge),f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ke)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(H,fe),u=Math.imul(H,Ge),u=u+Math.imul(V,fe)|0,M=Math.imul(V,Ge),f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,We)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,We)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(te,fe),u=Math.imul(te,Ge),u=u+Math.imul(ue,fe)|0,M=Math.imul(ue,Ge),f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,We)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,We)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,ze)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,ze)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,fe),u=Math.imul(he,Ge),u=u+Math.imul(_e,fe)|0,M=Math.imul(_e,Ge),f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(ue,ve)|0,M=M+Math.imul(ue,Ve)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,We)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,We)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,ze)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,ze)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Xe)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Xe)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(ce,fe),u=Math.imul(ce,Ge),u=u+Math.imul(Ie,fe)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(he,ve)|0,u=u+Math.imul(he,Ve)|0,u=u+Math.imul(_e,ve)|0,M=M+Math.imul(_e,Ve)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(ue,we)|0,M=M+Math.imul(ue,Ze)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,We)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,We)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,ze)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,ze)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Xe)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Xe)|0,f=f+Math.imul($,Se)|0,u=u+Math.imul($,Je)|0,u=u+Math.imul(z,Se)|0,M=M+Math.imul(z,Je)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(ge,fe),u=Math.imul(ge,Ge),u=u+Math.imul(Be,fe)|0,M=Math.imul(Be,Ge),f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(Ie,ve)|0,M=M+Math.imul(Ie,Ve)|0,f=f+Math.imul(he,we)|0,u=u+Math.imul(he,Ze)|0,u=u+Math.imul(_e,we)|0,M=M+Math.imul(_e,Ze)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(ue,be)|0,M=M+Math.imul(ue,Ke)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,We)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,We)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,ze)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,ze)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Xe)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Xe)|0,f=f+Math.imul(C,Se)|0,u=u+Math.imul(C,Je)|0,u=u+Math.imul(T,Se)|0,M=M+Math.imul(T,Je)|0,f=f+Math.imul($,Ce)|0,u=u+Math.imul($,Ye)|0,u=u+Math.imul(z,Ce)|0,M=M+Math.imul(z,Ye)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(me,fe),u=Math.imul(me,Ge),u=u+Math.imul(Oe,fe)|0,M=Math.imul(Oe,Ge),f=f+Math.imul(ge,ve)|0,u=u+Math.imul(ge,Ve)|0,u=u+Math.imul(Be,ve)|0,M=M+Math.imul(Be,Ve)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(Ie,we)|0,M=M+Math.imul(Ie,Ze)|0,f=f+Math.imul(he,be)|0,u=u+Math.imul(he,Ke)|0,u=u+Math.imul(_e,be)|0,M=M+Math.imul(_e,Ke)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,We)|0,u=u+Math.imul(ue,ye)|0,M=M+Math.imul(ue,We)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,ze)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,ze)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Xe)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Xe)|0,f=f+Math.imul(F,Se)|0,u=u+Math.imul(F,Je)|0,u=u+Math.imul(L,Se)|0,M=M+Math.imul(L,Je)|0,f=f+Math.imul(C,Ce)|0,u=u+Math.imul(C,Ye)|0,u=u+Math.imul(T,Ce)|0,M=M+Math.imul(T,Ye)|0,f=f+Math.imul($,Ee)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,Ee)|0,M=M+Math.imul(z,He)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(me,ve),u=Math.imul(me,Ve),u=u+Math.imul(Oe,ve)|0,M=Math.imul(Oe,Ve),f=f+Math.imul(ge,we)|0,u=u+Math.imul(ge,Ze)|0,u=u+Math.imul(Be,we)|0,M=M+Math.imul(Be,Ze)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(Ie,be)|0,M=M+Math.imul(Ie,Ke)|0,f=f+Math.imul(he,ye)|0,u=u+Math.imul(he,We)|0,u=u+Math.imul(_e,ye)|0,M=M+Math.imul(_e,We)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,ze)|0,u=u+Math.imul(ue,Me)|0,M=M+Math.imul(ue,ze)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Xe)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Xe)|0,f=f+Math.imul(B,Se)|0,u=u+Math.imul(B,Je)|0,u=u+Math.imul(D,Se)|0,M=M+Math.imul(D,Je)|0,f=f+Math.imul(F,Ce)|0,u=u+Math.imul(F,Ye)|0,u=u+Math.imul(L,Ce)|0,M=M+Math.imul(L,Ye)|0,f=f+Math.imul(C,Ee)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,Ee)|0,M=M+Math.imul(T,He)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(me,we),u=Math.imul(me,Ze),u=u+Math.imul(Oe,we)|0,M=Math.imul(Oe,Ze),f=f+Math.imul(ge,be)|0,u=u+Math.imul(ge,Ke)|0,u=u+Math.imul(Be,be)|0,M=M+Math.imul(Be,Ke)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,We)|0,u=u+Math.imul(Ie,ye)|0,M=M+Math.imul(Ie,We)|0,f=f+Math.imul(he,Me)|0,u=u+Math.imul(he,ze)|0,u=u+Math.imul(_e,Me)|0,M=M+Math.imul(_e,ze)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Xe)|0,u=u+Math.imul(ue,Ae)|0,M=M+Math.imul(ue,Xe)|0,f=f+Math.imul(H,Se)|0,u=u+Math.imul(H,Je)|0,u=u+Math.imul(V,Se)|0,M=M+Math.imul(V,Je)|0,f=f+Math.imul(B,Ce)|0,u=u+Math.imul(B,Ye)|0,u=u+Math.imul(D,Ce)|0,M=M+Math.imul(D,Ye)|0,f=f+Math.imul(F,Ee)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,Ee)|0,M=M+Math.imul(L,He)|0;var li=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(li>>>26)|0,li&=67108863,f=Math.imul(me,be),u=Math.imul(me,Ke),u=u+Math.imul(Oe,be)|0,M=Math.imul(Oe,Ke),f=f+Math.imul(ge,ye)|0,u=u+Math.imul(ge,We)|0,u=u+Math.imul(Be,ye)|0,M=M+Math.imul(Be,We)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,ze)|0,u=u+Math.imul(Ie,Me)|0,M=M+Math.imul(Ie,ze)|0,f=f+Math.imul(he,Ae)|0,u=u+Math.imul(he,Xe)|0,u=u+Math.imul(_e,Ae)|0,M=M+Math.imul(_e,Xe)|0,f=f+Math.imul(te,Se)|0,u=u+Math.imul(te,Je)|0,u=u+Math.imul(ue,Se)|0,M=M+Math.imul(ue,Je)|0,f=f+Math.imul(H,Ce)|0,u=u+Math.imul(H,Ye)|0,u=u+Math.imul(V,Ce)|0,M=M+Math.imul(V,Ye)|0,f=f+Math.imul(B,Ee)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,Ee)|0,M=M+Math.imul(D,He)|0;var ui=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,f=Math.imul(me,ye),u=Math.imul(me,We),u=u+Math.imul(Oe,ye)|0,M=Math.imul(Oe,We),f=f+Math.imul(ge,Me)|0,u=u+Math.imul(ge,ze)|0,u=u+Math.imul(Be,Me)|0,M=M+Math.imul(Be,ze)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Xe)|0,u=u+Math.imul(Ie,Ae)|0,M=M+Math.imul(Ie,Xe)|0,f=f+Math.imul(he,Se)|0,u=u+Math.imul(he,Je)|0,u=u+Math.imul(_e,Se)|0,M=M+Math.imul(_e,Je)|0,f=f+Math.imul(te,Ce)|0,u=u+Math.imul(te,Ye)|0,u=u+Math.imul(ue,Ce)|0,M=M+Math.imul(ue,Ye)|0,f=f+Math.imul(H,Ee)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,Ee)|0,M=M+Math.imul(V,He)|0;var ci=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,f=Math.imul(me,Me),u=Math.imul(me,ze),u=u+Math.imul(Oe,Me)|0,M=Math.imul(Oe,ze),f=f+Math.imul(ge,Ae)|0,u=u+Math.imul(ge,Xe)|0,u=u+Math.imul(Be,Ae)|0,M=M+Math.imul(Be,Xe)|0,f=f+Math.imul(ce,Se)|0,u=u+Math.imul(ce,Je)|0,u=u+Math.imul(Ie,Se)|0,M=M+Math.imul(Ie,Je)|0,f=f+Math.imul(he,Ce)|0,u=u+Math.imul(he,Ye)|0,u=u+Math.imul(_e,Ce)|0,M=M+Math.imul(_e,Ye)|0,f=f+Math.imul(te,Ee)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(ue,Ee)|0,M=M+Math.imul(ue,He)|0;var di=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(di>>>26)|0,di&=67108863,f=Math.imul(me,Ae),u=Math.imul(me,Xe),u=u+Math.imul(Oe,Ae)|0,M=Math.imul(Oe,Xe),f=f+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Je)|0,u=u+Math.imul(Be,Se)|0,M=M+Math.imul(Be,Je)|0,f=f+Math.imul(ce,Ce)|0,u=u+Math.imul(ce,Ye)|0,u=u+Math.imul(Ie,Ce)|0,M=M+Math.imul(Ie,Ye)|0,f=f+Math.imul(he,Ee)|0,u=u+Math.imul(he,He)|0,u=u+Math.imul(_e,Ee)|0,M=M+Math.imul(_e,He)|0;var hi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,f=Math.imul(me,Se),u=Math.imul(me,Je),u=u+Math.imul(Oe,Se)|0,M=Math.imul(Oe,Je),f=f+Math.imul(ge,Ce)|0,u=u+Math.imul(ge,Ye)|0,u=u+Math.imul(Be,Ce)|0,M=M+Math.imul(Be,Ye)|0,f=f+Math.imul(ce,Ee)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(Ie,Ee)|0,M=M+Math.imul(Ie,He)|0;var fi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,f=Math.imul(me,Ce),u=Math.imul(me,Ye),u=u+Math.imul(Oe,Ce)|0,M=Math.imul(Oe,Ye),f=f+Math.imul(ge,Ee)|0,u=u+Math.imul(ge,He)|0,u=u+Math.imul(Be,Ee)|0,M=M+Math.imul(Be,He)|0;var pi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,f=Math.imul(me,Ee),u=Math.imul(me,He),u=u+Math.imul(Oe,Ee)|0,M=Math.imul(Oe,He);var nr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(nr>>>26)|0,nr&=67108863,b[0]=Jt,b[1]=Yt,b[2]=Qt,b[3]=ei,b[4]=ti,b[5]=ii,b[6]=ri,b[7]=ni,b[8]=oi,b[9]=si,b[10]=ai,b[11]=li,b[12]=ui,b[13]=ci,b[14]=di,b[15]=hi,b[16]=fi,b[17]=pi,b[18]=nr,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 le(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()}le.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},le.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},le.prototype.split=function(o,l){o.iushrn(this.n,0,l)},le.prototype.imulK=function(o){return o.imul(this.k)};function E(){le.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(E,le),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(){le.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,le);function O(){le.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(O,le);function R(){le.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(R,le),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)}}),St=vr(wr()),pr=vr(wr()),Sa=(e=>(e.InvalidType="InvalidType",e))(Sa||{}),Ca=(e=>(e.MissAggregatorPackage="MissAggregatorPackage",e.MissGlobalConfig="MissGlobalConfig",e.InvalidWallet="InvalidWallet",e.SimulateError="SimulateError",e))(Ca||{}),Ea=(e=>(e.InsufficientBalance="InsufficientBalance",e.SimulateEventError="simulateEventError",e.CannotGetDecimals="CannotGetDecimals",e.MissCoinA="MissCoinA",e.MissCoinB="MissCoinB",e.MissTurbosFeeType="MissTurbosFeeType",e.MissAftermathLpSupplyType="MissAftermathLpSupplyType",e))(Ea||{}),Ia=(e=>(e[e.NumberTooLarge=1e3]="NumberTooLarge",e[e.RateLimitExceeded=1001]="RateLimitExceeded",e[e.InsufficientLiquidity=1002]="InsufficientLiquidity",e[e.HoneyPot=1003]="HoneyPot",e))(Ia||{});function hn(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 S0=class ka extends Error{constructor(t,i){super(t),this.message=t,this.errorCode=i}static isAggregatorErrorCode(t,i){return t instanceof ka&&t.errorCode===i}},C0=0,Ta=1,E0=2;function ca(e,t){return e===t?C0:e<t?Ta:E0}function I0(e,t){let i=0,r=e.length<=t.length?e.length:t.length,n=ca(e.length,t.length);for(;i<r;){let s=ca(e.charCodeAt(i),t.charCodeAt(i));if(i+=1,s!==0)return s}return n}function k0(e,t){return I0(e,t)===Ta}function wo(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 T0(e){return e.split("::")[0]}function gr(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=gr(i),g=pn(xr({},p),{type_arguments:n.map(v=>gr(v).source_address)});return g.type_arguments=g.type_arguments.map(v=>_i.isSuiCoin(v)?v:gr(v).source_address),g.source_address=wo(g.full_address,g.type_arguments),g}let s=i.split("::"),c={full_address:i,address:i===ko||i===xa?"0x2":yt.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=wo(c.full_address,c.type_arguments),c}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function bo(e){return gr(e).source_address}function Oa(e){return e.toLowerCase().startsWith("0x")?yt.normalizeSuiObjectId(e):e}function Pa(e){for(let t in e){let i=typeof e[t];if(i==="object")Pa(e[t]);else if(i==="string"){let r=e[t];e[t]=Oa(r)}}}function O0(e,t,i){return`${e}::${t}::${i}`}var P0="0x2::coin::Coin",x0=/^0x2::coin::Coin<(.+)>$/,N0=1e3,R0=500,L0=100,F0=100,D0=1e3,ko="0x2::sui::SUI",xa="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",B0="SUI",U0=450,j0="0x0000000000000000000000000000000000000005",_i=class Wi{static getCoinTypeArg(t){let i=t.type.match(x0);return i?i[1]:null}static isSUI(t){let i=Wi.getCoinTypeArg(t);return i?Wi.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`${P0}<${t}>`}static getCoinAssets(t,i){let r=[];return i.forEach(n=>{bo(n.coinAddress)===bo(t)&&r.push(n)}),r}static isSuiCoin(t){return gr(t).full_address===ko}static selectCoinObjectIdGreaterThanOrEqual(t,i,r=[]){let n=Wi.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=Wi.sortByBalance(t.filter(g=>!r.includes(g.coinObjectId))),s=Wi.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:Wi.sortByBalance(c),remainingCoins:Wi.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 Bi(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 Na(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t],arguments:[]})}function Ra(e,t){e=Bi(e),t=Bi(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 q0(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 $0(e){let t=/<([^>]*)>/,i=e.match(t);if(i)return i[1]}function H0(e,t,i,r){let n=_i.getCoinAssets(r,t);if(i===BigInt(0))return _i.isSuiCoin(r)||n.length===0&&!_i.isSuiCoin(r)?{targetCoin:Na(e,r),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(n[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(n[0].balance.toString())};if(_i.calculateTotalBalance(n)<i)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+r,"InsufficientBalance"+r);if(_i.isSuiCoin(r))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(i.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(i.toString())};let a=_i.sortByBalance(n);a.slice(0,3).reduce((A,k)=>A+k.balance,BigInt(0))<BigInt(i)&&(a=_i.sortByBalanceDes(n));let p=_i.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 Fr=vr(wr()),sr=new Fr.default(0),G0=new Fr.default(1),La=new Fr.default(2),V0=La.pow(new Fr.default(128)),Z0=new Fr.default("18446744073709551615"),mn="18446744073709551615",K0=1e9,W0="aggregator",z0="CETUS",X0="DEEPBOOK",J0="KRIYA",Y0="FLOWX",Q0="TURBOS",ec="AFTERMATH",tc="integrate",ic="cetus",rc="deepbook",nc="kriya",oc="utils",sc="pool",ac="pay",lc="flowx_amm",uc="turbos",cc="aftermath",Fa="custodian_v2",Da="clob_v2",dc="flash_swap",hc="flash_swap_with_partner",fc="repay_flash_swap",pc="repay_flash_swap_with_partner",mc="flash_swap_a2b",gc="flash_swap_b2a",_c="flash_swap_with_partner_a2b",vc="flash_swap_with_partner_b2a",wc="repay_flash_swap_a2b",bc="repay_flash_swap_b2a",yc="repay_flash_swap_with_partner_a2b",Mc="repay_flash_swap_with_partner_b2a",Ac="swap_a2b",Sc="swap_b2a",Cc="transfer_or_destroy_coin",Ec="check_coins_threshold",Ic="join_vec",kc="transfer_account_cap",Tc="0x0000000000000000000000000000000000000000000000000000000000000006",Oc="0x1::coin::CoinInfo",Pc="0x1::coin::CoinStore",xc="0x2::coin::zero",Ba="0x000000000000000000000000000000000000000000000000000000000000dee9",Ua="0x000000000000000000000000000000000000000000000000000000000000dee9",Nc="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",ja="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",Rc="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",Lc="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",Fc="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",Dc="",Bc="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",Uc="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",jc="",qc="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",$c="",Hc="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",Gc="",Vc="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",Zc="",Kc="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",Wc="",Nr={AGGREGATOR_V3:"aggregator_v3"},zc="https://api-sui.cetus.zone/router_v3",Xc="https://api-sui.cetus.zone/router_v2",Jc={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},yn={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},Rr={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},Fi={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"}},ot={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:mn,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},qa=1010102;function Yc(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 pr.default(e.amount_in.toString()),amountOut:new pr.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 $a(e,t,i,r,n){return Nt(this,null,function*(){let s;if(i.liquidityChanges&&i.liquidityChanges.length>0?s=yield ed(e,i):s=yield Qc(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:hn(p)}}}let a=p0.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:hn(1003)}};if(a.data!=null){let p=Yc(a.data,i.byAmountIn);if(r>0&&n!=="0x0")if(i.byAmountIn){let g=p.amountOut.mul(new pr.default(r)).div(new pr.default(1e6));p.overlayFee=Number(g.toString()),p.amountOut=p.amountOut.sub(g)}else{let g=p.amountIn.mul(new pr.default(r)).div(new pr.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:hn(1002)}}})}function Qc(e,t,i){return Nt(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=Bi(r),k=Bi(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=${qa}`,console.log("url",U),yield fetch(U)}catch(r){return console.error(r),null}})}function ed(e,t){return Nt(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=Bi(i),k=Bi(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:qa};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 td(e){return Nt(this,null,function*(){let t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(i){return console.error("Error:",i),null}})}function yo(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 Ha=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(Ha||{}),id=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}},rd=vr(wr()),mr=9e15,Yi=1e9,Mo="0123456789abcdef",gn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",_n="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ao={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-mr,maxE:mr,crypto:!1},Ga,Di,qe=!0,Mn="[DecimalError] ",Ji=Mn+"Invalid argument: ",Va=Mn+"Precision limit exceeded",Za=Mn+"crypto unavailable",Ka="[object Decimal]",jt=Math.floor,It=Math.pow,nd=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,od=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,sd=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Wa=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,wi=1e7,Fe=7,ad=9007199254740991,ld=gn.length-1,So=_n.length-1,ne={toStringTag:Ka};ne.absoluteValue=ne.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),xe(e)};ne.ceil=function(){return xe(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(Ji+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())+Fe,r.rounding=1,i=ud(r,Qa(r,i)),r.precision=e,r.rounding=t,xe(Di==2||Di==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(qe=!1,s=v.s*It(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Rt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=It(i,1/3),e=jt((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=ct(g.plus(v).times(c),g.plus(p),a+2,1),Rt(c.d).slice(0,a)===(i=Rt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(xe(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")&&(xe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return qe=!0,xe(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-jt(this.e/Fe))*Fe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};ne.dividedBy=ne.div=function(e){return ct(this,new this.constructor(e))};ne.dividedToIntegerBy=ne.divToInt=function(e){var t=this,i=t.constructor;return xe(ct(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 xe(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/Sn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=_r(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 xe(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=_r(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Sn(5,e)),n=_r(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,xe(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,ct(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()?vi(i,n,s):new i(0):new i(NaN):t.isZero()?vi(i,n+4,s).times(.5):(i.precision=n+6,i.rounding=1,t=t.asin(),e=vi(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,qe=!1,i=i.times(i).minus(1).sqrt().plus(i),qe=!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,qe=!1,i=i.times(i).plus(1).sqrt().plus(i),qe=!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?xe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=ct(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=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)))};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<=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/Fe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(qe=!1,t=Math.ceil(c/Fe),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)),qe=!0,xe(a,v.precision=y,v.rounding=A,!0)};ne.isFinite=function(){return!!this.d};ne.isInteger=ne.isInt=function(){return!!this.d&&jt(this.e/Fe)>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(qe=!1,c=y+k,a=Xi(g,c),r=t?vn(v,c+10):Xi(e,c),p=ct(a,r,c,1),Lr(p.d,n=y,A))do if(c+=10,a=Xi(g,c),r=t?vn(v,c+10):Xi(e,c),p=ct(a,r,c,1),!s){+Rt(p.d).slice(n+1,n+15)+1==1e14&&(p=xe(p,y+1,0));break}while(Lr(p.d,n+=10,A));return qe=!0,xe(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 qe?xe(e,c,p):e}if(i=jt(e.e/Fe),v=jt(k.e/Fe),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/Fe),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]=wi-1;--g[n],g[r]+=wi}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=An(g,i),qe?xe(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]?xe(new r(i),r.precision,r.rounding):(qe=!1,r.modulo==9?(t=ct(i,e.abs(),0,3,1),t.s*=e.s):t=ct(i,e,0,r.modulo,1),t=t.times(e),qe=!0,i.minus(t))};ne.naturalExponential=ne.exp=function(){return Co(this)};ne.naturalLogarithm=ne.ln=function(){return Xi(this)};ne.negated=ne.neg=function(){var e=new this.constructor(this);return e.s=-e.s,xe(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)),qe?xe(e,c,p):e;if(s=jt(y.e/Fe),r=jt(e.e/Fe),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/Fe),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)/wi|0,g[n]%=wi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=An(g,r),qe?xe(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(Ji+e);return i.d?(t=za(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};ne.round=function(){var e=this,t=e.constructor;return xe(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())+Fe,r.rounding=1,i=dd(r,Qa(r,i)),r.precision=e,r.rounding=t,xe(Di>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(qe=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Rt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=jt((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(ct(a,s,i+2,1)).times(.5),Rt(s.d).slice(0,i)===(t=Rt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(xe(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")&&(xe(r,p+1,1),e=!r.times(r).eq(a));break}return qe=!0,xe(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=ct(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,xe(Di==2||Di==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=jt(v.e/Fe)+jt(e.e/Fe),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%wi|0,t=c/wi|0;s[n]=(s[n]+t)%wi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=An(s,i),qe?xe(e,y.precision,y.rounding):e};ne.toBinary=function(e,t){return To(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:(Vt(e,0,Yi),t===void 0?t=r.rounding:Vt(t,0,8),xe(i,e+i.e+1,t))};ne.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ii(r,!0):(Vt(e,0,Yi),t===void 0?t=n.rounding:Vt(t,0,8),r=xe(new n(r),e+1,t),i=Ii(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=Ii(n):(Vt(e,0,Yi),t===void 0?t=s.rounding:Vt(t,0,8),r=xe(new s(n),e+n.e+1,t),i=Ii(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=za(U)-k.e-1,a=s%Fe,t.d[0]=It(10,a<0?Fe+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(qe=!1,c=new P(Rt(U)),v=P.precision,P.precision=s=U.length*Fe*2;y=ct(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=ct(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=ct(g,r,s,1).minus(k).abs().cmp(ct(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,qe=!0,A};ne.toHexadecimal=ne.toHex=function(e,t){return To(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:Vt(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]?(qe=!1,i=ct(i,e,0,t,1).times(e),qe=!0,xe(i)):(e.s=i.s,i=e),i};ne.toNumber=function(){return+this};ne.toOctal=function(e,t){return To(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(It(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return xe(c,r,s);if(t=jt(e.e/Fe),t>=e.d.length-1&&(i=g<0?-g:g)<=ad)return n=Xa(p,c,i,r),e.s<0?new p(1).div(n):xe(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=It(+c,g),t=i==0||!isFinite(i)?jt(g*(Math.log("0."+Rt(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):(qe=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Co(e.times(Xi(c,r+i)),r),n.d&&(n=xe(n,r+5,1),Lr(n.d,r,s)&&(t=r+10,n=xe(Co(e.times(Xi(c,t+i)),t),t+5,1),+Rt(n.d).slice(r+1,r+15)+1==1e14&&(n=xe(n,r+1,0)))),n.s=a,qe=!0,p.rounding=s,xe(n,r,s))};ne.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ii(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Vt(e,1,Yi),t===void 0?t=n.rounding:Vt(t,0,8),r=xe(new n(r),e,t),i=Ii(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):(Vt(e,1,Yi),t===void 0?t=r.rounding:Vt(t,0,8)),xe(new r(i),e,t)};ne.toString=function(){var e=this,t=e.constructor,i=Ii(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};ne.truncated=ne.trunc=function(){return xe(new this.constructor(this),this.e+1,1)};ne.valueOf=ne.toJSON=function(){var e=this,t=e.constructor,i=Ii(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Rt(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=Fe-r.length,i&&(s+=zi(i)),s+=r;a=e[t],r=a+"",i=Fe-r.length,i&&(s+=zi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Vt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Ji+e)}function Lr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Fe,n=0):(n=Math.ceil((t+1)/Fe),t%=Fe),s=It(10,Fe-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)==It(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)==It(10,t-3)-1,a}function fn(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 ud(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Sn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=_r(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 ct=(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,le,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=wi,k=Fe,v=jt(r.e/k)-jt(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++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%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,Ga=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,xe(j,c?s+j.e+1:s,a,U)}return j}})();function xe(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+=Fe,a=t,v=y[A=0],p=v/It(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Fe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Fe,a=s-Fe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Fe,a=s-Fe+n,p=a<0?0:v/It(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%It(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/It(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]=It(10,(Fe-t%Fe)%Fe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=It(10,Fe-s),y[A]=a>0?(v/It(10,n-a)%It(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]==wi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=wi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return qe&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Ii(e,t,i){if(!e.isFinite())return Ya(e);var r,n=e.e,s=Rt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+zi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+zi(-n-1)+s,i&&(r=i-a)>0&&(s+=zi(r))):n>=a?(s+=zi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+zi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=zi(r))),s}function An(e,t){var i=e[0];for(t*=Fe;i>=10;i/=10)t++;return t}function vn(e,t,i){if(t>ld)throw qe=!0,i&&(e.precision=i),Error(Va);return xe(new e(gn),t,1,!0)}function vi(e,t,i){if(t>So)throw Error(Va);return xe(new e(_n),t,i,!0)}function za(e){var t=e.length-1,i=t*Fe+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 zi(e){for(var t="";e--;)t+="0";return t}function Xa(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Fe+4);for(qe=!1;;){if(i%2&&(s=s.times(t),ha(s.d,a)&&(n=!0)),i=jt(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 qe=!0,s}function da(e){return e.d[e.d.length-1]&1}function Ja(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 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?(qe=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(It(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=xe(s.times(e),p,1),i=i.times(++v),c=a.plus(ct(s,i,p,1)),Rt(c.d).slice(0,p)===Rt(a.d).slice(0,p)){for(n=y;n--;)a=xe(a.times(a),p,1);if(t==null)if(g<3&&Lr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return xe(a,A.precision=U,k,qe=!0);else return A.precision=U,a}a=c}}function Xi(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?(qe=!1,v=X):v=t,j.precision=v+=U,i=Rt(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=Rt(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=vn(j,v+2,X).times(s+""),P=Xi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?xe(P,X,K,qe=!0):P;for(y=P,p=a=P=ct(P.minus(1),P.plus(1),v,1),A=xe(P.times(P),v,1),n=3;;){if(a=xe(a.times(A),v,1),g=p.plus(ct(a,new j(n),v,1)),Rt(g.d).slice(0,v)===Rt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(vn(j,v+2,X).times(s+""))),p=ct(p,new j(k),v,1),t==null)if(Lr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=ct(y.minus(1),y.plus(1),v,1),A=xe(P.times(P),v,1),n=c=1;else return xe(p,j.precision=X,K,qe=!0);else return j.precision=X,p;p=g,n+=2}}function Ya(e){return String(e.s*e.s/0)}function Eo(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)%Fe,i<0&&(r+=Fe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Fe;r<n;)e.d.push(+t.slice(r,r+=Fe));t=t.slice(r),r=Fe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),qe&&(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 cd(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Wa.test(t))return Eo(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(od.test(t))i=16,t=t.toLowerCase();else if(nd.test(t))i=2;else if(sd.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=Xa(r,new r(i),s,s*2)),g=fn(t,i,wi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=An(g,v),e.d=g,qe=!1,a&&(e=ct(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?It(2,p):Dr.pow(2,p))),qe=!0,e)}function dd(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:_r(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Sn(5,i)),t=_r(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 _r(e,t,i,r,n){var s,a,c,p,g=e.precision,v=Math.ceil(g/Fe);for(qe=!1,p=i.times(i),c=new e(r);;){if(a=ct(c.times(p),new e(t++*t++),g,1),c=n?r.plus(a):r.minus(a),r=ct(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 qe=!0,a.d.length=v+1,a}function Sn(e,t){for(var i=e;--t;)i*=e;return i}function Qa(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 Di=r?4:1,t;if(i=t.divToInt(n),i.isZero())Di=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Di=da(i)?r?2:3:r?4:1,t;Di=da(i)?r?1:4:r?3:2}return t.minus(n).abs()}function To(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Vt(i,1,Yi),r===void 0?r=k.rounding:Vt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Ya(e);else{for(v=Ii(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=fn(Ii(A),10,n),A.e=A.d.length),y=fn(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=ct(e,A,i,r,0,n),y=e.d,s=e.e,g=Ga),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=fn(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 ha(e,t){if(e.length>t)return e.length=t,!0}function hd(e){return new this(e).abs()}function fd(e){return new this(e).acos()}function pd(e){return new this(e).acosh()}function md(e,t){return new this(e).plus(t)}function gd(e){return new this(e).asin()}function _d(e){return new this(e).asinh()}function vd(e){return new this(e).atan()}function wd(e){return new this(e).atanh()}function bd(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(ct(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(ct(e,t,s,1)),i}function yd(e){return new this(e).cbrt()}function Md(e){return xe(e=new this(e),e.e+1,2)}function Ad(e,t,i){return new this(e).clamp(t,i)}function Sd(e){if(!e||typeof e!="object")throw Error(Mn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Yi,"rounding",0,8,"toExpNeg",-mr,0,"toExpPos",0,mr,"maxE",0,mr,"minE",-mr,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(jt(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(Za);else this[i]=!1;else throw Error(Ji+i+": "+r);return this}function Cd(e){return new this(e).cos()}function Ed(e){return new this(e).cosh()}function el(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,fa(s)){g.s=s.s,qe?!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++;qe?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 Eo(g,s.toString())}else if(p!=="string")throw Error(Ji+s);return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Wa.test(s)?Eo(g,s):cd(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=Sd,n.clone=el,n.isDecimal=fa,n.abs=hd,n.acos=fd,n.acosh=pd,n.add=md,n.asin=gd,n.asinh=_d,n.atan=vd,n.atanh=wd,n.atan2=bd,n.cbrt=yd,n.ceil=Md,n.clamp=Ad,n.cos=Cd,n.cosh=Ed,n.div=Id,n.exp=kd,n.floor=Td,n.hypot=Od,n.ln=Pd,n.log=xd,n.log10=Rd,n.log2=Nd,n.max=Ld,n.min=Fd,n.mod=Dd,n.mul=Bd,n.pow=Ud,n.random=jd,n.round=qd,n.sign=$d,n.sin=Hd,n.sinh=Gd,n.sqrt=Vd,n.sub=Zd,n.sum=Kd,n.tan=Wd,n.tanh=zd,n.trunc=Xd,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 Id(e,t){return new this(e).div(t)}function kd(e){return new this(e).exp()}function Td(e){return xe(e=new this(e),e.e+1,3)}function Od(){var e,t,i=new this(0);for(qe=!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 qe=!0,new this(1/0);i=t}return qe=!0,i.sqrt()}function fa(e){return e instanceof Dr||e&&e.toStringTag===Ka||!1}function Pd(e){return new this(e).ln()}function xd(e,t){return new this(e).log(t)}function Nd(e){return new this(e).log(2)}function Rd(e){return new this(e).log(10)}function Ld(){return Ja(this,arguments,"lt")}function Fd(){return Ja(this,arguments,"gt")}function Dd(e,t){return new this(e).mod(t)}function Bd(e,t){return new this(e).mul(t)}function Ud(e,t){return new this(e).pow(t)}function jd(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Vt(e,1,Yi),r=Math.ceil(e/Fe),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(Za);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Fe,r&&e&&(n=It(10,Fe-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-=Fe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Fe&&(i-=Fe-r)}return a.e=i,a.d=c,a}function qd(e){return xe(e=new this(e),e.e+1,this.rounding)}function $d(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Hd(e){return new this(e).sin()}function Gd(e){return new this(e).sinh()}function Vd(e){return new this(e).sqrt()}function Zd(e,t){return new this(e).sub(t)}function Kd(){var e=0,t=arguments,i=new this(t[e]);for(qe=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return qe=!0,xe(i,this.precision,this.rounding)}function Wd(e){return new this(e).tan()}function zd(e){return new this(e).tanh()}function Xd(e){return xe(e=new this(e),e.e+1,1)}ne[Symbol.for("nodejs.util.inspect.custom")]=ne.toString;ne[Symbol.toStringTag]="Decimal";var Dr=ne.constructor=el(Ao);gn=new Dr(gn);_n=new Dr(_n);var wn=Dr;function Jd(e,t,i){return Number(tl(new wn(e.toString()),t,i).toFixed(0))}function pa(e,t,i){let r=tl(new wn(e.toString()),t,i);return new rd.default(r.toFixed(0))}function tl(e,t,i){return t?e.mul(1-i):e.mul(1+i)}var ma=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?ot.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(yt.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(yt.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})}},Yd=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::kriya_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Qd=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::flowx_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},eh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::turbos::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},th=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::bluefin::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ih=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::momentum::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},rh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::magma::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},nh=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?ot.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})}},oh=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?ot.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})}},sh=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?ot.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})}},ah=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::deepbookv3::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?Rr.Mainnet:Rr.Testnet}},lh=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})}},uh=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?ot.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(yt.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})}},ch=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?ot.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(yt.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})}},ga=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?ot.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})}},dh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},hh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::obric::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},fh=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?ot.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(yt.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(yt.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})}},ph=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?ot.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(yt.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(yt.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(yt.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})}},mh=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?ot.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(yt.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(yt.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(yt.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})}},gh="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",_h="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",vh="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",wh=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?ot.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 gh:{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 _h:case vh:{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(yt.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})}},bh=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?ot.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})}},yh=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?ot.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})}},Mh=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?ot.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})}},Ah=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?ot.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})}},Sh=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?ot.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})}},Ch=ot.DEFAULT_PUBLISHED_AT.Mainnet;function Br(e,t){return e&&e.has(Nr.AGGREGATOR_V3)?e.get(Nr.AGGREGATOR_V3):t||Ch}function _a(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=Br(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 va(e,t){let{swapContext:i,targetCoinType:r,aggregatorPublishedAt:n,packages:s}=e,a=Br(s,n);return t.moveCall({target:`${a}::router::confirm_swap`,typeArguments:[r],arguments:[i]})}function Eh(e,t){let{coinType:i,amount:r,swapCtx:n,aggregatorPublishedAt:s,packages:a}=e,c=Br(a,s),p=[n,t.pure.u64(r.toString())];return t.moveCall({target:`${c}::router::take_balance`,typeArguments:[i],arguments:p})}function Ih(e,t){let{balance:i,coinType:r,recipient:n,aggregatorPublishedAt:s,packages:a}=e,c=Br(a,s),p=[i,t.pure.address(n)];t.moveCall({target:`${c}::router::transfer_balance`,typeArguments:[r],arguments:p})}function kh(e,t){let{coin:i,coinType:r,aggregatorPublishedAt:n,packages:s}=e,a=Br(s,n);t.moveCall({target:`${a}::router::transfer_or_destroy_coin`,typeArguments:[r],arguments:[i]})}function Th(){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 Oh(){let e=Date.now(),t=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${e.toString(16)}_${t}`}function il(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 Ph(e){if(!il(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 xh(e,t,i){return Nt(this,null,function*(){let r=yield Nh(t,i);return r!==null?{accountCap:e.object(r),isCreate:!1}:{accountCap:e.moveCall({target:`${Ua}::${Da}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function Nh(e,t){return Nt(this,null,function*(){let i=50,r=null;for(;;){let n=e.getOwnedObjects({owner:t,cursor:r,limit:i,filter:{MoveModule:{package:Ba,module:Fa}}});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 Rh(e,t){return t?.has("aggregator_v2")?t.get("aggregator_v2"):e||yn.V2.Mainnet}function Lh(e,t){return t?.has("aggregator_v2_extend")?t.get("aggregator_v2_extend"):e||yn.V2_EXTEND.Mainnet}function Fh(e,t){return t?.has("aggregator_v2_extend2")?t.get("aggregator_v2_extend2"):e||yn.V2_EXTEND2.Mainnet}var Kt=vr(wr());function Dh(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:Bh(r),gasUsed:r.computationCost||"0",gasPrice:"1000",success:!0}}function Bh(e){let t=new Kt.default(e.computationCost||"0"),i=new Kt.default(e.storageCost||"0"),r=new Kt.default(e.storageRebate||"0"),n=new Kt.default(e.nonRefundableStorageFee||"0");return t.add(i).sub(r).add(n).toString()}function Uh(e,t){let i=new Kt.default(t);return i.isZero()?0:e.div(i).toNumber()}function jh(e,t,i=1){let r=e.mul(new Kt.default(Math.floor(i*1e6))).div(new Kt.default(1e6));return r.isZero()?0:r.sub(t).mul(new Kt.default(1e4)).div(r).toNumber()/100}function qh(e,t){let i=e.filter(c=>c.gasMetrics.success),r=t.filter(c=>c.gasMetrics.success),n=wa(i),s=wa(r),a=n.isZero()?0:n.sub(s).mul(new Kt.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 wa(e){return e.length===0?new Kt.default(0):e.reduce((i,r)=>i.add(new Kt.default(r.gasMetrics.totalGasCost)),new Kt.default(0)).div(new Kt.default(e.length))}function $h(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 Hh(e){return JSON.stringify(e,null,2)}function Gh(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 ba=vr(wr()),Vh=e=>{var t,i,r;return pn(xr({},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=pn(xr({},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})})},Zh=e=>{var t;return pn(xr({},e),{amountIn:new ba.default(e?.amountIn),amountOut:new ba.default(e?.amountIn),paths:(t=e?.paths)==null?void 0:t.map(r=>{var n,s,a,c;let p=xr({},r);return r?.initialPrice&&(p.initialPrice=new wn((n=r?.initialPrice)==null?void 0:n.toString())),(s=r?.extendedDetails)!=null&&s.after_sqrt_price&&(p.extendedDetails={after_sqrt_price:new wn((c=(a=r?.extendedDetails)==null?void 0:a.after_sqrt_price)==null?void 0:c.toString())}),p})})};function Kh(e,t=!0){return Nt(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((i,r)=>{t&&console.log(`transaction ${r}: `,JSON.stringify(i,Wh,2))})})}function Wh(e,t){return typeof t=="bigint"?t.toString():t}function zh(e){return!(!e.startsWith("0x")||e.length!==66)}var Xh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Jh=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?ot.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(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::fullsail::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},bn="CETUS",Yh="DEEPBOOK",Oo="KRIYA",Po="FLOWX",xo="FLOWXV3",No="KRIYAV3",Ro="TURBOS",Lo="AFTERMATH",Fo="HAEDAL",Do="VOLO",Bo="AFSUI",Uo="BLUEMOVE",jo="DEEPBOOKV3",qo="SCALLOP",$o="SUILEND",Ho="BLUEFIN",Cn="HAEDALPMM",Go="ALPHAFI",Vo="SPRINGSUI",Zo="STEAMM",En="METASTABLE",In="OBRIC",Ko="HAWAL",kn="STEAMM_OMM",Wo="MOMENTUM",Tn="STEAMM_OMM_V2",zo="MAGMA",On="SEVENK",Pn="HAEDALHMMV2",Xo="FULLSAIL",nl="https://api-sui.cetus.zone/router_v3",xn=[bn,Oo,Po,xo,No,Ro,Lo,Fo,Do,Bo,Uo,jo,qo,$o,Ho,Cn,Go,Vo,Zo,En,In,Ko,Wo,kn,Tn,zo,On,Pn,Xo];function Qh(){return xn}function ef(e){return xn.filter(t=>!e.includes(t))}function tf(e){return xn.filter(t=>e.includes(t))}function ya(e){let t=new Set;for(let i of e){if(i.provider===Cn&&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===En&&(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===In&&(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===kn||i.provider===Tn)&&(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===On&&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===Pn&&i.extendedDetails&&i.extendedDetails.haedalhmmv2_base_price_seed&&t.add(i.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(t)}var ol=class sl{constructor(t){var i,r;this.endpoint=t.endpoint?rl(t.endpoint):nl,this.client=t.client||new sa.SuiClient({url:sa.getFullnodeUrl("mainnet")}),this.signer=t.signer||"",this.env=t.env||0;let n=sl.CONFIG[this.env];if(this.pythConnections=this.newPythClients((i=t.pythUrls)!=null?i:[]),this.pythClient=new aa.SuiPythClient(this.client,n.pythStateId,n.wormholeStateId),this.apiKey=t.apiKey||"",this.partner=t.partner,t.overlayFeeRate)if(t.overlayFeeRate>0&&t.overlayFeeRate<=Fi.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=t.overlayFeeRate*ot.FEE_DENOMINATOR,this.overlayFeeRate>ot.MAX_FEE_RATE)throw new Error(Fi.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(Fi.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(r=t.overlayFeeReceiver)!=null?r:Fi.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(t){return t.includes("https://hermes.pyth.network")||t.push("https://hermes.pyth.network"),t.map(r=>new aa.SuiPriceServiceConnection(r,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?Rr.Mainnet:Rr.Testnet}getOneCoinUsedToMerge(t){return Nt(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 Nt(this,null,function*(){return $a(this.endpoint,this.apiKey,t,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(t,i,r,n,s,a,c,p,g){return Nt(this,null,function*(){})}newDexRouterV3(t,i,r){switch(t){case bn:return new ma(this.env,r);case No:return new Yd(this.env);case xo:return new Qd(this.env);case Ro:return new eh(this.env);case Ho:return new th(this.env);case Wo:return new ih(this.env);case zo:return new rh(this.env);case Oo:return new nh(this.env);case Po:return new oh(this.env);case Uo:return new sh(this.env);case jo:return new ah(this.env);case Lo:return new lh(this.env);case Zo:return new uh(this.env);case qo:return new ch(this.env);case $o:return new ga(this.env);case Vo:return new ga(this.env);case Cn:return new dh(this.env,i);case In:return new hh(this.env,i);case On:return new fh(this.env,i);case kn:return new ph(this.env,i);case Tn:return new mh(this.env,i);case En:return new wh(this.env,i);case Go:return new bh(this.env);case Do:return new yh(this.env);case Bo:return new Mh(this.env);case Fo:return new Ah(this.env);case Ko:return new Sh(this.env);case Pn:return new Xh(this.env,i);case Xo:return new Jh(this.env);default:throw new Error(`${Fi.ERRORS.UNSUPPORTED_DEX} ${t}`)}}expectInputSwapV3(t,i,r,n,s,a,c){if(r.quoteID==null)throw new Error(Fi.ERRORS.QUOTE_ID_REQUIRED);let p=yo(r),g=_a({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 va({swapContext:g,targetCoinType:p.targetCoinType,packages:p.packages},t)}expectOutputSwapV3(t,i,r,n,s,a){let c=[],p=new ma(this.env,a),g=yo(r),v=_a({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=of(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=Eh({coinType:g.fromCoinType,amount:mn,swapCtx:v,packages:g.packages},t);return Ih({balance:U,coinType:g.fromCoinType,recipient:this.signer,packages:g.packages},t),va({swapContext:v,targetCoinType:g.targetCoinType,packages:g.packages},t)}routerSwap(t){return Nt(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(Fi.ERRORS.INVALID_SLIPPAGE);let p=t.router.byAmountIn,g=i.amountIn,v=i.amountOut,y=new St.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(p?y=v.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)):y=g.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)));let A=p?v.sub(y):v,k=p?g:g.add(y),U=pa(p?A:k,p,n);if(!t.router.packages||!t.router.packages.get(Nr.AGGREGATOR_V3))throw new Error(Fi.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 Nt(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 St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()):v=Number(i.amountIn.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()));let y=g?i.amountOut.sub(new St.default(v)):i.amountOut,A=g?i.amountIn:i.amountIn.add(new St.default(v)),k=Jd(g?y:A,g,r),U=g?A:k,P=vo.coinWithBalance({balance:BigInt(U.toString()),useGasCoin:!0,type:c}),W;a&&a>0&&(W=vo.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(_i.isSuiCoin(p))n.mergeCoins(n.gas,[K]);else{let X=yield this.getOneCoinUsedToMerge(p);X!=null?n.mergeCoins(n.object(X),[K]):kh({coin:K,coinType:p,packages:i.packages},n)}})}fixableRouterSwapV3(t){return Nt(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 St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()):p=Number(i.amountIn.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()));let g=i.byAmountIn?i.amountOut.sub(new St.default(p)):i.amountOut,v=i.byAmountIn?i.amountIn:i.amountIn.add(new St.default(p)),y=pa(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 Nt(this,null,function*(){var i,r,n,s;let{from:a,target:c,amount:p,byAmountIn:g,pools:v}=t,y=Bi(a),A=Bi(c),k=new vo.Transaction,U=Ra(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 St.default(0):new St.default(mn),Y=0;for(let l=0;l<Q.length;l+=1)if(!Q[l].parsedJson.data.is_exceed)if(t.byAmountIn){let d=new St.default(Q[l].parsedJson.data.amount_out);d.gt(se)&&(Y=l,se=d)}else{let d=new St.default(Q[l].parsedJson.data.amount_out);d.lt(se)&&(Y=l,se=d)}let le=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(le.fee_rate)/1e6,R=new St.default((r=le.amount_in)!=null?r:0),N=new St.default((n=le.fee_amount)!=null?n:0),S=R.add(N),h={amountIn:S,amountOut:new St.default((s=le.amount_out)!=null?s:0),paths:[{id:v[Y],direction:U,provider:bn,from:y,target:A,feeRate:O,amountIn:S.toString(),amountOut:le.amount_out,publishedAt:ja,extendedDetails:{afterSqrtPrice:le.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn,quoteID:`degraded-${nf()}`,packages:new Map([[Nr.AGGREGATOR_V3,ot.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:le.is_exceed,routeData:h}})}updatePythPriceIDs(t,i){return Nt(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 Nt(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:t,sender:this.signer})})}sendTransaction(t,i){return Nt(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:t,signer:i})})}};ol.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var rf=ol;function nf(){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 of(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 sf=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=Bo;J.AFTERMATH=Lo;J.AFTERMATH_AMM=ec;J.AFTERMATH_MODULE=cc;J.AGGREGATOR=W0;J.AGGREGATOR_V3_CONFIG=ot;J.ALL_DEXES=xn;J.ALPHAFI=Go;J.AggregatorClient=rf;J.AggregatorConfig=id;J.AggregatorError=S0;J.AggregatorServerErrorCode=Ia;J.BLUEFIN=Ho;J.BLUEMOVE=Uo;J.CETUS=bn;J.CETUS_DEX=z0;J.CETUS_MODULE=ic;J.CETUS_PUBLISHED_AT=Nc;J.CETUS_V3_PUBLISHED_AT=ja;J.CHECK_COINS_THRESHOLD_FUNC=Ec;J.CLIENT_CONFIG=Fi;J.CLOCK_ADDRESS=Tc;J.CoinInfoAddress=Oc;J.CoinStoreAddress=Pc;J.CoinUtils=_i;J.ConfigErrorCode=Ca;J.DEEPBOOKV2=Yh;J.DEEPBOOKV3=jo;J.DEEPBOOK_CLOB_V2_MODULE=Da;J.DEEPBOOK_CUSTODIAN_V2_MODULE=Fa;J.DEEPBOOK_DEX=X0;J.DEEPBOOK_MODULE=rc;J.DEEPBOOK_PACKAGE_ID=Ba;J.DEEPBOOK_PUBLISHED_AT=Ua;J.DEEPBOOK_V3_DEEP_FEE_TYPES=Rr;J.DEFAULT_AGG_V2_ENDPOINT=Xc;J.DEFAULT_AGG_V3_ENDPOINT=zc;J.DEFAULT_ENDPOINT=nl;J.DEFAULT_GAS_BUDGET_FOR_MERGE=R0;J.DEFAULT_GAS_BUDGET_FOR_SPLIT=N0;J.DEFAULT_GAS_BUDGET_FOR_STAKE=D0;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER=L0;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=F0;J.DEFAULT_NFT_TRANSFER_GAS_FEE=U0;J.Env=Ha;J.FLOWXV2=Po;J.FLOWXV3=xo;J.FLOWX_AMM=Y0;J.FLOWX_AMM_MODULE=lc;J.FULLSAIL=Xo;J.FlashSwapA2BFunc=mc;J.FlashSwapB2AFunc=gc;J.FlashSwapFunc=dc;J.FlashSwapWithPartnerA2BFunc=_c;J.FlashSwapWithPartnerB2AFunc=vc;J.FlashSwapWithPartnerFunc=hc;J.GAS_SYMBOL=B0;J.GAS_TYPE_ARG=ko;J.GAS_TYPE_ARG_LONG=xa;J.HAEDAL=Fo;J.HAEDALHMMV2=Pn;J.HAEDALPMM=Cn;J.HAWAL=Ko;J.INTEGRATE=tc;J.JOIN_FUNC=Ic;J.KRIYA=Oo;J.KRIYAV3=No;J.KRIYA_DEX=J0;J.KRIYA_MODULE=nc;J.MAGMA=zo;J.MAINNET_AFTERMATH_INSURANCE_FUND_ID=Vc;J.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=qc;J.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=Kc;J.MAINNET_AFTERMATH_REGISTRY_ID=Uc;J.MAINNET_AFTERMATH_TREASURY_ID=Hc;J.MAINNET_CETUS_GLOBAL_CONFIG_ID=Rc;J.MAINNET_FLOWX_AMM_CONTAINER_ID=Fc;J.METASTABLE=En;J.MOMENTUM=Wo;J.OBRIC=In;J.ONE=G0;J.PACKAGE_NAMES=Nr;J.PAY_MODULE=ac;J.POOL_MODULT=sc;J.PUBLISHED_ADDRESSES=yn;J.PYTH_CONFIG=Jc;J.REPAY_FLASH_SWAP_A2B_FUNC=wc;J.REPAY_FLASH_SWAP_B2A_FUNC=bc;J.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=yc;J.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=Mc;J.RepayFalshSwapFunc=fc;J.RepayFlashSwapWithPartnerFunc=pc;J.SCALLOP=qo;J.SEVENK=On;J.SPRINGSUI=Vo;J.STEAMM=Zo;J.STEAMM_OMM=kn;J.STEAMM_OMM_V2=Tn;J.SUILEND=$o;J.SUI_SYSTEM_STATE_OBJECT_ID=j0;J.SWAP_A2B_FUNC=Ac;J.SWAP_B2A_FUNC=Sc;J.SuiZeroCoinFn=xc;J.TEN_POW_NINE=K0;J.TESTNET_AFTERMATH_INSURANCE_FUND_ID=Zc;J.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=$c;J.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=Wc;J.TESTNET_AFTERMATH_REGISTRY_ID=jc;J.TESTNET_AFTERMATH_TREASURY_ID=Gc;J.TESTNET_CETUS_GLOBAL_CONFIG_ID=Lc;J.TESTNET_FLOWX_AMM_CONTAINER_ID=Dc;J.TRANSFER_ACCOUNT_CAP=kc;J.TRANSFER_OR_DESTORY_COIN_FUNC=Cc;J.TURBOS=Ro;J.TURBOS_DEX=Q0;J.TURBOS_MODULE=uc;J.TURBOS_VERSIONED=Bc;J.TWO=La;J.TransactionErrorCode=Ea;J.TypesErrorCode=Sa;J.U128=V0;J.U64_MAX=mn;J.U64_MAX_BN=Z0;J.UTILS_MODULE=oc;J.VOLO=Do;J.ZERO=sr;J.buildInputCoin=H0;J.calculateGasEfficiency=Uh;J.calculatePriceImpact=jh;J.checkInvalidSuiAddress=zh;J.compareCoins=Ra;J.compareGasMetrics=qh;J.completionCoin=Bi;J.composeType=wo;J.createTarget=O0;J.dealWithFastRouterSwapParamsForMsafe=Vh;J.exportToCSV=Gh;J.exportToJSON=Hh;J.extractAddressFromType=T0;J.extractGasMetrics=Dh;J.extractStructTagFromType=gr;J.extractTimestampFromDowngradeUuid6=Ph;J.fixSuiObjectId=Oa;J.formatGasMetrics=$h;J.generateDowngradeUuid6=Th;J.generateSimpleDowngradeUuid6=Oh;J.getAggregatorServerErrorMessage=hn;J.getAggregatorV2Extend2PublishedAt=Fh;J.getAggregatorV2ExtendPublishedAt=Lh;J.getAggregatorV2PublishedAt=Rh;J.getAllProviders=Qh;J.getDeepbookV3Config=td;J.getDefaultSuiInputType=sf;J.getOrCreateAccountCap=xh;J.getProvidersExcluding=ef;J.getProvidersIncluding=tf;J.getRouterResult=$a;J.isSortedSymbols=k0;J.isValidDowngradeUuid6=il;J.mintZeroCoin=Na;J.normalizeCoinType=bo;J.parseAftermathFeeType=$0;J.parseTurbosPoolFeeType=q0;J.patchFixSuiObjectId=Pa;J.printTransaction=Kh;J.processEndpoint=rl;J.processFlattenRoutes=yo;J.restituteMsafeFastRouterSwapParams=Zh});var tm={};du(tm,{CetusLeverageSDK:()=>Hr,default:()=>em,leverage_mainnet:()=>Qn});module.exports=hu(tm);var iu=require("@cetusprotocol/common-sdk");var Zr=require("@cetusprotocol/common-sdk");var Qn={full_rpc_url:Zr.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Zr.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};var Ts=require("@suilend/sdk/client"),At=require("@suilend/sdk");var fu=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,eo=Math.ceil,zt=Math.floor,Ht="[BigNumber Error] ",gs=Ht+"Number primitive has more than 15 significant digits: ",mi=1e14,Qe=14,to=9007199254740991,io=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Hi=1e7,Tt=1e9;function _s(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(!fu.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(Ct(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(gs+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>to||E!==zt(E)))throw Error(gs+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)%Qe,S<0&&(h+=Qe),h<l){for(h&&m.c.push(+d.slice(0,h)),l-=Qe;h<l;)m.c.push(+d.slice(h,h+=Qe));h=Qe-(d=d.slice(h)).length}else h-=l;for(;h--;d+="0");m.c.push(+d)}}else m.c=[m.e=0]}K.clone=_s,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],Ct(O,0,Tt,I),a=O),E.hasOwnProperty(I="ROUNDING_MODE")&&(O=E[I],Ct(O,0,8,I),c=O),E.hasOwnProperty(I="EXPONENTIAL_AT")&&(O=E[I],O&&O.pop?(Ct(O[0],-Tt,0,I),Ct(O[1],0,Tt,I),p=O[0],g=O[1]):(Ct(O,-Tt,Tt,I),p=-(g=O<0?-O:O))),E.hasOwnProperty(I="RANGE"))if(O=E[I],O&&O.pop)Ct(O[0],-Tt,-1,I),Ct(O[1],1,Tt,I),v=O[0],y=O[1];else if(Ct(O,-Tt,Tt,I),O)v=-(y=O<0?-O:O);else throw Error(Ht+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(Ht+"crypto unavailable");else A=O;else throw Error(Ht+I+" not true or false: "+O);if(E.hasOwnProperty(I="MODULO_MODE")&&(O=E[I],Ct(O,0,9,I),k=O),E.hasOwnProperty(I="POW_PRECISION")&&(O=E[I],Ct(O,0,Tt,I),U=O),E.hasOwnProperty(I="FORMAT"))if(O=E[I],typeof O=="object")P=O;else throw Error(Ht+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(Ht+I+" invalid: "+O)}else throw Error(Ht+"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>=-Tt&&N<=Tt&&N===zt(N)){if(R[0]===0){if(N===0&&R.length===1)return!0;break e}if(I=(N+1)%Qe,I<1&&(I+=Qe),String(R[0]).length==I){for(I=0;I<R.length;I++)if(O=R[I],O<0||O>=mi||O!==zt(O))break e;if(O!==0)return!0}}}else if(R===null&&N===null&&(S===null||S===1||S===-1))return!0;throw Error(Ht+"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 zt(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:Ct(O,0,Tt),h=eo(O/Qe),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(Ht+"crypto unavailable");if(!A)for(;l<h;)o=I(),o<9e15&&(d[l++]=o%1e14);for(h=d[--l],O%=Qe,h&&O&&(o=io[Qe-O],d[l]=zt(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-=Qe);for(l=1,o=d[0];o>=10;o/=10,l++);l<Qe&&(S-=Qe-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(xi(Wt(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=_?xi(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=xi(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%Hi,w=N/Hi|0;for(R=R.slice();_--;)l=R[_]%Hi,d=R[_]/Hi|0,h=w*l+d*b,o=b*l+h%Hi*Hi+m,m=(o/S|0)+(h/Hi|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=mi,d=Xt(R.e/Qe)-Xt(N.e/Qe),L=L/Qe|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=zt(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=zt(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==mi){for(m=1,L=M[0];L>=10;L/=10,m++);Y(u,S+(u.e=m+d*Qe-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:Ct(O,0,8),!E.c)return E.toString();if(N=E.c[0],h=E.e,I==null)l=Wt(E.c),l=R==1||R==2&&(h<=p||h>=g)?Wr(l,h):xi(l,h,"0");else if(E=Y(new K(E),I,O),S=E.e,l=Wt(E.c),o=l.length,R==1||R==2&&(I<=S||S<=p)){for(;o<I;l+="0",o++);l=Wr(l,S)}else if(I-=h+(R===2&&S>h),l=xi(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=or(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*Qe-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(Ht+"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=io;if(_){e:{for(N=1,o=_[0];o>=10;o/=10,N++);if(S=I-N,S<0)S+=Qe,h=I,l=_[d=0],m=zt(l/b[N-h-1]%10);else if(d=eo((S+1)/Qe),d>=_.length)if(R){for(;_.length<=d;_.push(0));l=m=0,N=1,S%=Qe,h=S-Qe+1}else break e;else{for(l=o=_[d],N=1;o>=10;o/=10,N++);S%=Qe,h=S-Qe+N,m=h<0?0:zt(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[(Qe-I%Qe)%Qe],E.e=-I||0):_[0]=E.e=0,E;if(S==0?(_.length=d,o=1,d--):(_.length=d+1,o=b[Qe-S],_[d]=h>0?zt(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]==mi&&(_[0]=1));break}else{if(_[d]+=o,_[d]!=mi)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 le(E){var I,O=E.e;return O===null?E.toString():(I=Wt(E.c),I=O<=p||O>=g?Wr(I,O):xi(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 or(this,new K(E,I))},n.decimalPlaces=n.dp=function(E,I){var O,R,N,S=this;if(E!=null)return Ct(E,0,Tt),I==null?I=c:Ct(I,0,8),Y(new K(S),E+S.e+1,I);if(!(O=S.c))return null;if(R=((N=O.length-1)-Xt(this.e/Qe))*Qe,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(Ht+"Exponent not an integer: "+le(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(+le(_),o?E.s*(2-Kr(E)):+le(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&&Kr(E)?-0:0,_.e>-1&&(S=1/S),new K(l?1/S:S);U&&(S=eo(U/Qe+2))}for(o?(O=new K(.5),l&&(E.s=1),d=Kr(E)):(N=Math.abs(+le(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=zt(N/2),N===0)break;d=N%2}else if(E=E.times(O),Y(E,E.e+1,1),E.e>14)d=Kr(E);else{if(N=+le(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:Ct(E,0,8),Y(I,I.e+1,E)},n.isEqualTo=n.eq=function(E,I){return or(this,new K(E,I))===0},n.isFinite=function(){return!!this.c},n.isGreaterThan=n.gt=function(E,I){return or(this,new K(E,I))>0},n.isGreaterThanOrEqualTo=n.gte=function(E,I){return(I=or(this,new K(E,I)))===1||I===0},n.isInteger=function(){return!!this.c&&Xt(this.e/Qe)>this.c.length-2},n.isLessThan=n.lt=function(E,I){return or(this,new K(E,I))<0},n.isLessThanOrEqualTo=n.lte=function(E,I){return(I=or(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/Qe,d=E.e/Qe,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=Xt(l),d=Xt(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=mi-1;R>o;){if(m[--R]<_[R]){for(O=R;O&&!m[--O];m[O]=I);--m[O],m[R]+=mi}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=Xt(q.e/Qe)+Xt(E.e/Qe),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=mi,M=Hi,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/Qe,h=E.e/Qe,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=Xt(S),h=Xt(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)/mi|0,o[I]=mi===o[I]?0:o[I]%mi;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 Ct(E,1,Tt),I==null?I=c:Ct(I,0,8),Y(new K(S),E,I);if(!(O=S.c))return null;if(N=O.length-1,R=N*Qe+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 Ct(E,-to,to),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(+le(S)),o==0||o==1/0?(I=Wt(h),(I.length+l)%2==0&&(I+="0"),o=Math.sqrt(+I),l=Xt((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))),Wt(N.c).slice(0,o)===(I=Wt(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&&(Ct(E,0,Tt),E++),X(this,E,I,1)},n.toFixed=function(E,I){return E!=null&&(Ct(E,0,Tt),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(Ht+"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(Ht+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+le(o));if(!f)return new K(w);for(I=new K(s),d=O=new K(s),R=l=new K(s),b=Wt(f),S=I.e=b.length-w.e-1,I.c[0]=io[(h=S%Qe)<0?Qe+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+le(this)},n.toPrecision=function(E,I){return E!=null&&Ct(E,1,Tt),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?Wr(Wt(O.c),N):xi(Wt(O.c),N,"0"):E===10&&j?(O=Y(new K(O),a+N+1,c),I=xi(Wt(O.c),O.e,"0")):(Ct(E,2,W.length,"Base"),I=i(xi(Wt(O.c),N,"0"),10,E,R,!0)),R<0&&O.c[0]&&(I="-"+I)),I},n.valueOf=n.toJSON=function(){return le(this)},n._isBigNumber=!0,n[Symbol.toStringTag]="BigNumber",n[Symbol.for("nodejs.util.inspect.custom")]=n.valueOf,e!=null&&K.set(e),K}function Xt(e){var t=e|0;return e>0||e===t?t:t-1}function Wt(e){for(var t,i,r=1,n=e.length,s=e[0]+"";r<n;){for(t=e[r++]+"",i=Qe-t.length;i--;t="0"+t);s+=t}for(n=s.length;s.charCodeAt(--n)===48;);return s.slice(0,n+1||1)}function or(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 Ct(e,t,i,r){if(e<t||e>i||e!==zt(e))throw Error(Ht+(r||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Kr(e){var t=e.c.length-1;return Xt(e.e/Qe)==t&&e.c[t]%2!=0}function Wr(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function xi(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 pu=_s(),Mi=pu;var Ai=require("@suilend/sdk"),cr=require("@suilend/sui-fe");var vs=Vr(require("crypto")),Xr=new Uint8Array(256),zr=Xr.length;function ro(){return zr>Xr.length-16&&(vs.default.randomFillSync(Xr),zr=0),Xr.slice(zr,zr+=16)}var Pt=[];for(let e=0;e<256;++e)Pt.push((e+256).toString(16).slice(1));function ws(e,t=0){return Pt[e[t+0]]+Pt[e[t+1]]+Pt[e[t+2]]+Pt[e[t+3]]+"-"+Pt[e[t+4]]+Pt[e[t+5]]+"-"+Pt[e[t+6]]+Pt[e[t+7]]+"-"+Pt[e[t+8]]+Pt[e[t+9]]+"-"+Pt[e[t+10]]+Pt[e[t+11]]+Pt[e[t+12]]+Pt[e[t+13]]+Pt[e[t+14]]+Pt[e[t+15]]}var bs=Vr(require("crypto")),no={randomUUID:bs.default.randomUUID};function mu(e,t,i){if(no.randomUUID&&!t&&!e)return no.randomUUID();e=e||{};let r=e.random||(e.rng||ro)();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 Jr=mu;var ys=require("@cetusprotocol/common-sdk"),oo=10n;function Ms(e){return e.depositedAmount.eq(0)?new Mi(0):e.borrowedAmount.div(e.depositedAmount).times(100)}function so(e){let t=Ms(e);if(!t.gt(100))return(0,Ai.linearlyInterpolate)(e.config.interestRate,"utilPercent","aprPercent",t)}function As(e){let t=Ms(e),i=so(e);if(!(i===void 0||t.gt(100)))return new Mi(t.div(100)).times(i.div(100)).times(1-e.config.spreadFeeBps/1e4).times(100)}function Ss(e,t,i,r){let{apiUrl:n}=(0,ys.getPackagerConfigs)(r.sdkOptions.suilend);e===Ai.Side.DEPOSIT&&([cr.NORMALIZED_flSUI_COINTYPE,cr.NORMALIZED_jugSUI_COINTYPE].includes(t.coinType)&&i.push({stats:{id:Jr(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${n}/partners/LiqAg.png`,perDay:new Mi(.036),side:Ai.Side.DEPOSIT},obligationClaims:{}}),t.coinType===cr.NORMALIZED_LBTC_COINTYPE&&i.push({stats:{id:Jr(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${n}/partners/Lombard Lux.png`,perDay:new Mi(0),side:Ai.Side.DEPOSIT},obligationClaims:{}}))}function Cs(e,t,i){return{...e,depositedAmount:t===Ai.Side.DEPOSIT?Mi.max(e.depositedAmount.plus(i),0):e.depositedAmount,borrowedAmount:t===Ai.Side.BORROW?Mi.max(e.borrowedAmount.plus(i),0):e.borrowedAmount}}function Es(e,t,i){let r=e===Ai.Side.DEPOSIT?t.depositedAmount:t.borrowedAmount,n=e===Ai.Side.DEPOSIT?i.depositedAmount:i.borrowedAmount,s=n.eq(0)?new Mi(-1):r.div(n);return{multiplier:s,isValid:!s.eq(-1)}}function Is(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 ks(e,t){if(!oo)throw new Error("oraclePriceMultiplierDecimal is required");if(e===0n)throw new Error("Invalid oracle price");if(t<0n){let i=10n**(oo- -t);return e*i}return e/10n**(t+oo)}var Bt=require("@cetusprotocol/common-sdk"),Os=require("@mysten/sui/utils"),Yr=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(le=>le.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=(0,At.getFilteredRewards)(g);Ss(p,a,v,this.sdk);let y=(0,At.getStakingYieldAprPercent)(p,a.coinType,n),A=p===At.Side.DEPOSIT?a.depositAprPercent:a.borrowAprPercent,k=A,U=Cs(a,p,i);k=p===At.Side.DEPOSIT?As(U):so(U);let{multiplier:P,isValid:W}=Es(p,a,U),j=(0,At.getDedupedPerDayRewards)(v),K=(0,At.getDedupedAprRewards)(v),{newPerDayRewards:X,newAprRewards:Q}=Is(j,K,P,W),se=(0,At.getTotalAprPercent)(p,A,v,y),Y=k===void 0||Q.some(le=>le.stats.aprPercent===void 0)?void 0:(0,At.getTotalAprPercent)(p,k,Q,y);return{borrowLimit:a.config.borrowLimit.toString(),borrowedAmount:a.borrowedAmount.toString(),remainingBorrowLimit:(0,Bt.d)(a.config.borrowLimit.toString()).sub((0,Bt.d)(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}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(i,r)).createObligation(t)};this.refreshReservePrices=async(t,i,r)=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Bt.getPackagerConfigs)(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}=(0,Bt.getPackagerConfigs)(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=>(0,Os.toHEX)(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=(0,Bt.d)(A).mul((0,Bt.d)(10).pow((0,Bt.d)(k))).toString(),P={coin_type:y.coinType.name,price:U,oracle_price:0n,last_update_time:v.publishTime};P.oracle_price=ks(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}=(0,Bt.getPackagerConfigs)(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==(0,Bt.removeHexPrefix)(t)||p.coinType.name==(0,Bt.removeHexPrefix)(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 Ts.SuilendClient.initialize(t,i,this.sdk.FullClient,!0)),this.suilendClientCache[r]}async getLendingMarketData(t=!1){if(!t&&this.lendingMarketCache)return this.lendingMarketCache;let i=(0,Bt.getPackagerConfigs)(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(0,At.initializeSuilend)(this.sdk.FullClient,c),{rewardPriceMap:j}=await(0,At.initializeSuilendRewards)(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 Mi(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(0,At.initializeObligations)(this.sdk.FullClient,n.suilendClient,n.refreshedRawReserves,n.reserveMap,this.sdk.senderAddress),c=(0,At.formatRewards)(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}=(0,Bt.getPackagerConfigs)(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=(0,At.getNetAprPercent)(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}};var ae=require("@cetusprotocol/common-sdk");var dr=9e15,Ki=1e9,ao="0123456789abcdef",tn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",rn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",lo={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-dr,maxE:dr,crypto:!1},Rs,Ni,je=!0,on="[DecimalError] ",Zi=on+"Invalid argument: ",Ls=on+"Precision limit exceeded",Fs=on+"crypto unavailable",Ds="[object Decimal]",Ut=Math.floor,Et=Math.pow,gu=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,_u=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,vu=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Bs=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,gi=1e7,Le=7,wu=9007199254740991,bu=tn.length-1,uo=rn.length-1,re={toStringTag:Ds};re.absoluteValue=re.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Pe(e)};re.ceil=function(){return Pe(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(Zi+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())+Le,r.rounding=1,i=yu(r,Hs(r,i)),r.precision=e,r.rounding=t,Pe(Ni==2||Ni==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(je=!1,s=v.s*Et(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=xt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=Et(i,1/3),e=Ut((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=ut(g.plus(v).times(c),g.plus(p),a+2,1),xt(c.d).slice(0,a)===(i=xt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Pe(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")&&(Pe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return je=!0,Pe(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-Ut(this.e/Le))*Le,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};re.dividedBy=re.div=function(e){return ut(this,new this.constructor(e))};re.dividedToIntegerBy=re.divToInt=function(e){var t=this,i=t.constructor;return Pe(ut(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 Pe(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/an(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=hr(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 Pe(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=hr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/an(5,e)),n=hr(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,Pe(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,ut(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()?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))};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,je=!1,i=i.times(i).minus(1).sqrt().plus(i),je=!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,je=!1,i=i.times(i).plus(1).sqrt().plus(i),je=!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?Pe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=ut(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=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)))};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<=uo)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<=uo)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/Le+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(je=!1,t=Math.ceil(c/Le),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)),je=!0,Pe(a,v.precision=y,v.rounding=A,!0)};re.isFinite=function(){return!!this.d};re.isInteger=re.isInt=function(){return!!this.d&&Ut(this.e/Le)>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(je=!1,c=y+k,a=Vi(g,c),r=t?nn(v,c+10):Vi(e,c),p=ut(a,r,c,1),Or(p.d,n=y,A))do if(c+=10,a=Vi(g,c),r=t?nn(v,c+10):Vi(e,c),p=ut(a,r,c,1),!s){+xt(p.d).slice(n+1,n+15)+1==1e14&&(p=Pe(p,y+1,0));break}while(Or(p.d,n+=10,A));return je=!0,Pe(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 je?Pe(e,c,p):e}if(i=Ut(e.e/Le),v=Ut(k.e/Le),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/Le),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=sn(g,i),je?Pe(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]?Pe(new r(i),r.precision,r.rounding):(je=!1,r.modulo==9?(t=ut(i,e.abs(),0,3,1),t.s*=e.s):t=ut(i,e,0,r.modulo,1),t=t.times(e),je=!0,i.minus(t))};re.naturalExponential=re.exp=function(){return co(this)};re.naturalLogarithm=re.ln=function(){return Vi(this)};re.negated=re.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Pe(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)),je?Pe(e,c,p):e;if(s=Ut(y.e/Le),r=Ut(e.e/Le),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/Le),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=sn(g,r),je?Pe(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(Zi+e);return i.d?(t=Us(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};re.round=function(){var e=this,t=e.constructor;return Pe(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())+Le,r.rounding=1,i=Au(r,Hs(r,i)),r.precision=e,r.rounding=t,Pe(Ni>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(je=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=xt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Ut((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(ut(a,s,i+2,1)).times(.5),xt(s.d).slice(0,i)===(t=xt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Pe(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")&&(Pe(r,p+1,1),e=!r.times(r).eq(a));break}return je=!0,Pe(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=ut(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Pe(Ni==2||Ni==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=Ut(v.e/Le)+Ut(e.e/Le),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=sn(s,i),je?Pe(e,y.precision,y.rounding):e};re.toBinary=function(e,t){return ho(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:(Gt(e,0,Ki),t===void 0?t=r.rounding:Gt(t,0,8),Pe(i,e+i.e+1,t))};re.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,!0):(Gt(e,0,Ki),t===void 0?t=n.rounding:Gt(t,0,8),r=Pe(new n(r),e+1,t),i=Ci(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=Ci(n):(Gt(e,0,Ki),t===void 0?t=s.rounding:Gt(t,0,8),r=Pe(new s(n),e+n.e+1,t),i=Ci(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=Us(U)-k.e-1,a=s%Le,t.d[0]=Et(10,a<0?Le+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(Zi+c);e=c.gt(t)?s>0?t:g:c}for(je=!1,c=new P(xt(U)),v=P.precision,P.precision=s=U.length*Le*2;y=ut(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=ut(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=ut(g,r,s,1).minus(k).abs().cmp(ut(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,je=!0,A};re.toHexadecimal=re.toHex=function(e,t){return ho(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:Gt(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]?(je=!1,i=ut(i,e,0,t,1).times(e),je=!0,Pe(i)):(e.s=i.s,i=e),i};re.toNumber=function(){return+this};re.toOctal=function(e,t){return ho(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(Et(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Pe(c,r,s);if(t=Ut(e.e/Le),t>=e.d.length-1&&(i=g<0?-g:g)<=wu)return n=js(p,c,i,r),e.s<0?new p(1).div(n):Pe(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=Et(+c,g),t=i==0||!isFinite(i)?Ut(g*(Math.log("0."+xt(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):(je=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=co(e.times(Vi(c,r+i)),r),n.d&&(n=Pe(n,r+5,1),Or(n.d,r,s)&&(t=r+10,n=Pe(co(e.times(Vi(c,t+i)),t),t+5,1),+xt(n.d).slice(r+1,r+15)+1==1e14&&(n=Pe(n,r+1,0)))),n.s=a,je=!0,p.rounding=s,Pe(n,r,s))};re.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):(Gt(e,1,Ki),t===void 0?t=n.rounding:Gt(t,0,8),r=Pe(new n(r),e,t),i=Ci(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):(Gt(e,1,Ki),t===void 0?t=r.rounding:Gt(t,0,8)),Pe(new r(i),e,t)};re.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};re.truncated=re.trunc=function(){return Pe(new this.constructor(this),this.e+1,1)};re.valueOf=re.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 xt(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=Le-r.length,i&&(s+=Gi(i)),s+=r;a=e[t],r=a+"",i=Le-r.length,i&&(s+=Gi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Gt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Zi+e)}function Or(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Le,n=0):(n=Math.ceil((t+1)/Le),t%=Le),s=Et(10,Le-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)==Et(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)==Et(10,t-3)-1,a}function Qr(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]+=ao.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 yu(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/an(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=hr(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 ut=(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,le,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=Le,v=Ut(r.e/k)-Ut(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++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%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,Rs=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Pe(j,c?s+j.e+1:s,a,U)}return j}})();function Pe(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+=Le,a=t,v=y[A=0],p=v/Et(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Le),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Le,a=s-Le+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Le,a=s-Le+n,p=a<0?0:v/Et(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%Et(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/Et(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]=Et(10,(Le-t%Le)%Le),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=Et(10,Le-s),y[A]=a>0?(v/Et(10,n-a)%Et(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 je&&(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 $s(e);var r,n=e.e,s=xt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Gi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Gi(-n-1)+s,i&&(r=i-a)>0&&(s+=Gi(r))):n>=a?(s+=Gi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Gi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Gi(r))),s}function sn(e,t){var i=e[0];for(t*=Le;i>=10;i/=10)t++;return t}function nn(e,t,i){if(t>bu)throw je=!0,i&&(e.precision=i),Error(Ls);return Pe(new e(tn),t,1,!0)}function Si(e,t,i){if(t>uo)throw Error(Ls);return Pe(new e(rn),t,i,!0)}function Us(e){var t=e.length-1,i=t*Le+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 Gi(e){for(var t="";e--;)t+="0";return t}function js(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Le+4);for(je=!1;;){if(i%2&&(s=s.times(t),xs(s.d,a)&&(n=!0)),i=Ut(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),xs(t.d,a)}return je=!0,s}function Ps(e){return e.d[e.d.length-1]&1}function qs(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?(je=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(Et(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Pe(s.times(e),p,1),i=i.times(++v),c=a.plus(ut(s,i,p,1)),xt(c.d).slice(0,p)===xt(a.d).slice(0,p)){for(n=y;n--;)a=Pe(a.times(a),p,1);if(t==null)if(g<3&&Or(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Pe(a,A.precision=U,k,je=!0);else return A.precision=U,a}a=c}}function Vi(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?(je=!1,v=X):v=t,j.precision=v+=U,i=xt(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=xt(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=nn(j,v+2,X).times(s+""),P=Vi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Pe(P,X,K,je=!0):P;for(y=P,p=a=P=ut(P.minus(1),P.plus(1),v,1),A=Pe(P.times(P),v,1),n=3;;){if(a=Pe(a.times(A),v,1),g=p.plus(ut(a,new j(n),v,1)),xt(g.d).slice(0,v)===xt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(nn(j,v+2,X).times(s+""))),p=ut(p,new j(k),v,1),t==null)if(Or(p.d,v-U,K,c))j.precision=v+=U,g=a=P=ut(y.minus(1),y.plus(1),v,1),A=Pe(P.times(P),v,1),n=c=1;else return Pe(p,j.precision=X,K,je=!0);else return j.precision=X,p;p=g,n+=2}}function $s(e){return String(e.s*e.s/0)}function en(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)%Le,i<0&&(r+=Le),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Le;r<n;)e.d.push(+t.slice(r,r+=Le));t=t.slice(r),r=Le-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),je&&(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 Mu(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Bs.test(t))return en(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(_u.test(t))i=16,t=t.toLowerCase();else if(gu.test(t))i=2;else if(vu.test(t))i=8;else throw Error(Zi+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=js(r,new r(i),s,s*2)),g=Qr(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=sn(g,v),e.d=g,je=!1,a&&(e=ut(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?Et(2,p):Pr.pow(2,p))),je=!0,e)}function Au(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:hr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/an(5,i)),t=hr(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 hr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Le);for(je=!1,p=i.times(i),c=new e(r);;){if(a=ut(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=ut(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 je=!0,a.d.length=y+1,a}function an(e,t){for(var i=e;--t;)i*=e;return i}function Hs(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=Ps(i)?r?2:3:r?4:1,t;Ni=Ps(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?(Gt(i,1,Ki),r===void 0?r=k.rounding:Gt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=$s(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=Qr(Ci(A),10,n),A.e=A.d.length),y=Qr(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=ut(e,A,i,r,0,n),y=e.d,s=e.e,g=Rs),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+=ao.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=Qr(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=ao.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 xs(e,t){if(e.length>t)return e.length=t,!0}function Su(e){return new this(e).abs()}function Cu(e){return new this(e).acos()}function Eu(e){return new this(e).acosh()}function Iu(e,t){return new this(e).plus(t)}function ku(e){return new this(e).asin()}function Tu(e){return new this(e).asinh()}function Ou(e){return new this(e).atan()}function Pu(e){return new this(e).atanh()}function xu(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(ut(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(ut(e,t,s,1)),i}function Nu(e){return new this(e).cbrt()}function Ru(e){return Pe(e=new this(e),e.e+1,2)}function Lu(e,t,i){return new this(e).clamp(t,i)}function Fu(e){if(!e||typeof e!="object")throw Error(on+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Ki,"rounding",0,8,"toExpNeg",-dr,0,"toExpPos",0,dr,"maxE",0,dr,"minE",-dr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=lo[i]),(r=e[i])!==void 0)if(Ut(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(Zi+i+": "+r);if(i="crypto",n&&(this[i]=lo[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(Fs);else this[i]=!1;else throw Error(Zi+i+": "+r);return this}function Du(e){return new this(e).cos()}function Bu(e){return new this(e).cosh()}function Gs(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,Ns(s)){g.s=s.s,je?!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++;je?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 en(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),Bs.test(s)?en(g,s):Mu(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,en(g,s.toString());throw Error(Zi+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=Fu,n.clone=Gs,n.isDecimal=Ns,n.abs=Su,n.acos=Cu,n.acosh=Eu,n.add=Iu,n.asin=ku,n.asinh=Tu,n.atan=Ou,n.atanh=Pu,n.atan2=xu,n.cbrt=Nu,n.ceil=Ru,n.clamp=Lu,n.cos=Du,n.cosh=Bu,n.div=Uu,n.exp=ju,n.floor=qu,n.hypot=$u,n.ln=Hu,n.log=Gu,n.log10=Zu,n.log2=Vu,n.max=Ku,n.min=Wu,n.mod=zu,n.mul=Xu,n.pow=Ju,n.random=Yu,n.round=Qu,n.sign=e0,n.sin=t0,n.sinh=i0,n.sqrt=r0,n.sub=n0,n.sum=o0,n.tan=s0,n.tanh=a0,n.trunc=l0,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 Uu(e,t){return new this(e).div(t)}function ju(e){return new this(e).exp()}function qu(e){return Pe(e=new this(e),e.e+1,3)}function $u(){var e,t,i=new this(0);for(je=!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 je=!0,new this(1/0);i=t}return je=!0,i.sqrt()}function Ns(e){return e instanceof Pr||e&&e.toStringTag===Ds||!1}function Hu(e){return new this(e).ln()}function Gu(e,t){return new this(e).log(t)}function Vu(e){return new this(e).log(2)}function Zu(e){return new this(e).log(10)}function Ku(){return qs(this,arguments,-1)}function Wu(){return qs(this,arguments,1)}function zu(e,t){return new this(e).mod(t)}function Xu(e,t){return new this(e).mul(t)}function Ju(e,t){return new this(e).pow(t)}function Yu(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Gt(e,1,Ki),r=Math.ceil(e/Le),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(Fs);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Le,r&&e&&(n=Et(10,Le-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-=Le)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Le&&(i-=Le-r)}return a.e=i,a.d=c,a}function Qu(e){return Pe(e=new this(e),e.e+1,this.rounding)}function e0(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function t0(e){return new this(e).sin()}function i0(e){return new this(e).sinh()}function r0(e){return new this(e).sqrt()}function n0(e,t){return new this(e).sub(t)}function o0(){var e=0,t=arguments,i=new this(t[e]);for(je=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return je=!0,Pe(i,this.precision,this.rounding)}function s0(e){return new this(e).tan()}function a0(e){return new this(e).tanh()}function l0(e){return Pe(e=new this(e),e.e+1,1)}re[Symbol.for("nodejs.util.inspect.custom")]=re.toString;re[Symbol.toStringTag]="Decimal";var Pr=re.constructor=Gs(lo);tn=new Pr(tn);rn=new Pr(rn);var Ei=Pr;var go=Vr(Zs()),Ri=require("@mysten/sui/transactions");var fr=require("@cetusprotocol/common-sdk"),Ks=e=>{let t=[];return e.forEach(i=>{t.push(po(i))}),t},po=e=>{let t=(0,fr.getObjectFields)(e);return{marketId:t.id.id,baseToken:(0,fr.addHexPrefix)(t.base_token.fields.name),quoteToken:(0,fr.addHexPrefix)(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}},mo=e=>{let t=(0,fr.getObjectFields)(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}};var Li=require("@mysten/sui/utils"),Ws=require("@suilend/sdk/parsers/obligation"),zs=require("@suilend/sdk/_generated/suilend/lending-market/functions"),ln=class{constructor(t){this.getLeverageConfig=async()=>{let t=(0,ae.getPackagerConfigs)(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=(0,ae.getPackagerConfigs)(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=Ks(v);return this._sdk.updateCache(i,y,ae.CACHE_TIME_5MIN),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=po(n);return this._sdk.updateCache(i,s,ae.CACHE_TIME_5MIN),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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),n=await this._sdk.SuiLendModule.getSuilendClient(i,r),s=[];for(let a=0;a<t.data.length;a++){let c=mo(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=mo(i.data[0]),{lendingMarketId:n,lendingMarketType:s}=(0,ae.getPackagerConfigs)(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{...(0,Ws.parseObligation)(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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),v=new Ri.Transaction,{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,le;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=ae.CoinAssist.buildCoinWithBalance(BigInt(n.toString()),$,v);le=await this.routerSwap({router:ie.route_obj,slippage:a,inputCoin:C,txb:v}),Y=le}}else Y=ae.CoinAssist.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=(0,ae.d)(E).mul(U).toString(),{balanceA:N,balanceB:S,receipt:h}=this.flashLoan({amount:(0,ae.d)(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,(0,ae.d)(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=(0,ae.d)(d?.amount_out||0),_;d&&(_=await this.routerSwap({router:d.route_obj,inputCoin:O?ae.CoinAssist.fromBalance(N,P,v):ae.CoinAssist.fromBalance(S,W,v),slippage:a,txb:v}));let b=(0,ae.d)(m).add(se).mul(1-y).toDP(0,Ei.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=(0,Li.toHEX)(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=(0,ae.d)(E).add(R).toDP(0,Ei.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:(0,ae.d)(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=ae.CoinAssist.mintBalanceZero(O?W:P,v);return this.repayFlashLoan({tx:v,clmmPool:s,repayBase:O?ae.CoinAssist.intoBalance(M,P,v):q,repayQuote:O?q:ae.CoinAssist.intoBalance(M,W,v),receipt:h,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}),v.transferObjects([w],v.pure.address(this._sdk.getSenderAddress())),ae.CoinAssist.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}=(0,ae.getPackagerConfigs)(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 Ri.Transaction,se=U[0].reserveArrayIndex.toString(),Y=P[0].reserveArrayIndex.toString(),le=n&&k||!n&&!k,E;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",le);let I;if(le){let M=n&&k?A:y,q=n&&k?y:A,$=await this.findRouters(M,q,s,!0,[a]);if($){let z=ae.CoinAssist.buildCoinWithBalance(BigInt(s.toString()),M,Q);I=await this.routerSwap({router:$.route_obj,inputCoin:z,slippage:c,txb:Q}),E=I}}else E=ae.CoinAssist.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=(0,ae.d)(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:(0,ae.d)(R),clmmPool:a,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X,flashLoanCoin:O,tx:Q}),d=k?A:y,m=k?y:A,_=await this.findRouters(d,m,(0,ae.d)(R),!0,[a]),b;_&&(b=await this.routerSwap({router:_.route_obj,inputCoin:S?ae.CoinAssist.fromBalance(h,K,Q):ae.CoinAssist.fromBalance(o,X,Q),slippage:c,txb:Q})),Q.mergeCoins(b,[E]);for(let M=0;M<W.length;M++){let q=(0,Li.toHEX)(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=(0,ae.d)(R).add(N).toDP(0,Ei.ROUND_UP).toString(),f=this.borrowAsset({positionId:r,reserveArrayIndex:Y,borrowAmount:(0,ae.d)(w),baseToken:y,quoteToken:A,isLong:k,lendingMarketId:v},Q),u=ae.CoinAssist.mintBalanceZero(S?X:K,Q);return this.repayFlashLoan({tx:Q,clmmPool:a,repayBase:S?ae.CoinAssist.intoBalance(f,K,Q):u,repayQuote:S?u:ae.CoinAssist.intoBalance(f,X,Q),receipt:l,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}),ae.CoinAssist.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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),A=a||new Ri.Transaction,{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=(0,Li.toHEX)(new Uint8Array(K[b].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,w,BigInt(K[b].arrayIndex))}let{token:Y}=j[0].reserve,le=(0,ae.d)(W[0].depositedCtokenAmount.toString()).div((0,ae.d)(g)).toDP(0,Ei.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",le);let E=(0,ae.d)(Q).div((0,ae.d)(le)).toString(),I=(0,ae.d)(j[0].borrowedAmount.toString()).mul(10**Y.decimals).toString(),O=(0,ae.d)(I).mul(E).toDP(0,Ei.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:le});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:(0,ae.d)(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,(0,ae.d)(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:(0,ae.d)(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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:K}=A[0].reserve,X=new Ri.Transaction,Q=(0,ae.d)(A[0].borrowedAmount.toString()).mul((0,ae.d)(a).sub((0,ae.d)(s))).mul(10**K.decimals).toDP(0,Ei.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:le,balanceB:E,receipt:I}=this.flashLoan({tx:X,amount:(0,ae.d)(se),clmmPool:c,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,flashLoanCoin:Y}),O=n?v:g,R=n?g:v,N=await this.findRouters(O,R,(0,ae.d)(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?ae.CoinAssist.fromBalance(E,P,X):ae.CoinAssist.fromBalance(le,U,X),slippage:p,txb:X});for(let m=0;m<k.length;m++){let _=(0,Li.toHEX)(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=(0,ae.d)(se).mul((0,ae.d)(1).add(W)).toDP(0,Ei.ROUND_UP).toString(),o=await this.borrowAsset({positionId:r,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:(0,ae.d)(h),baseToken:g,quoteToken:v,isLong:n,lendingMarketId:j},X),l=ae.CoinAssist.mintBalanceZero(n?g:v,X),d=U===Y;return this.repayFlashLoan({tx:X,clmmPool:c,repayBase:n?l:ae.CoinAssist.intoBalance(o,g,X),repayQuote:n?ae.CoinAssist.intoBalance(o,v,X):l,receipt:I,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P}),ae.CoinAssist.destroyBalanceZero(d?E:le,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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),j=new Ri.Transaction,K=(0,ae.d)(A[0].depositedCtokenAmount.toString()).mul((0,ae.d)(s).sub((0,ae.d)(a))).toString(),X=(0,ae.d)(K).toDP(0,Ei.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=(0,Li.toHEX)(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 le=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:(0,ae.d)(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,(0,ae.d)(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:le,slippage:p,txb:j});return this.repay({txb:j,positionId:r,repayReserveArrayIndex:k[0].reserveArrayIndex.toString(),repayCoin:R,repayCoinType:n?v:g,repayAmount:(0,ae.d)(0)}),R&&j.transferObjects([R],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(t,i)=>{let r=i||new Ri.Transaction,{marketId:n,positionId:s}=t,{leverage:a}=this._sdk.sdkOptions,{global_config_id:c}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:p,lendingMarketId:g}=(0,ae.getPackagerConfigs)(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=(0,zs.obligation)(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(ae.CLOCK_ADDRESS)]}),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}=(0,ae.getPackagerConfigs)(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}=(0,ae.getPackagerConfigs)(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}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return ae.CoinAssist.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(Li.SUI_SYSTEM_STATE_OBJECT_ID),i.object(ae.CLOCK_ADDRESS)]}):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(ae.CLOCK_ADDRESS)]})};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}=(0,ae.getPackagerConfigs)(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 ae.CoinAssist.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(Li.SUI_SYSTEM_STATE_OBJECT_ID),i.object(ae.CLOCK_ADDRESS)]}):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(ae.CLOCK_ADDRESS)]})};this.repay=t=>{let{leverage:i}=this._sdk.sdkOptions,{lendingMarketId:r,lendingMarketType:n}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:s,positionId:a,repayAmount:c,repayCoinType:p,repayCoin:g,repayReserveArrayIndex:v}=t,y=s||new Ri.Transaction,A=g||ae.CoinAssist.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(ae.CLOCK_ADDRESS)]})};this.routerSwap=async t=>{let{slippage:i,txb:r,inputCoin:n,router:s}=t,a=r||new Ri.Transaction;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,(0,ae.d)(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[(0,ae.removeHexPrefix)(s)]?.price,v=p[(0,ae.removeHexPrefix)(n)]?.price,y=i?(0,ae.d)(v).div((0,ae.d)(g)).toString():(0,ae.d)(g).div((0,ae.d)(v)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",a.toString(),i,y,g,v),{flashAmount:(0,ae.d)(a).mul(r-1).mul(y).toDP(0,Ei.ROUND_UP).toString(),rate:y,quotePrice:g,basePrice:v}}createLeveragePosition(t){let{lendingMarketId:i,lendingMarketType:r}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:n}=(0,ae.getPackagerConfigs)(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(ae.CLOCK_ADDRESS)],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}=(0,ae.getPackagerConfigs)(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(ae.CLOCK_ADDRESS)]}),i}async findRouters(t,i,r,n,s){let{providers:a}=this._sdk.sdkOptions;try{let c={from:t,target:i,amount:new go.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 go.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 $r=Vr(al()),ru=require("@mysten/sui/utils"),nu=require("@mysten/sui/client");var wl=require("@cetusprotocol/common-sdk"),Fn=require("@mysten/sui/utils"),Ne=require("@cetusprotocol/common-sdk"),Nl=require("@cetusprotocol/common-sdk"),Ll=require("@mysten/sui/client"),yr=require("@mysten/sui/transactions"),ar=require("@mysten/sui/utils"),it=require("@cetusprotocol/common-sdk"),Bn=require("@mysten/sui/transactions"),nt=require("@cetusprotocol/common-sdk"),Un=require("@mysten/sui/transactions"),at=require("@cetusprotocol/common-sdk"),Ue=require("@cetusprotocol/common-sdk"),de=require("@cetusprotocol/common-sdk"),Dt=require("@cetusprotocol/common-sdk"),zl=require("@mysten/sui/client"),ki=require("@mysten/sui/transactions"),Jn=require("@mysten/sui/utils"),pe=require("@cetusprotocol/common-sdk"),$n=require("@mysten/sui/transactions"),Xl=require("@mysten/sui/utils"),lt=require("@cetusprotocol/common-sdk"),us=require("@mysten/sui/transactions"),cs=require("@mysten/sui/utils"),Mt=require("@cetusprotocol/common-sdk"),qt=require("@cetusprotocol/common-sdk"),ds=require("@mysten/sui/transactions"),Jl=require("@mysten/sui/utils"),Yl=require("@cetusprotocol/common-sdk"),Ql=require("@cetusprotocol/common-sdk"),tu=require("@cetusprotocol/common-sdk"),af=Object.create,vl=Object.defineProperty,lf=Object.getOwnPropertyDescriptor,uf=Object.getOwnPropertyNames,cf=Object.getPrototypeOf,df=Object.prototype.hasOwnProperty,hf=(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')}),ff=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),pf=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of uf(t))!df.call(e,n)&&n!==i&&vl(e,n,{get:()=>t[n],enumerable:!(r=lf(t,n))||r.enumerable});return e},qi=(e,t,i)=>(i=e!=null?af(cf(e)):{},pf(t||!e||!e.__esModule?vl(i,"default",{value:e,enumerable:!0}):i,e)),$i=ff((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=hf("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,ue=ee>>>13,Te=m[6]|0,he=Te&8191,_e=Te>>>13,ke=m[7]|0,ce=ke&8191,Ie=ke>>>13,st=m[8]|0,ge=st&8191,Be=st>>>13,rt=m[9]|0,me=rt&8191,Oe=rt>>>13,et=_[0]|0,fe=et&8191,Ge=et>>>13,ht=_[1]|0,ve=ht&8191,Ve=ht>>>13,ft=_[2]|0,we=ft&8191,Ze=ft>>>13,pt=_[3]|0,be=pt&8191,Ke=pt>>>13,mt=_[4]|0,ye=mt&8191,We=mt>>>13,gt=_[5]|0,Me=gt&8191,ze=gt>>>13,_t=_[6]|0,Ae=_t&8191,Xe=_t>>>13,vt=_[7]|0,Se=vt&8191,Je=vt>>>13,wt=_[8]|0,Ce=wt&8191,Ye=wt>>>13,bt=_[9]|0,Ee=bt&8191,He=bt>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,fe),u=Math.imul($,Ge),u=u+Math.imul(z,fe)|0,M=Math.imul(z,Ge);var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(C,fe),u=Math.imul(C,Ge),u=u+Math.imul(T,fe)|0,M=Math.imul(T,Ge),f=f+Math.imul($,ve)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,Ve)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(F,fe),u=Math.imul(F,Ge),u=u+Math.imul(L,fe)|0,M=Math.imul(L,Ge),f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ze)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(B,fe),u=Math.imul(B,Ge),u=u+Math.imul(D,fe)|0,M=Math.imul(D,Ge),f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ke)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(H,fe),u=Math.imul(H,Ge),u=u+Math.imul(V,fe)|0,M=Math.imul(V,Ge),f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,We)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,We)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(te,fe),u=Math.imul(te,Ge),u=u+Math.imul(ue,fe)|0,M=Math.imul(ue,Ge),f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,We)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,We)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,ze)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,ze)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,fe),u=Math.imul(he,Ge),u=u+Math.imul(_e,fe)|0,M=Math.imul(_e,Ge),f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(ue,ve)|0,M=M+Math.imul(ue,Ve)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,We)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,We)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,ze)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,ze)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Xe)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Xe)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(ce,fe),u=Math.imul(ce,Ge),u=u+Math.imul(Ie,fe)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(he,ve)|0,u=u+Math.imul(he,Ve)|0,u=u+Math.imul(_e,ve)|0,M=M+Math.imul(_e,Ve)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(ue,we)|0,M=M+Math.imul(ue,Ze)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,We)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,We)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,ze)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,ze)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Xe)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Xe)|0,f=f+Math.imul($,Se)|0,u=u+Math.imul($,Je)|0,u=u+Math.imul(z,Se)|0,M=M+Math.imul(z,Je)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(ge,fe),u=Math.imul(ge,Ge),u=u+Math.imul(Be,fe)|0,M=Math.imul(Be,Ge),f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(Ie,ve)|0,M=M+Math.imul(Ie,Ve)|0,f=f+Math.imul(he,we)|0,u=u+Math.imul(he,Ze)|0,u=u+Math.imul(_e,we)|0,M=M+Math.imul(_e,Ze)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(ue,be)|0,M=M+Math.imul(ue,Ke)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,We)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,We)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,ze)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,ze)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Xe)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Xe)|0,f=f+Math.imul(C,Se)|0,u=u+Math.imul(C,Je)|0,u=u+Math.imul(T,Se)|0,M=M+Math.imul(T,Je)|0,f=f+Math.imul($,Ce)|0,u=u+Math.imul($,Ye)|0,u=u+Math.imul(z,Ce)|0,M=M+Math.imul(z,Ye)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(me,fe),u=Math.imul(me,Ge),u=u+Math.imul(Oe,fe)|0,M=Math.imul(Oe,Ge),f=f+Math.imul(ge,ve)|0,u=u+Math.imul(ge,Ve)|0,u=u+Math.imul(Be,ve)|0,M=M+Math.imul(Be,Ve)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(Ie,we)|0,M=M+Math.imul(Ie,Ze)|0,f=f+Math.imul(he,be)|0,u=u+Math.imul(he,Ke)|0,u=u+Math.imul(_e,be)|0,M=M+Math.imul(_e,Ke)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,We)|0,u=u+Math.imul(ue,ye)|0,M=M+Math.imul(ue,We)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,ze)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,ze)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Xe)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Xe)|0,f=f+Math.imul(F,Se)|0,u=u+Math.imul(F,Je)|0,u=u+Math.imul(L,Se)|0,M=M+Math.imul(L,Je)|0,f=f+Math.imul(C,Ce)|0,u=u+Math.imul(C,Ye)|0,u=u+Math.imul(T,Ce)|0,M=M+Math.imul(T,Ye)|0,f=f+Math.imul($,Ee)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,Ee)|0,M=M+Math.imul(z,He)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(me,ve),u=Math.imul(me,Ve),u=u+Math.imul(Oe,ve)|0,M=Math.imul(Oe,Ve),f=f+Math.imul(ge,we)|0,u=u+Math.imul(ge,Ze)|0,u=u+Math.imul(Be,we)|0,M=M+Math.imul(Be,Ze)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(Ie,be)|0,M=M+Math.imul(Ie,Ke)|0,f=f+Math.imul(he,ye)|0,u=u+Math.imul(he,We)|0,u=u+Math.imul(_e,ye)|0,M=M+Math.imul(_e,We)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,ze)|0,u=u+Math.imul(ue,Me)|0,M=M+Math.imul(ue,ze)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Xe)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Xe)|0,f=f+Math.imul(B,Se)|0,u=u+Math.imul(B,Je)|0,u=u+Math.imul(D,Se)|0,M=M+Math.imul(D,Je)|0,f=f+Math.imul(F,Ce)|0,u=u+Math.imul(F,Ye)|0,u=u+Math.imul(L,Ce)|0,M=M+Math.imul(L,Ye)|0,f=f+Math.imul(C,Ee)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,Ee)|0,M=M+Math.imul(T,He)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(me,we),u=Math.imul(me,Ze),u=u+Math.imul(Oe,we)|0,M=Math.imul(Oe,Ze),f=f+Math.imul(ge,be)|0,u=u+Math.imul(ge,Ke)|0,u=u+Math.imul(Be,be)|0,M=M+Math.imul(Be,Ke)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,We)|0,u=u+Math.imul(Ie,ye)|0,M=M+Math.imul(Ie,We)|0,f=f+Math.imul(he,Me)|0,u=u+Math.imul(he,ze)|0,u=u+Math.imul(_e,Me)|0,M=M+Math.imul(_e,ze)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Xe)|0,u=u+Math.imul(ue,Ae)|0,M=M+Math.imul(ue,Xe)|0,f=f+Math.imul(H,Se)|0,u=u+Math.imul(H,Je)|0,u=u+Math.imul(V,Se)|0,M=M+Math.imul(V,Je)|0,f=f+Math.imul(B,Ce)|0,u=u+Math.imul(B,Ye)|0,u=u+Math.imul(D,Ce)|0,M=M+Math.imul(D,Ye)|0,f=f+Math.imul(F,Ee)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,Ee)|0,M=M+Math.imul(L,He)|0;var li=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(li>>>26)|0,li&=67108863,f=Math.imul(me,be),u=Math.imul(me,Ke),u=u+Math.imul(Oe,be)|0,M=Math.imul(Oe,Ke),f=f+Math.imul(ge,ye)|0,u=u+Math.imul(ge,We)|0,u=u+Math.imul(Be,ye)|0,M=M+Math.imul(Be,We)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,ze)|0,u=u+Math.imul(Ie,Me)|0,M=M+Math.imul(Ie,ze)|0,f=f+Math.imul(he,Ae)|0,u=u+Math.imul(he,Xe)|0,u=u+Math.imul(_e,Ae)|0,M=M+Math.imul(_e,Xe)|0,f=f+Math.imul(te,Se)|0,u=u+Math.imul(te,Je)|0,u=u+Math.imul(ue,Se)|0,M=M+Math.imul(ue,Je)|0,f=f+Math.imul(H,Ce)|0,u=u+Math.imul(H,Ye)|0,u=u+Math.imul(V,Ce)|0,M=M+Math.imul(V,Ye)|0,f=f+Math.imul(B,Ee)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,Ee)|0,M=M+Math.imul(D,He)|0;var ui=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,f=Math.imul(me,ye),u=Math.imul(me,We),u=u+Math.imul(Oe,ye)|0,M=Math.imul(Oe,We),f=f+Math.imul(ge,Me)|0,u=u+Math.imul(ge,ze)|0,u=u+Math.imul(Be,Me)|0,M=M+Math.imul(Be,ze)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Xe)|0,u=u+Math.imul(Ie,Ae)|0,M=M+Math.imul(Ie,Xe)|0,f=f+Math.imul(he,Se)|0,u=u+Math.imul(he,Je)|0,u=u+Math.imul(_e,Se)|0,M=M+Math.imul(_e,Je)|0,f=f+Math.imul(te,Ce)|0,u=u+Math.imul(te,Ye)|0,u=u+Math.imul(ue,Ce)|0,M=M+Math.imul(ue,Ye)|0,f=f+Math.imul(H,Ee)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,Ee)|0,M=M+Math.imul(V,He)|0;var ci=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,f=Math.imul(me,Me),u=Math.imul(me,ze),u=u+Math.imul(Oe,Me)|0,M=Math.imul(Oe,ze),f=f+Math.imul(ge,Ae)|0,u=u+Math.imul(ge,Xe)|0,u=u+Math.imul(Be,Ae)|0,M=M+Math.imul(Be,Xe)|0,f=f+Math.imul(ce,Se)|0,u=u+Math.imul(ce,Je)|0,u=u+Math.imul(Ie,Se)|0,M=M+Math.imul(Ie,Je)|0,f=f+Math.imul(he,Ce)|0,u=u+Math.imul(he,Ye)|0,u=u+Math.imul(_e,Ce)|0,M=M+Math.imul(_e,Ye)|0,f=f+Math.imul(te,Ee)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(ue,Ee)|0,M=M+Math.imul(ue,He)|0;var di=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(di>>>26)|0,di&=67108863,f=Math.imul(me,Ae),u=Math.imul(me,Xe),u=u+Math.imul(Oe,Ae)|0,M=Math.imul(Oe,Xe),f=f+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Je)|0,u=u+Math.imul(Be,Se)|0,M=M+Math.imul(Be,Je)|0,f=f+Math.imul(ce,Ce)|0,u=u+Math.imul(ce,Ye)|0,u=u+Math.imul(Ie,Ce)|0,M=M+Math.imul(Ie,Ye)|0,f=f+Math.imul(he,Ee)|0,u=u+Math.imul(he,He)|0,u=u+Math.imul(_e,Ee)|0,M=M+Math.imul(_e,He)|0;var hi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,f=Math.imul(me,Se),u=Math.imul(me,Je),u=u+Math.imul(Oe,Se)|0,M=Math.imul(Oe,Je),f=f+Math.imul(ge,Ce)|0,u=u+Math.imul(ge,Ye)|0,u=u+Math.imul(Be,Ce)|0,M=M+Math.imul(Be,Ye)|0,f=f+Math.imul(ce,Ee)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(Ie,Ee)|0,M=M+Math.imul(Ie,He)|0;var fi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,f=Math.imul(me,Ce),u=Math.imul(me,Ye),u=u+Math.imul(Oe,Ce)|0,M=Math.imul(Oe,Ye),f=f+Math.imul(ge,Ee)|0,u=u+Math.imul(ge,He)|0,u=u+Math.imul(Be,Ee)|0,M=M+Math.imul(Be,He)|0;var pi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,f=Math.imul(me,Ee),u=Math.imul(me,He),u=u+Math.imul(Oe,Ee)|0,M=Math.imul(Oe,He);var nr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(nr>>>26)|0,nr&=67108863,b[0]=Jt,b[1]=Yt,b[2]=Qt,b[3]=ei,b[4]=ti,b[5]=ii,b[6]=ri,b[7]=ni,b[8]=oi,b[9]=si,b[10]=ai,b[11]=li,b[12]=ui,b[13]=ci,b[14]=di,b[15]=hi,b[16]=fi,b[17]=pi,b[18]=nr,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 le={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(le[o])return le[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 le[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)}),bl="3.7.8",mf=bl,Tr=typeof Buffer=="function",ll=typeof TextDecoder=="function"?new TextDecoder:void 0,ul=typeof TextEncoder=="function"?new TextEncoder:void 0,gf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Ur=Array.prototype.slice.call(gf),Nn=(e=>{let t={};return e.forEach((i,r)=>t[i]=r),t})(Ur),_f=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Lt=String.fromCharCode.bind(String),cl=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),yl=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),Ml=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),Al=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+=Ur[t>>18&63]+Ur[t>>12&63]+Ur[t>>6&63]+Ur[t&63]}return a?s.slice(0,a-3)+"===".substring(a):s},hs=typeof btoa=="function"?e=>btoa(e):Tr?e=>Buffer.from(e,"binary").toString("base64"):Al,ts=Tr?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let i=0,r=e.length;i<r;i+=4096)t.push(Lt.apply(null,e.subarray(i,i+4096)));return hs(t.join(""))},Dn=(e,t=!1)=>t?yl(ts(e)):ts(e),vf=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?Lt(192|t>>>6)+Lt(128|t&63):Lt(224|t>>>12&15)+Lt(128|t>>>6&63)+Lt(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return Lt(240|t>>>18&7)+Lt(128|t>>>12&63)+Lt(128|t>>>6&63)+Lt(128|t&63)}},wf=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Sl=e=>e.replace(wf,vf),dl=Tr?e=>Buffer.from(e,"utf8").toString("base64"):ul?e=>ts(ul.encode(e)):e=>hs(Sl(e)),Sr=(e,t=!1)=>t?yl(dl(e)):dl(e),hl=e=>Sr(e,!0),bf=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,yf=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 Lt((i>>>10)+55296)+Lt((i&1023)+56320);case 3:return Lt((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return Lt((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Cl=e=>e.replace(bf,yf),El=e=>{if(e=e.replace(/\s+/g,""),!_f.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=Nn[e.charAt(s++)]<<18|Nn[e.charAt(s++)]<<12|(i=Nn[e.charAt(s++)])<<6|(r=Nn[e.charAt(s++)]),i===64?n.push(Lt(t>>16&255)):r===64?n.push(Lt(t>>16&255,t>>8&255)):n.push(Lt(t>>16&255,t>>8&255,t&255));return n.join("")},fs=typeof atob=="function"?e=>atob(Ml(e)):Tr?e=>Buffer.from(e,"base64").toString("binary"):El,Il=Tr?e=>cl(Buffer.from(e,"base64")):e=>cl(fs(e).split("").map(t=>t.charCodeAt(0))),kl=e=>Il(Tl(e)),Mf=Tr?e=>Buffer.from(e,"base64").toString("utf8"):ll?e=>ll.decode(Il(e)):e=>Cl(fs(e)),Tl=e=>Ml(e.replace(/[-_]/g,t=>t=="-"?"+":"/")),is=e=>Mf(Tl(e)),Af=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)},Ol=e=>({value:e,enumerable:!1,writable:!0,configurable:!0}),Pl=function(){let e=(t,i)=>Object.defineProperty(String.prototype,t,Ol(i));e("fromBase64",function(){return is(this)}),e("toBase64",function(t){return Sr(this,t)}),e("toBase64URI",function(){return Sr(this,!0)}),e("toBase64URL",function(){return Sr(this,!0)}),e("toUint8Array",function(){return kl(this)})},xl=function(){let e=(t,i)=>Object.defineProperty(Uint8Array.prototype,t,Ol(i));e("toBase64",function(t){return Dn(this,t)}),e("toBase64URI",function(){return Dn(this,!0)}),e("toBase64URL",function(){return Dn(this,!0)})},Sf=()=>{Pl(),xl()},Jo={version:bl,VERSION:mf,atob:fs,atobPolyfill:El,btoa:hs,btoaPolyfill:Al,fromBase64:is,toBase64:Sr,encode:Sr,encodeURI:hl,encodeURL:hl,utob:Sl,btou:Cl,decode:is,isValid:Af,fromUint8Array:Dn,toUint8Array:kl,extendString:Pl,extendUint8Array:xl,extendBuiltins:Sf},Cf=(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))(Cf||{}),Ef=(e=>(e.InvalidTickEvent="InvalidTickEvent",e.InvalidPositionObject="InvalidPositionObject",e.InvalidPositionRewardObject="InvalidPositionRewardObject",e.InvalidParams="InvalidParams",e.FetchError="FetchError",e))(Ef||{}),If=(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))(If||{}),kf=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(kf||{}),Tf=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(Tf||{}),Of=(e=>(e.InvalidConfig="InvalidConfig",e.InvalidConfigHandle="InvalidConfigHandle",e.InvalidSimulateAccount="InvalidSimulateAccount",e))(Of||{}),Pf=(e=>(e.InvalidSendAddress="InvalidSendAddress",e.InvalidRecipientAddress="InvalidRecipientAddress",e.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",e.InsufficientBalance="InsufficientBalance",e.InvalidTarget="InvalidTarget",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e))(Pf||{}),xf=(e=>(e.InvalidCoin="InvalidCoin",e.NotFoundPath="NotFoundPath",e.NoDowngradeNeedParams="NoDowngradeNeedParams",e.InvalidSwapCountUrl="InvalidSwapCountUrl",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e.InvalidServerResponse="InvalidServerResponse",e))(xf||{}),Nf=(e=>(e.InvalidType="InvalidType",e))(Nf||{}),Rl=class extends Nl.BaseError{constructor(e,t,i){super(e,t||"UnknownError",i)}static isVaultsErrorCode(e,t){return this.isErrorCode(e,t)}},ji=(e,t,i)=>{throw new Rl(t.message,e,i)},tt=(e,t,i)=>{throw new Rl(t,e,i)},Rf=class{constructor(e){this._cache={},this._sdk=e}get sdk(){return this._sdk}setTokenListCache(e){let{coin_list_handle:t}=(0,Ne.getPackagerConfigs)(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}=(0,Ne.getPackagerConfigs)(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((0,Ne.normalizeCoinType)(c)===(0,Ne.normalizeCoinType)(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,Ne.CACHE_TIME_24H)}else console.log(`not found ${a}`)}}return t}async getCoinConfigs(e=!1,t=!0){let{coin_list_handle:i}=(0,Ne.getPackagerConfigs)(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")&&tt("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let g=this.buildCoinConfig(p,t);this.updateCache(`${i}_${g.address}_getCoinConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getCoinConfig(e,t=!1,i=!0){let{coin_list_handle:r}=(0,Ne.getPackagerConfigs)(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:(0,Ne.fixCoinType)(e)}}});(a.error!=null||a.data?.content?.dataType!=="moveObject")&&tt("FetchError",`when getCoinConfig get object error: ${a.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let c=this.buildCoinConfig(a,i);return this.updateCache(n,c,Ne.CACHE_TIME_24H),c}buildCoinConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};return r.id=(0,Ne.getObjectId)(e),r.address=(0,Ne.extractStructTagFromType)(i.coin_type.fields.name).full_address,i.pyth_id&&(r.pyth_id=(0,Fn.normalizeSuiObjectId)(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}=(0,Ne.getPackagerConfigs)(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")&&tt("FetchError",`when getClmmPoolsConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let g=this.buildClmmPoolConfig(p,t);this.updateCache(`${g.pool_address}_getClmmPoolConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getClmmPoolConfig(e,t=!1,i=!0){let{clmm_pools_handle:r}=(0,Ne.getPackagerConfigs)(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,Ne.CACHE_TIME_24H),c}buildClmmPoolConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};return r.id=(0,Ne.getObjectId)(e),r.pool_address=(0,Fn.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t),r}async getLaunchpadPoolConfigs(e=!1,t=!0){let{launchpad_pools_handle:i}=(0,Ne.getPackagerConfigs)(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")&&tt("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let g=this.buildLaunchpadPoolConfig(p,t);this.updateCache(`${g.pool_address}_getLaunchpadPoolConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getLaunchpadPoolConfig(e,t=!1,i=!0){let{launchpad_pools_handle:r}=(0,Ne.getPackagerConfigs)(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,Ne.CACHE_TIME_24H),c}buildLaunchpadPoolConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};r.id=(0,Ne.getObjectId)(e),r.pool_address=(0,Fn.normalizeSuiObjectId)(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(Jo.decode(r.regulation).replace(/%/g,"%25"))}catch{r.regulation=Jo.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(Jo.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=(0,Ne.getObjectPreviousTransactionDigest)(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((0,Ne.extractStructTagFromType)(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,Ne.CACHE_TIME_24H),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")&&tt("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${i.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let r=(0,Ne.getObjectFields)(i),n=(0,Ne.getObjectType)(i);switch((0,Ne.extractStructTagFromType)(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=Ne.CACHE_TIME_5MIN){let r=this._cache[e];r?(r.overdue_time=(0,Ne.getFutureTime)(i),r.value=t):r=new Ne.CachedContent(t,(0,Ne.getFutureTime)(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}}},Lf=qi($i()),Ff="position_liquidity_snapshot",Df=(e=>(e.Deleted="Deleted",e.Exists="Exists",e.NotExists="NotExists",e))(Df||{}),Bf=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],Ti=qi($i()),Uf=qi($i()),jf="partner",Rn="pool_script",Cr="pool_script_v2",Fl="pool_script_v3",Dl="router",qf="router_with_partner",Ir="fetcher_script";var $f="utils";var Hf=qi($i()),Ar=9e15,rr=1e9,rs="0123456789abcdef",Gn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Vn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ns={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ar,maxE:Ar,crypto:!1},Bl,Ui,$e=!0,Wn="[DecimalError] ",ir=Wn+"Invalid argument: ",Ul=Wn+"Precision limit exceeded",jl=Wn+"crypto unavailable",ql="[object Decimal]",$t=Math.floor,kt=Math.pow,Gf=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Vf=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Zf=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,$l=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,yi=1e7,De=7,Kf=9007199254740991,Wf=Gn.length-1,os=Vn.length-1,oe={toStringTag:ql};oe.absoluteValue=oe.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Re(e)};oe.ceil=function(){return Re(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(ir+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())+De,r.rounding=1,i=zf(r,Kl(r,i)),r.precision=e,r.rounding=t,Re(Ui==2||Ui==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($e=!1,s=v.s*kt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Ft(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=kt(i,1/3),e=$t((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=dt(g.plus(v).times(c),g.plus(p),a+2,1),Ft(c.d).slice(0,a)===(i=Ft(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Re(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")&&(Re(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return $e=!0,Re(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-$t(this.e/De))*De,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};oe.dividedBy=oe.div=function(e){return dt(this,new this.constructor(e))};oe.dividedToIntegerBy=oe.divToInt=function(e){var t=this,i=t.constructor;return Re(dt(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 Re(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/Xn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=kr(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 Re(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=kr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Xn(5,e)),n=kr(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,Re(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,dt(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()?Oi(t,r,n):new t(0):new t(NaN):e.isZero()?Oi(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,$e=!1,i=i.times(i).minus(1).sqrt().plus(i),$e=!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,$e=!1,i=i.times(i).plus(1).sqrt().plus(i),$e=!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?Re(new s(n),e,t,!0):(s.precision=i=r-n.e,n=dt(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=Oi(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<=os)return a=Oi(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=os)return a=Oi(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/De+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for($e=!1,t=Math.ceil(c/De),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)),$e=!0,Re(a,v.precision=y,v.rounding=A,!0)};oe.isFinite=function(){return!!this.d};oe.isInteger=oe.isInt=function(){return!!this.d&&$t(this.e/De)>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($e=!1,c=y+k,a=tr(g,c),r=t?Zn(v,c+10):tr(e,c),p=dt(a,r,c,1),jr(p.d,n=y,A))do if(c+=10,a=tr(g,c),r=t?Zn(v,c+10):tr(e,c),p=dt(a,r,c,1),!s){+Ft(p.d).slice(n+1,n+15)+1==1e14&&(p=Re(p,y+1,0));break}while(jr(p.d,n+=10,A));return $e=!0,Re(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 $e?Re(e,c,p):e}if(i=$t(e.e/De),v=$t(k.e/De),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/De),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]=yi-1;--g[n],g[r]+=yi}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=zn(g,i),$e?Re(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]?Re(new r(i),r.precision,r.rounding):($e=!1,r.modulo==9?(t=dt(i,e.abs(),0,3,1),t.s*=e.s):t=dt(i,e,0,r.modulo,1),t=t.times(e),$e=!0,i.minus(t))};oe.naturalExponential=oe.exp=function(){return ss(this)};oe.naturalLogarithm=oe.ln=function(){return tr(this)};oe.negated=oe.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Re(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)),$e?Re(e,c,p):e;if(s=$t(y.e/De),r=$t(e.e/De),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/De),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)/yi|0,g[n]%=yi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=zn(g,r),$e?Re(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(ir+e);return i.d?(t=Hl(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};oe.round=function(){var e=this,t=e.constructor;return Re(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())+De,r.rounding=1,i=Jf(r,Kl(r,i)),r.precision=e,r.rounding=t,Re(Ui>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($e=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Ft(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=$t((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(dt(a,s,i+2,1)).times(.5),Ft(s.d).slice(0,i)===(t=Ft(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Re(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")&&(Re(r,p+1,1),e=!r.times(r).eq(a));break}return $e=!0,Re(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=dt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Re(Ui==2||Ui==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=$t(v.e/De)+$t(e.e/De),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%yi|0,t=c/yi|0;s[n]=(s[n]+t)%yi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=zn(s,i),$e?Re(e,y.precision,y.rounding):e};oe.toBinary=function(e,t){return ps(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:(Zt(e,0,rr),t===void 0?t=r.rounding:Zt(t,0,8),Re(i,e+i.e+1,t))};oe.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Pi(r,!0):(Zt(e,0,rr),t===void 0?t=n.rounding:Zt(t,0,8),r=Re(new n(r),e+1,t),i=Pi(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=Pi(n):(Zt(e,0,rr),t===void 0?t=s.rounding:Zt(t,0,8),r=Re(new s(n),e+n.e+1,t),i=Pi(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=Hl(U)-k.e-1,a=s%De,t.d[0]=kt(10,a<0?De+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(ir+c);e=c.gt(t)?s>0?t:g:c}for($e=!1,c=new P(Ft(U)),v=P.precision,P.precision=s=U.length*De*2;y=dt(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=dt(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=dt(g,r,s,1).minus(k).abs().cmp(dt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,$e=!0,A};oe.toHexadecimal=oe.toHex=function(e,t){return ps(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:Zt(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]?($e=!1,i=dt(i,e,0,t,1).times(e),$e=!0,Re(i)):(e.s=i.s,i=e),i};oe.toNumber=function(){return+this};oe.toOctal=function(e,t){return ps(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(kt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Re(c,r,s);if(t=$t(e.e/De),t>=e.d.length-1&&(i=g<0?-g:g)<=Kf)return n=Gl(p,c,i,r),e.s<0?new p(1).div(n):Re(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=kt(+c,g),t=i==0||!isFinite(i)?$t(g*(Math.log("0."+Ft(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):($e=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=ss(e.times(tr(c,r+i)),r),n.d&&(n=Re(n,r+5,1),jr(n.d,r,s)&&(t=r+10,n=Re(ss(e.times(tr(c,t+i)),t),t+5,1),+Ft(n.d).slice(r+1,r+15)+1==1e14&&(n=Re(n,r+1,0)))),n.s=a,$e=!0,p.rounding=s,Re(n,r,s))};oe.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Pi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Zt(e,1,rr),t===void 0?t=n.rounding:Zt(t,0,8),r=Re(new n(r),e,t),i=Pi(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):(Zt(e,1,rr),t===void 0?t=r.rounding:Zt(t,0,8)),Re(new r(i),e,t)};oe.toString=function(){var e=this,t=e.constructor,i=Pi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};oe.truncated=oe.trunc=function(){return Re(new this.constructor(this),this.e+1,1)};oe.valueOf=oe.toJSON=function(){var e=this,t=e.constructor,i=Pi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Ft(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=De-r.length,i&&(s+=er(i)),s+=r;a=e[t],r=a+"",i=De-r.length,i&&(s+=er(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Zt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(ir+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+=De,n=0):(n=Math.ceil((t+1)/De),t%=De),s=kt(10,De-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)==kt(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)==kt(10,t-3)-1,a}function jn(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]+=rs.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 zf(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Xn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=kr(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 dt=(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,le,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=yi,k=De,v=$t(r.e/k)-$t(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++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%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,Bl=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Re(j,c?s+j.e+1:s,a,U)}return j}})();function Re(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+=De,a=t,v=y[A=0],p=v/kt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/De),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=De,a=s-De+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=De,a=s-De+n,p=a<0?0:v/kt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%kt(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/kt(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]=kt(10,(De-t%De)%De),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=kt(10,De-s),y[A]=a>0?(v/kt(10,n-a)%kt(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]==yi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=yi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return $e&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Pi(e,t,i){if(!e.isFinite())return Zl(e);var r,n=e.e,s=Ft(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+er(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+er(-n-1)+s,i&&(r=i-a)>0&&(s+=er(r))):n>=a?(s+=er(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+er(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=er(r))),s}function zn(e,t){var i=e[0];for(t*=De;i>=10;i/=10)t++;return t}function Zn(e,t,i){if(t>Wf)throw $e=!0,i&&(e.precision=i),Error(Ul);return Re(new e(Gn),t,1,!0)}function Oi(e,t,i){if(t>os)throw Error(Ul);return Re(new e(Vn),t,i,!0)}function Hl(e){var t=e.length-1,i=t*De+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 er(e){for(var t="";e--;)t+="0";return t}function Gl(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/De+4);for($e=!1;;){if(i%2&&(s=s.times(t),pl(s.d,a)&&(n=!0)),i=$t(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),pl(t.d,a)}return $e=!0,s}function fl(e){return e.d[e.d.length-1]&1}function Vl(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 ss(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?($e=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(kt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Re(s.times(e),p,1),i=i.times(++v),c=a.plus(dt(s,i,p,1)),Ft(c.d).slice(0,p)===Ft(a.d).slice(0,p)){for(n=y;n--;)a=Re(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 Re(a,A.precision=U,k,$e=!0);else return A.precision=U,a}a=c}}function tr(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?($e=!1,v=X):v=t,j.precision=v+=U,i=Ft(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=Ft(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=Zn(j,v+2,X).times(s+""),P=tr(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Re(P,X,K,$e=!0):P;for(y=P,p=a=P=dt(P.minus(1),P.plus(1),v,1),A=Re(P.times(P),v,1),n=3;;){if(a=Re(a.times(A),v,1),g=p.plus(dt(a,new j(n),v,1)),Ft(g.d).slice(0,v)===Ft(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(Zn(j,v+2,X).times(s+""))),p=dt(p,new j(k),v,1),t==null)if(jr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=dt(y.minus(1),y.plus(1),v,1),A=Re(P.times(P),v,1),n=c=1;else return Re(p,j.precision=X,K,$e=!0);else return j.precision=X,p;p=g,n+=2}}function Zl(e){return String(e.s*e.s/0)}function qn(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)%De,i<0&&(r+=De),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=De;r<n;)e.d.push(+t.slice(r,r+=De));t=t.slice(r),r=De-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),$e&&(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 Xf(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),$l.test(t))return qn(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Vf.test(t))i=16,t=t.toLowerCase();else if(Gf.test(t))i=2;else if(Zf.test(t))i=8;else throw Error(ir+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=Gl(r,new r(i),s,s*2)),g=jn(t,i,yi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=zn(g,v),e.d=g,$e=!1,a&&(e=dt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?kt(2,p):qr.pow(2,p))),$e=!0,e)}function Jf(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:kr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Xn(5,i)),t=kr(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 kr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/De);for($e=!1,p=i.times(i),c=new e(r);;){if(a=dt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=dt(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 $e=!0,a.d.length=y+1,a}function Xn(e,t){for(var i=e;--t;)i*=e;return i}function Kl(e,t){var i,r=t.s<0,n=Oi(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ui=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ui=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ui=fl(i)?r?2:3:r?4:1,t;Ui=fl(i)?r?1:4:r?3:2}return t.minus(n).abs()}function ps(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Zt(i,1,rr),r===void 0?r=k.rounding:Zt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Zl(e);else{for(v=Pi(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=jn(Pi(A),10,n),A.e=A.d.length),y=jn(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=dt(e,A,i,r,0,n),y=e.d,s=e.e,g=Bl),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+=rs.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=jn(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=rs.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 pl(e,t){if(e.length>t)return e.length=t,!0}function Yf(e){return new this(e).abs()}function Qf(e){return new this(e).acos()}function ep(e){return new this(e).acosh()}function tp(e,t){return new this(e).plus(t)}function ip(e){return new this(e).asin()}function rp(e){return new this(e).asinh()}function np(e){return new this(e).atan()}function op(e){return new this(e).atanh()}function sp(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=Oi(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?Oi(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=Oi(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(dt(e,t,s,1)),t=Oi(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(dt(e,t,s,1)),i}function ap(e){return new this(e).cbrt()}function lp(e){return Re(e=new this(e),e.e+1,2)}function up(e,t,i){return new this(e).clamp(t,i)}function cp(e){if(!e||typeof e!="object")throw Error(Wn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,rr,"rounding",0,8,"toExpNeg",-Ar,0,"toExpPos",0,Ar,"maxE",0,Ar,"minE",-Ar,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($t(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(ir+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(jl);else this[i]=!1;else throw Error(ir+i+": "+r);return this}function dp(e){return new this(e).cos()}function hp(e){return new this(e).cosh()}function Wl(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,ml(s)){g.s=s.s,$e?!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++;$e?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 qn(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),$l.test(s)?qn(g,s):Xf(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,qn(g,s.toString());throw Error(ir+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=cp,n.clone=Wl,n.isDecimal=ml,n.abs=Yf,n.acos=Qf,n.acosh=ep,n.add=tp,n.asin=ip,n.asinh=rp,n.atan=np,n.atanh=op,n.atan2=sp,n.cbrt=ap,n.ceil=lp,n.clamp=up,n.cos=dp,n.cosh=hp,n.div=fp,n.exp=pp,n.floor=mp,n.hypot=gp,n.ln=_p,n.log=vp,n.log10=bp,n.log2=wp,n.max=yp,n.min=Mp,n.mod=Ap,n.mul=Sp,n.pow=Cp,n.random=Ep,n.round=Ip,n.sign=kp,n.sin=Tp,n.sinh=Op,n.sqrt=Pp,n.sub=xp,n.sum=Np,n.tan=Rp,n.tanh=Lp,n.trunc=Fp,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 fp(e,t){return new this(e).div(t)}function pp(e){return new this(e).exp()}function mp(e){return Re(e=new this(e),e.e+1,3)}function gp(){var e,t,i=new this(0);for($e=!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 $e=!0,new this(1/0);i=t}return $e=!0,i.sqrt()}function ml(e){return e instanceof qr||e&&e.toStringTag===ql||!1}function _p(e){return new this(e).ln()}function vp(e,t){return new this(e).log(t)}function wp(e){return new this(e).log(2)}function bp(e){return new this(e).log(10)}function yp(){return Vl(this,arguments,-1)}function Mp(){return Vl(this,arguments,1)}function Ap(e,t){return new this(e).mod(t)}function Sp(e,t){return new this(e).mul(t)}function Cp(e,t){return new this(e).pow(t)}function Ep(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Zt(e,1,rr),r=Math.ceil(e/De),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(jl);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=De,r&&e&&(n=kt(10,De-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-=De)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<De&&(i-=De-r)}return a.e=i,a.d=c,a}function Ip(e){return Re(e=new this(e),e.e+1,this.rounding)}function kp(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Tp(e){return new this(e).sin()}function Op(e){return new this(e).sinh()}function Pp(e){return new this(e).sqrt()}function xp(e,t){return new this(e).sub(t)}function Np(){var e=0,t=arguments,i=new this(t[e]);for($e=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return $e=!0,Re(i,this.precision,this.rounding)}function Rp(e){return new this(e).tan()}function Lp(e){return new this(e).tanh()}function Fp(e){return Re(e=new this(e),e.e+1,1)}oe[Symbol.for("nodejs.util.inspect.custom")]=oe.toString;oe[Symbol.toStringTag]="Decimal";var qr=oe.constructor=Wl(ns);Gn=new qr(Gn);Vn=new qr(Vn);var Ot=qr;function Kn(e){let t=at.CoinAssist.isSuiCoin(e.coin_type_a),i=at.CoinAssist.isSuiCoin(e.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:i}}function Dp(e,t){return Ot.ceil(Ot(e).div(1+t)).toString()}var lr=class{static createCollectRewarderAndFeeParams(e,t,i,r,n,s){n===void 0&&(n=[...r]),s===void 0&&(s=[...r]);let a=(0,at.normalizeCoinType)(i.coin_type_a),c=(0,at.normalizeCoinType)(i.coin_type_b);if(i.collect_fee){let g=at.CoinAssist.buildCoinForAmount(t,n,BigInt(0),a,!1);n=g.remain_coins;let v=at.CoinAssist.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((0,at.normalizeCoinType)(g)){case a:p.push(at.CoinAssist.buildCoinForAmount(t,n,BigInt(0),g,!1).target_coin);break;case c:p.push(at.CoinAssist.buildCoinForAmount(t,s,BigInt(0),g,!1).target_coin);break;default:p.push(at.CoinAssist.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=at.CoinAssist.selectCoinAssetGreaterThanOrEqual(t,i).selected_coins,s=at.CoinAssist.calculateTotalBalance(t);if(n.length===0&&tt("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${s}`),s-i>1e9)return{fixAmount:i};let a=await e.FullClient.calculationTxGas(Un.Transaction.from(r));if(at.CoinAssist.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&&tt("InsufficientBalance","gas Insufficient balance");let p=new Un.Transaction;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}=Kn(i),p=c?i.amount_a:i.amount_b,g=await this.adjustTransactionForGas(e,at.CoinAssist.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 Un.Transaction;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?at.CoinAssist.buildCoinForAmountInterval(e,s,{amount_second:BigInt(Dp(i,r)),amount_first:BigInt(i)},n,a,c):at.CoinAssist.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=at.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(e.tick_lower),Number(e.tick_upper),new Hf.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=(0,at.getPackagerConfigs)(p),y=r.is_open?[e.object(v.global_config_id),e.object(r.pool_id),e.pure.u32(Number((0,at.asUintN)(BigInt(r.tick_lower)).toString())),e.pure.u32(Number((0,at.asUintN)(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(at.CLOCK_ADDRESS)]:[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(at.CLOCK_ADDRESS)];return e.moveCall({target:`${g.published_at}::${Cr}::${c}`,typeArguments:a,arguments:y}),e}static checkCoinThreshold(e,t,i,r,n,s){t&&i.moveCall({target:`${e.sdkOptions.integrate.published_at}::${Dl}::check_coin_threshold`,typeArguments:[s],arguments:[r,i.pure.u64(n)]})}},Mr=class Qi{static getDefaultSqrtPriceLimit(t){return new Uf.default(t?nt.MIN_SQRT_PRICE:nt.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(t){return t?nt.ZERO:nt.U64_MAX}static async buildSwapTransactionForGas(t,i,r,n){let s=this.buildSwapTransaction(t,i,r);s.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,nt.CoinAssist.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=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a),v=nt.CoinAssist.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=Qi.getDefaultSqrtPriceLimit(i.a2b),g=[i.coin_type_a,i.coin_type_b],{global_config_id:v}=(0,nt.getPackagerConfigs)(a);v===void 0&&tt("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(nt.CLOCK_ADDRESS)]:[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(nt.CLOCK_ADDRESS)];return t.moveCall({target:`${c.published_at}::${Cr}::${A}`,typeArguments:g,arguments:k}),t}static async adjustTransactionForGas(t,i,r,n){n.setSender(t.getSenderAddress());let s=nt.CoinAssist.selectCoinAssetGreaterThanOrEqual(i,r).selected_coins,a=nt.CoinAssist.calculateTotalBalance(i);if(s.length===0&&tt("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${a}`),a-r>1e9)return{fixAmount:r};let c=await t.FullClient.calculationTxGas(n);if(nt.CoinAssist.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&&tt("InsufficientBalance","gas Insufficient balance");let g=new Bn.Transaction;return{fixAmount:r,newTx:g}}}return{fixAmount:r}}static buildSwapTransaction(t,i,r){let n=new Bn.Transaction;n.setSender(t.getSenderAddress());let s=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1),a=nt.CoinAssist.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=(0,nt.adjustForSlippage)(a,r.slippage,!r.by_amount_in);i.amount_limit=c.toString()}catch(s){ji("InvalidConfig",s)}return i}static async buildSwapTransactionWithoutTransferCoinsForGas(t,i,r,n){let{tx:s,coin_ab_s:a}=Qi.buildSwapTransactionWithoutTransferCoins(t,i,r);s.setSender(t.getSenderAddress());let c=await Qi.adjustTransactionForGas(t,nt.CoinAssist.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 Qi.fixSwapParams(t,i,n);let v=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),y=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),A=Qi.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 Bn.Transaction;n.setSender(t.getSenderAddress());let s=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),a=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),c=Qi.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=Qi.getDefaultSqrtPriceLimit(r.a2b),{global_config_id:v}=(0,nt.getPackagerConfigs)(c);v===void 0&&tt("InvalidConfig","clmm.config.global_config_id is undefined");let y=r.swap_partner!==void 0,A=y?"swap_with_partner":"swap",k=y?qf:Dl,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(nt.CLOCK_ADDRESS)]:[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(nt.CLOCK_ADDRESS)],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);lr.checkCoinThreshold(t,r.by_amount_in,i,K,X,j)}return{tx:i,txRes:W}}};function Bp(e){return{coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,current_sqrt_price:new Ti.default(e.current_sqrt_price),current_tick_index:e.current_tick_index,fee_growth_global_a:new Ti.default(e.fee_growth_global_a),fee_growth_global_b:new Ti.default(e.fee_growth_global_b),fee_protocol_coin_a:new Ti.default(e.fee_protocol_coin_a),fee_protocol_coin_b:new Ti.default(e.fee_protocol_coin_b),fee_rate:new Ti.default(e.fee_rate),liquidity:new Ti.default(e.liquidity),tick_indexes:[],tick_spacing:Number(e.tick_spacing),ticks:[],collection_name:""}}function Up(e,t,i,r,n,s){if(i===it.ZERO)return{amount_in:it.ZERO,amount_out:it.ZERO,next_sqrt_price:t,fee_amount:it.ZERO};let a=e.gte(t),c,p,g,v;if(s){let y=it.MathUtil.checkMulDivFloor(r,it.MathUtil.checkUnsignedSub(it.FEE_RATE_DENOMINATOR,n),it.FEE_RATE_DENOMINATOR,64),A=(0,it.getDeltaUpFromInput)(e,t,i,a);A.gt(y)?(c=y,v=it.MathUtil.checkUnsignedSub(r,y),g=(0,it.getNextSqrtPriceFromInput)(e,i,y,a)):(c=A,v=it.MathUtil.checkMulDivCeil(c,n,it.FEE_RATE_DENOMINATOR.sub(n),64),g=t),p=(0,it.getDeltaDownFromOutput)(e,g,i,a)}else{let y=(0,it.getDeltaDownFromOutput)(e,t,i,a);y.gt(r)?(p=r,g=(0,it.getNextSqrtPriceFromOutput)(e,i,r,a)):(p=y,g=t),c=(0,it.getDeltaUpFromInput)(e,g,i,a),v=it.MathUtil.checkMulDivCeil(c,n,it.FEE_RATE_DENOMINATOR.sub(n),64)}return{amount_in:c,amount_out:p,next_sqrt_price:g,fee_amount:v}}function jp(e,t,i,r,n){let s=i,a=r.liquidity,{current_sqrt_price:c}=r,p={amount_in:it.ZERO,amount_out:it.ZERO,fee_amount:it.ZERO,ref_amount:it.ZERO,next_sqrt_price:it.ZERO,cross_tick_num:0},g,v,y=Mr.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=Up(c,g,a,s,r.fee_rate,t);if(k.amount_in.eq(it.ZERO)||(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 Ti.default(-1)),e?it.MathUtil.is_neg(v)?a=a.add(new Ti.default((0,it.asUintN)(BigInt(v.toString()),128))):a=a.add(v):it.MathUtil.is_neg(v)?a=a.sub(new Ti.default((0,it.asUintN)(BigInt(v.toString()),128))):a=a.sub(v),c=A.sqrt_price):c=k.next_sqrt_price,p.cross_tick_num+=1,s.eq(it.ZERO))break}return p.amount_in=p.amount_in.add(p.fee_amount),p.next_sqrt_price=c,p}var bi=qi($i());function qp(e,t,i){let r=(0,Ue.extractStructTagFromType)(e).name,n=(0,Ue.extractStructTagFromType)(t).name;return`${r}-${n}[${i}]`}function Yo(e){let t=(0,Ue.getMoveObjectType)(e),i=(0,Ue.extractStructTagFromType)(t),r=(0,Ue.getObjectFields)(e);r==null&&tt("InvalidPoolObject",`Pool id ${(0,Ue.getObjectId)(e)} not exists.`,{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let n=[];r.rewarder_manager.fields.rewarders.forEach(p=>{let{emissions_per_second:g}=p.fields,v=Ue.MathUtil.fromX64(new bi.default(g)),y=Math.floor(v.toNumber()*60*60*24);n.push({emissions_per_second:g,coin_type:(0,Ue.extractStructTagFromType)(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:(0,Ue.getObjectId)(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:(0,Ue.asIntN)(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=qp(c.coin_type_a,c.coin_type_b,c.tick_spacing),c}function Qo(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&tt("InvalidPositionObject",`Position not exists. Get Position error:${e.error}`,{[Ue.DETAILS_KEYS.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=(0,Ue.getObjectFields)(e);if(r){let a=(0,Ue.getMoveObjectType)(e),c=(0,Ue.getObjectOwner)(e);"nft"in r?(r=r.nft.fields,t.description=r.description,t.name=r.name,t.link=r.url):t=(0,Ue.buildNFT)(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:(0,Ue.asIntN)(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:(0,Ue.asIntN)(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=(0,Ue.getObjectDeletedResponse)(e);n&&(i.pos_object_id=n.objectId,i.position_status="Deleted");let s=(0,Ue.getObjectNotExistsResponse)(e);return s&&(i.pos_object_id=s,i.position_status="NotExists"),i}function as(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:(0,Ue.asIntN)(BigInt(i)),tick_upper_index:(0,Ue.asIntN)(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 es(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&tt("InvalidTickObject",`Tick not exists. Get tick data error:${e.error}`,{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let t=(0,Ue.getObjectFields)(e).value.fields.value.fields;return{object_id:(0,Ue.getObjectId)(e),index:(0,Ue.asIntN)(BigInt(t.index.fields.bits)),sqrt_price:new bi.default(t.sqrt_price),liquidity_net:new bi.default(t.liquidity_net.fields.bits),liquidity_gross:new bi.default(t.liquidity_gross),fee_growth_outside_a:new bi.default(t.fee_growth_outside_a),fee_growth_outside_b:new bi.default(t.fee_growth_outside_b),rewarders_growth_outside:t.rewards_growth_outside}}function $p(e){(!e||!e.index||!e.sqrt_price||!e.liquidity_net||!e.liquidity_gross||!e.fee_growth_outside_a||!e.fee_growth_outside_b)&&tt("InvalidTickFields","Invalid tick fields.",{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let t=(0,Ue.asIntN)(BigInt(e.index.bits)),i=new bi.default(e.sqrt_price),r=new bi.default(e.liquidity_net.bits),n=new bi.default(e.liquidity_gross),s=new bi.default(e.fee_growth_outside_a),a=new bi.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 Hp(e,t,i){let r=[],{timestampMs:n,events:s}=e,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((c,p)=>{let g=(0,Ue.extractStructTagFromType)(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)&&((0,Ue.d)(v.parsed_json.amount_a).gt(0)||(0,Ue.d)(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":((0,Ue.d)(v.parsed_json.amount_a).gt(0)||(0,Ue.d)(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))&&(0,Ue.d)(v.parsed_json.amount).gt(0)&&r.push(v);break;default:break}}}),r}function Gp(e,t,i,r){let n=[],{timestampMs:s,events:a}=e;return a?.forEach((c,p)=>{let{name:g,address:v}=(0,Ue.extractStructTagFromType)(c.type);if(Bf.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 ls(e,t,i,r){t.moveCall({target:`${e.sdkOptions.integrate.published_at}::${$f}::transfer_coin_to_sender`,typeArguments:[r],arguments:[i]})}function Vp(e,t,i,r,n){n!=null?t.transferObjects([i],t.pure.address(n)):ls(e,t,i,r)}var Zp=1e4,Er=class{static parseClmmVestInfo(e){let t=(0,Dt.getObjectFields)(e),i=(0,Dt.getObjectType)(e),r=(0,Dt.extractStructTagFromType)(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:(0,Dt.d)(s.fields.percentage).div(Zp).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:(0,Dt.fixCoinType)(e.coin_a.name,!1),coin_type_b:(0,Dt.fixCoinType)(e.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(e){let t=(0,Dt.getObjectFields)(e);return{current_sqrt_price:t.current_sqrt_price,remove_percent:(0,Dt.d)(t.remove_percent).div(1e6).toString(),snapshots:{id:t.snapshots.fields.id.id,size:t.snapshots.fields.size}}}static parsePositionSnapshot(e){let t=(0,Dt.getObjectFields)(e),i=t.value.fields.value.fields;return{position_id:t.name,liquidity:i.liquidity,tick_lower_index:(0,Dt.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,Dt.asIntN)(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}}},Kp=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&&tt("InvalidConfig",`when getPositionList get position objects error: ${a.error}, please check the rpc, contracts address config and position id.`,{[de.DETAILS_KEYS.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:(0,de.extractStructTagFromType)(v.coin_type_a).full_address,coin_type_b:(0,de.extractStructTagFromType)(v.coin_type_b).full_address})})}catch(c){return ji("FetchError",c,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return n.data=r,s&&this._sdk.updateCache(`${i}_getPoolImmutables`,r,de.CACHE_TIME_24H),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")&&tt("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let a=Yo(s);i.data.push(a);let c=`${a.id}_getPoolObject`;this._sdk.updateCache(c,a,de.CACHE_TIME_24H)}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:Ff}}),r=Er.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=Er.parsePositionSnapshot(c);a.push(p)}),r.position_snapshots=a}}return r}catch(i){return ji("InvalidPoolObject",i,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[de.DETAILS_KEYS.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=Er.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")&&tt("InvalidPoolObject",`getPools error code: ${r.error?.code??"unknown error"}, please check config and object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let n=Yo(r);t.push(n);let s=`${n.id}_getPoolObject`;this._sdk.updateCache(s,n,de.CACHE_TIME_24H)}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")&&tt("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPool"});let a=Yo(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||tt("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[de.DETAILS_KEYS.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){ji("FetchError",c,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[de.DETAILS_KEYS.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((0,de.isSortedSymbols)((0,ar.normalizeSuiAddress)(e.coin_type_a),(0,ar.normalizeSuiAddress)(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((0,de.isSortedSymbols)((0,ar.normalizeSuiAddress)(e.coin_type_a),(0,ar.normalizeSuiAddress)(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=(0,de.getObjectPreviousTransactionDigest)(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((0,de.extractStructTagFromType)(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,de.CACHE_TIME_24H)),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=(0,de.createFullClient)(new Ll.SuiClient({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=Gp(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=de.TickMath.priceToSqrtPriceX64(s==="coin_a"?(0,de.d)(t):(0,de.d)(1).div(t),a,c),g=0,v=0;if(n.is_full_range)g=de.TickUtil.getMinIndex(r),v=de.TickUtil.getMaxIndex(r);else{let{min_price:K,max_price:X}=n;g=de.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,de.d)(K):(0,de.d)(1).div(X),a,c,r),v=de.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,de.d)(X):(0,de.d)(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}=de.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(g,v,new Lf.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 yr.Transaction,t.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:r}=this.sdk.sdkOptions,n=(0,de.getPackagerConfigs)(r),s=n.global_config_id,a=n.pools_id,c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),p=de.CoinAssist.buildCoinForAmount(t,c,BigInt(e.amount_a),e.coin_type_a,!1,!0),g=de.CoinAssist.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((0,de.asUintN)(BigInt(e.tick_lower)).toString())),t.pure.u32(Number((0,de.asUintN)(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(de.CLOCK_ADDRESS)];return t.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:v}),ls(this._sdk,t,p.target_coin,e.coin_type_a),ls(this._sdk,t,g.target_coin,e.coin_type_b),t}async createPoolAndAddLiquidityRow(e,t){t=t||new yr.Transaction;let{clmm_pool:i}=this.sdk.sdkOptions,r=(0,de.getPackagerConfigs)(i),n=r.global_config_id,s=r.pools_id,a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=de.CoinAssist.buildCoinForAmount(t,a,BigInt(e.amount_a),e.coin_type_a,!1,!0),p=de.CoinAssist.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((0,de.asUintN)(BigInt(e.tick_lower)).toString())),t.pure.u32(Number((0,de.asUintN)(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(de.CLOCK_ADDRESS)],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 tt("FetchError",`fetch coin ${i} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});if(j===null)return tt("FetchError",`fetch coin ${r} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.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 tt("FetchError",`fetch coin ${t} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});if(W===null)return tt("FetchError",`fetch coin ${i} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.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((0,de.asUintN)(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 yr.Transaction,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}::${Ir}::fetch_ticks`,arguments:a,typeArguments:r});let c=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,ar.normalizeSuiAddress)("0x0")});return c.error!=null&&tt("InvalidTickObjectId",`getTicks error code: ${c.error??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTicks",[de.DETAILS_KEYS.REQUEST_PARAMS]:e}),c.events?.forEach(p=>{(0,de.extractStructTagFromType)(p.type).name==="FetchTicksResultEvent"&&p.parsedJson.ticks.forEach(g=>{i.push($p(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 yr.Transaction,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}::${Ir}::fetch_positions`,arguments:p,typeArguments:s});let g=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:(0,ar.normalizeSuiAddress)("0x0")});g.error!=null&&tt("InvalidPositionRewardObject",`fetch position info error code: ${g.error??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});let v=[];if(g?.events?.forEach(y=>{(0,de.extractStructTagFromType)(y.type).name==="FetchPositionsEvent"&&y.parsedJson.positions.forEach(A=>{let k=as(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=>{(0,de.extractStructTagFromType)(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")&&tt("InvalidTickObjectId",`getTicksByRpc error code: ${r.error?.code??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let n=es(r);n!=null&&t.push(n)}return t}async getTickDataByIndex(e,t){let i={type:"u64",value:(0,de.asUintN)(BigInt((0,de.tickScore)(t).toString())).toString()},r=await this.sdk.FullClient.getDynamicFieldObject({parentId:e,name:i});return(r.error!=null||r.data?.content?.dataType!=="moveObject")&&tt("InvalidTickIndex",`get tick by index: ${t} error: ${r.error}`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),es(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")&&tt("InvalidTickObjectId",`getTicksByRpc error code: ${t.error?.code??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),es(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"&&tt("NotFoundPartnerObject",`get partner by object id: ${e} error: ${i[0].error}`,{[de.DETAILS_KEYS.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")&&tt("InvalidPartnerRefFeeFields",`get coin by object id: ${c.data.objectId} error: ${c.error}`,{[de.DETAILS_KEYS.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 yr.Transaction,{clmm_pool:n}=this.sdk.sdkOptions,{global_config_id:s}=(0,de.getPackagerConfigs)(n),a=[i],c=[r.object(s),r.object(e),r.object(t)];return r.moveCall({target:`${n.published_at}::${jf}::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=(0,de.getObjectFields)(t).position.fields.status;if(i)return i}catch(t){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",t)}}},Ln=qi($i()),Wp=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=(0,pe.createFullClient)(new zl.SuiClient({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=Hp(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){ji("FetchError",g,{[pe.DETAILS_KEYS.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((0,pe.extractStructTagFromType)(a.data.type).full_address===this.buildPositionType()){let c=Qo(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=Qo(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=Qo(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=(0,pe.getObjectFields)(i.data).value.fields.value;return as(r)}catch(i){return ji("FetchError",i,{[pe.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[pe.DETAILS_KEYS.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=(0,pe.deriveDynamicFieldIdByType)(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=(0,pe.getObjectFields)(r.data).value.fields.value,s=as(n);t.push(s)}catch(n){console.log("getPositionInfoList error",n)}}),t)}catch(t){return ji("FetchError",t,{[pe.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[pe.DETAILS_KEYS.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((0,pe.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id)];t.moveCall({target:`${r.published_at}::${Ir}::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 ki.Transaction;for(let c of e)this.buildFetchPosFee(c,r);let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,Jn.normalizeSuiAddress)("0x0")});n.error!=null&&tt("InvalidPoolObject",`fetch position fee error code: ${n.error??"unknown error"}, please check config and position and pool object ids`,{[pe.DETAILS_KEYS.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}=Kn(e);if(e=e,e.fix_amount_a&&a||!e.fix_amount_a&&c)return i=await lr.buildAddLiquidityFixTokenForGas(this._sdk,s,e,t,i,r,n),i}return lr.buildAddLiquidityFixToken(this._sdk,s,e,i,r,n)}async createAddLiquidityPayload(e,t,i,r){let{integrate:n,clmm_pool:s}=this._sdk.sdkOptions,a=(0,pe.asUintN)(BigInt(e.tick_lower)).toString(),c=(0,pe.asUintN)(BigInt(e.tick_upper)).toString(),p=[e.coin_type_a,e.coin_type_b];t=t||new ki.Transaction;let g=!(0,Jn.isValidSuiObjectId)(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=pe.CoinAssist.buildCoinForAmount(t,U,v,e.coin_type_a,!1,!0),k=pe.CoinAssist.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}::${Cr}::open_position_with_liquidity`,typeArguments:p,arguments:[t.object((0,pe.getPackagerConfigs)(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(pe.CLOCK_ADDRESS)]});else{let U=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,U,A.remain_coins,k.remain_coins),t.moveCall({target:`${n.published_at}::${Cr}::add_liquidity`,typeArguments:p,arguments:[t.object((0,pe.getPackagerConfigs)(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(pe.CLOCK_ADDRESS)]})}return t}async removeLiquidityPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n="remove_liquidity";t=t||new ki.Transaction;let s=[e.coin_type_a,e.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,a);let c=[t.object((0,pe.getPackagerConfigs)(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(pe.CLOCK_ADDRESS)];return t.moveCall({target:`${r.published_at}::${Rn}::${n}`,typeArguments:s,arguments:c}),t}async closePositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new ki.Transaction;let n=[e.coin_type_a,e.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,s),t.moveCall({target:`${r.published_at}::${Rn}::close_position`,typeArguments:n,arguments:[t.object((0,pe.getPackagerConfigs)(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(pe.CLOCK_ADDRESS)]}),t}openPositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new ki.Transaction;let n=[e.coin_type_a,e.coin_type_b],s=(0,pe.asUintN)(BigInt(e.tick_lower)).toString(),a=(0,pe.asUintN)(BigInt(e.tick_upper)).toString(),c=[t.object((0,pe.getPackagerConfigs)(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}::${Rn}::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 ki.Transaction;let s=await this.sdk.Pool.getPool(i,!1),a=Number(s.tick_spacing),c=0,p=0;if(e.is_full_range)c=pe.TickUtil.getMinIndex(a),p=pe.TickUtil.getMaxIndex(a);else{let{price_base_coin:y,min_price:A,max_price:k}=e;c=pe.TickMath.priceToInitializeTickIndex(y==="coin_a"?(0,pe.d)(A):(0,pe.d)(1).div(k),e.coin_decimals_a,e.coin_decimals_b,a),p=pe.TickMath.priceToInitializeTickIndex(y==="coin_a"?(0,pe.d)(k):(0,pe.d)(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((0,pe.getPackagerConfigs)(r).global_config_id),t.object(e.pool_id),t.pure.u32(Number((0,pe.asUintN)(BigInt(c)))),t.pure.u32(Number((0,pe.asUintN)(BigInt(p))))];return t.moveCall({target:`${n.published_at}::${Rn}::open_position`,typeArguments:g,arguments:v}),t}async collectFeePayload(e,t,i,r){t=t||new ki.Transaction;let n=i||pe.CoinAssist.buildCoinWithBalance(BigInt(0),e.coin_type_a,t),s=r||pe.CoinAssist.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((0,pe.getPackagerConfigs)(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Cr}::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=pe.TickUtil.getMinIndex(a),p=pe.TickUtil.getMaxIndex(a);else{let{price_base_coin:W,min_price:j,max_price:K}=n;c=pe.TickMath.priceToInitializeTickIndex(W==="coin_a"?(0,pe.d)(j):(0,pe.d)(1).div(K),n.coin_decimals_a,n.coin_decimals_b,a),p=pe.TickMath.priceToInitializeTickIndex(W==="coin_a"?(0,pe.d)(K):(0,pe.d)(1).div(j),n.coin_decimals_a,n.coin_decimals_b,a)}if("liquidity"in e){let{liquidity:W}=e,j=pe.TickMath.tickIndexToSqrtPriceX64(c),K=pe.TickMath.tickIndexToSqrtPriceX64(p),{coin_amount_a:X,coin_amount_b:Q}=pe.ClmmPoolUtil.getCoinAmountFromLiquidity(new Ln.default(W),new Ln.default(s.current_sqrt_price),j,K,!1),se=(0,pe.d)(X).mul(1+i).toFixed(0,Ot.ROUND_UP),Y=(0,pe.d)(Q).mul(1+i).toFixed(0,Ot.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}=pe.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(c,p,new Ln.default(g),v,!0,i,new Ln.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 ki.Transaction;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 tt("InvalidParams","fix_amount_a is undefined",{[pe.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[pe.DETAILS_KEYS.REQUEST_PARAMS]:e});t=t||new ki.Transaction;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((0,pe.getPackagerConfigs)(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Fl}::collect_fee`,typeArguments:a,arguments:c}),t}},gl=qi($i()),zp=class{constructor(e){this._sdk=e,this.growthGlobal=[lt.ZERO,lt.ZERO,lt.ZERO]}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=lt.MathUtil.fromX64(new gl.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((0,lt.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id),t.object(lt.CLOCK_ADDRESS)];t.moveCall({target:`${r.published_at}::${Ir}::fetch_position_rewards`,arguments:s,typeArguments:n})}async fetchPosRewardersAmount(e){let t=new $n.Transaction;for(let s of e)this.buildFetchPosReward(s,t);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:(0,Xl.normalizeSuiAddress)("0x")});i.error!=null&&tt("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[lt.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[lt.DETAILS_KEYS.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=[lt.ZERO,lt.ZERO,lt.ZERO];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 gl.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 $n.Transaction;return i=lr.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 $n.Transaction;let s={};return e.forEach(a=>{let c=(0,lt.normalizeCoinType)(a.coin_type_a),p=(0,lt.normalizeCoinType)(a.coin_type_b);if(a.collect_fee){let v=s[c];v==null&&(i==null?v=lt.CoinAssist.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=lt.CoinAssist.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=(0,lt.normalizeCoinType)(v),A=s[v];A===void 0&&(A=lt.CoinAssist.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&&Vp(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=(0,lt.getPackagerConfigs)(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}::${Cr}::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(lt.CLOCK_ADDRESS)]})}),t}createCollectRewarderNoSendPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=(0,lt.getPackagerConfigs)(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}::${Fl}::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(lt.CLOCK_ADDRESS)]})}),t}},br=qi($i());var Xp=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=(0,Mt.d)(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 Ot(n.fee_rate).div(10**6):new Ot(n.fee_rate).div(10**9),a=(0,Mt.d)(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 Ot(1).div(n.current_price),g=c.direction?c.current_price:new Ot(1).div(c.current_price),v=c.label==="Cetus"?new Ot(c.fee_rate).div(10**6):new Ot(c.fee_rate).div(10**9),y=(0,Mt.d)(c.output_amount).div(10**c.to_decimal).mul(v).div(p.mul(g));t=t.add(y)}}}),t.toString()}calculateSwapPriceImpact(e){let t=(0,Mt.d)(0);return e.forEach(i=>{let r=i.base_paths.length;if(r===1){let n=i.base_paths[0],s=(0,Mt.d)(n.output_amount).div(10**n.to_decimal),a=(0,Mt.d)(n.input_amount).div(10**n.from_decimal),c=s.div(a),p=n.direction?new Ot(n.current_price):new Ot(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 Ot(n.current_price):new Ot(1).div(n.current_price),c=s.direction?new Ot(s.current_price):new Ot(1).div(s.current_price),p=a.mul(c),g=new Ot(s.output_amount).div(10**s.to_decimal),v=new Ot(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 us.Transaction,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}::${Ir}::calculate_swap_result`,arguments:g,typeArguments:r})}let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,cs.normalizeSuiAddress)("0x0")});n.error!=null&&tt("InvalidConfig",`pre swap with multi pools error code: ${n.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let s=n.events?.filter(p=>(0,Mt.extractStructTagFromType)(p.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==e.pool_ids.length&&tt("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let a=e.by_amount_in?Mt.ZERO:Mt.U64_MAX,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 br.default(s[p].parsedJson.data.amount_out);g.gt(a)&&(c=p,a=g)}else{let g=new br.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 us.Transaction,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}::${Ir}::calculate_swap_result`,arguments:n,typeArguments:r});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,cs.normalizeSuiAddress)("0x0")});if(s.error!=null)return tt("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let a=s.events?.filter(c=>(0,Mt.extractStructTagFromType)(c.type).name==="CalculatedSwapResultEvent");return a.length===0?tt("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}}):this.transformSwapData(e,a[0].parsedJson.data)}transformSwapData(e,t){let i=t.amount_in&&t.fee_amount?new br.default(t.amount_in).add(new br.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 br.default(i.amount_in).add(new br.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=Bp(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=jp(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=Mr.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=Mt.TickMath.sqrtPriceX64ToPrice(i.current_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),g=Mt.TickMath.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}=Kn(e);if(e.a2b&&r||!e.a2b&&n)return await Mr.buildSwapTransactionForGas(this._sdk,e,i,t)}return Mr.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}=Kn(e);if(e.a2b&&r||!e.a2b&&n)return await Mr.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,e,i,t)}return Mr.buildSwapTransactionWithoutTransferCoins(this.sdk,e,i)}},Jp=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 tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.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=Er.parseClmmVestInfo(n),a=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(a,s),t.push(s)}),t}catch(i){ji("ClmmVestFetchError",i,{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(e=!0){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=(0,qt.getPackagerConfigs)(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=Er.parseClmmVestInfo(s);return this._sdk.updateCache(r,a),a}catch(s){return ji("ClmmVestFetchError",s,{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[qt.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(e){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(e.length===0)return[];let{clmm_vest_id:i}=(0,qt.getPackagerConfigs)(t),r=new ds.Transaction;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:(0,Jl.normalizeSuiAddress)("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=>Er.parsePositionVesting(p)))}}),s}buildRedeemPayload(e,t){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:r,clmm_vest_id:n,cetus_coin_type:s}=(0,qt.getPackagerConfigs)(i);return t=t||new ds.Transaction,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(qt.CLOCK_ADDRESS)],typeArguments:[g,v]}),k=qt.CoinAssist.fromBalance(A,s,t);t.transferObjects([k],this._sdk.getSenderAddress())}),t}},_l={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"}},Yp={env:"mainnet",full_rpc_url:Yl.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:_l.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:_l.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"}}},Qp={env:"testnet",full_rpc_url:Ql.FullRpcUrlTestnet,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"}}},eu=class Hn extends wl.SdkWrapper{constructor(t){super(t),this._swap=new Xp(this),this._pool=new Kp(this),this._position=new Wp(this),this._config=new Rf(this),this._rewarder=new zp(this),this._vest=new Jp(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"?Hn.createCustomSDK({...Yp,...t}):Hn.createCustomSDK({...Qp,...t})}static createCustomSDK(t){return new Hn(t)}},Yn=qi($i()),h1=new Yn.default(365),f1=new Yn.default(24),p1=new Yn.default(3600),m1=new Yn.default(.5);var ou=require("@pythnetwork/pyth-sui-js"),Hr=class e extends iu.SdkWrapper{constructor(t,i){super(t),this._suilendModule=new Yr(this),this._leverageModules=new ln(this),this._aggregatorClient=new $r.AggregatorClient({signer:(0,ru.normalizeSuiAddress)("0x0"),client:t.sui_client||new nu.SuiClient({url:t.full_rpc_url}),env:t.env==="testnet"?$r.Env.Testnet:$r.Env.Mainnet,pythUrls:t.pyth_urls}),this._clmmSDK=i||eu.createSDK({env:t.env,full_rpc_url:t.full_rpc_url}),this._pythConnection=new ou.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(t){return e.createCustomSDK({...Qn,...t})}static createCustomSDK(t){return new e(t)}};var em=Hr;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
22
10
  /*! Bundled license information:
23
11
 
24
12
  decimal.js/decimal.mjs:
@@ -32,14 +20,6 @@ decimal.js/decimal.mjs:
32
20
  */
33
21
  /*! Bundled license information:
34
22
 
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
-
43
23
  @cetusprotocol/aggregator-sdk/dist/index.js:
44
24
  (*! Bundled license information:
45
25