15 lines
195 KiB
JavaScript
15 lines
195 KiB
JavaScript
import{a as xt}from"./chunk-AMW3INUA.js";import{B as _n,w as Sn,x as In}from"./chunk-GQ3SEXRL.js";import{t as xi,u as dr}from"./chunk-S5RMPAYX.js";import{a as Li}from"./chunk-UYD4IAWV.js";import{a as Ri}from"./chunk-QWOR3C5W.js";import{a as D,c as ws,d as ks,e as Bi}from"./chunk-WMCBVXPA.js";import{c as fr,f as Rt,h as Ye,o as rt,q as nt}from"./chunk-QTLWQ5AJ.js";var Ss=fr((vs,An)=>{rt();nt();(function(a,e){"use strict";function t(b,s){if(!b)throw new Error(s||"Assertion failed")}function r(b,s){b.super_=s;var c=function(){};c.prototype=s.prototype,b.prototype=new c,b.prototype.constructor=b}function n(b,s,c){if(n.isBN(b))return b;this.negative=0,this.words=null,this.length=0,this.red=null,b!==null&&((s==="le"||s==="be")&&(c=s,s=10),this._init(b||0,s||10,c||"be"))}typeof a=="object"?a.exports=n:e.BN=n,n.BN=n,n.wordSize=26;var i;try{typeof window<"u"&&typeof window.Buffer<"u"?i=window.Buffer:i=ks().Buffer}catch{}n.isBN=function(s){return s instanceof n?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===n.wordSize&&Array.isArray(s.words)},n.max=function(s,c){return s.cmp(c)>0?s:c},n.min=function(s,c){return s.cmp(c)<0?s:c},n.prototype._init=function(s,c,h){if(typeof s=="number")return this._initNumber(s,c,h);if(typeof s=="object")return this._initArray(s,c,h);c==="hex"&&(c=16),t(c===(c|0)&&c>=2&&c<=36),s=s.toString().replace(/\s+/g,"");var f=0;s[0]==="-"&&(f++,this.negative=1),f<s.length&&(c===16?this._parseHex(s,f,h):(this._parseBase(s,c,f),h==="le"&&this._initArray(this.toArray(),c,h)))},n.prototype._initNumber=function(s,c,h){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(t(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),c,h)},n.prototype._initArray=function(s,c,h){if(t(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var p,w,k=0;if(h==="be")for(f=s.length-1,p=0;f>=0;f-=3)w=s[f]|s[f-1]<<8|s[f-2]<<16,this.words[p]|=w<<k&67108863,this.words[p+1]=w>>>26-k&67108863,k+=24,k>=26&&(k-=26,p++);else if(h==="le")for(f=0,p=0;f<s.length;f+=3)w=s[f]|s[f+1]<<8|s[f+2]<<16,this.words[p]|=w<<k&67108863,this.words[p+1]=w>>>26-k&67108863,k+=24,k>=26&&(k-=26,p++);return this._strip()};function u(b,s){var c=b.charCodeAt(s);if(c>=48&&c<=57)return c-48;if(c>=65&&c<=70)return c-55;if(c>=97&&c<=102)return c-87;t(!1,"Invalid character in "+b)}function l(b,s,c){var h=u(b,c);return c-1>=s&&(h|=u(b,c-1)<<4),h}n.prototype._parseHex=function(s,c,h){this.length=Math.ceil((s.length-c)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var p=0,w=0,k;if(h==="be")for(f=s.length-1;f>=c;f-=2)k=l(s,c,f)<<p,this.words[w]|=k&67108863,p>=18?(p-=18,w+=1,this.words[w]|=k>>>26):p+=8;else{var d=s.length-c;for(f=d%2===0?c+1:c;f<s.length;f+=2)k=l(s,c,f)<<p,this.words[w]|=k&67108863,p>=18?(p-=18,w+=1,this.words[w]|=k>>>26):p+=8}this._strip()};function m(b,s,c,h){for(var f=0,p=0,w=Math.min(b.length,c),k=s;k<w;k++){var d=b.charCodeAt(k)-48;f*=h,d>=49?p=d-49+10:d>=17?p=d-17+10:p=d,t(d>=0&&p<h,"Invalid character"),f+=p}return f}n.prototype._parseBase=function(s,c,h){this.words=[0],this.length=1;for(var f=0,p=1;p<=67108863;p*=c)f++;f--,p=p/c|0;for(var w=s.length-h,k=w%f,d=Math.min(w,w-k)+h,o=0,g=h;g<d;g+=f)o=m(s,g,g+f,c),this.imuln(p),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o);if(k!==0){var K=1;for(o=m(s,g,s.length,c),g=0;g<k;g++)K*=c;this.imuln(K),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o)}this._strip()},n.prototype.copy=function(s){s.words=new Array(this.length);for(var c=0;c<this.length;c++)s.words[c]=this.words[c];s.length=this.length,s.negative=this.negative,s.red=this.red};function I(b,s){b.words=s.words,b.length=s.length,b.negative=s.negative,b.red=s.red}if(n.prototype._move=function(s){I(s,this)},n.prototype.clone=function(){var s=new n(null);return this.copy(s),s},n.prototype._expand=function(s){for(;this.length<s;)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")]=B}catch{n.prototype.inspect=B}else n.prototype.inspect=B;function B(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],N=[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],_=[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(s,c){s=s||10,c=c|0||1;var h;if(s===16||s==="hex"){h="";for(var f=0,p=0,w=0;w<this.length;w++){var k=this.words[w],d=((k<<f|p)&16777215).toString(16);p=k>>>24-f&16777215,f+=2,f>=26&&(f-=26,w--),p!==0||w!==this.length-1?h=x[6-d.length]+d+h:h=d+h}for(p!==0&&(h=p.toString(16)+h);h.length%c!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(s===(s|0)&&s>=2&&s<=36){var o=N[s],g=_[s];h="";var K=this.clone();for(K.negative=0;!K.isZero();){var q=K.modrn(g).toString(s);K=K.idivn(g),K.isZero()?h=q+h:h=x[o-q.length]+q+h}for(this.isZero()&&(h="0"+h);h.length%c!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}t(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},n.prototype.toJSON=function(){return this.toString(16,2)},i&&(n.prototype.toBuffer=function(s,c){return this.toArrayLike(i,s,c)}),n.prototype.toArray=function(s,c){return this.toArrayLike(Array,s,c)};var R=function(s,c){return s.allocUnsafe?s.allocUnsafe(c):new s(c)};n.prototype.toArrayLike=function(s,c,h){this._strip();var f=this.byteLength(),p=h||Math.max(1,f);t(f<=p,"byte array longer than desired length"),t(p>0,"Requested array length <= 0");var w=R(s,p),k=c==="le"?"LE":"BE";return this["_toArrayLike"+k](w,f),w},n.prototype._toArrayLikeLE=function(s,c){for(var h=0,f=0,p=0,w=0;p<this.length;p++){var k=this.words[p]<<w|f;s[h++]=k&255,h<s.length&&(s[h++]=k>>8&255),h<s.length&&(s[h++]=k>>16&255),w===6?(h<s.length&&(s[h++]=k>>24&255),f=0,w=0):(f=k>>>24,w+=2)}if(h<s.length)for(s[h++]=f;h<s.length;)s[h++]=0},n.prototype._toArrayLikeBE=function(s,c){for(var h=s.length-1,f=0,p=0,w=0;p<this.length;p++){var k=this.words[p]<<w|f;s[h--]=k&255,h>=0&&(s[h--]=k>>8&255),h>=0&&(s[h--]=k>>16&255),w===6?(h>=0&&(s[h--]=k>>24&255),f=0,w=0):(f=k>>>24,w+=2)}if(h>=0)for(s[h--]=f;h>=0;)s[h--]=0},Math.clz32?n.prototype._countBits=function(s){return 32-Math.clz32(s)}:n.prototype._countBits=function(s){var c=s,h=0;return c>=4096&&(h+=13,c>>>=13),c>=64&&(h+=7,c>>>=7),c>=8&&(h+=4,c>>>=4),c>=2&&(h+=2,c>>>=2),h+c},n.prototype._zeroBits=function(s){if(s===0)return 26;var c=s,h=0;return(c&8191)===0&&(h+=13,c>>>=13),(c&127)===0&&(h+=7,c>>>=7),(c&15)===0&&(h+=4,c>>>=4),(c&3)===0&&(h+=2,c>>>=2),(c&1)===0&&h++,h},n.prototype.bitLength=function(){var s=this.words[this.length-1],c=this._countBits(s);return(this.length-1)*26+c};function L(b){for(var s=new Array(b.bitLength()),c=0;c<s.length;c++){var h=c/26|0,f=c%26;s[c]=b.words[h]>>>f&1}return s}n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,c=0;c<this.length;c++){var h=this._zeroBits(this.words[c]);if(s+=h,h!==26)break}return s},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},n.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).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(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var c=0;c<s.length;c++)this.words[c]=this.words[c]|s.words[c];return this._strip()},n.prototype.ior=function(s){return t((this.negative|s.negative)===0),this.iuor(s)},n.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},n.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},n.prototype.iuand=function(s){var c;this.length>s.length?c=s:c=this;for(var h=0;h<c.length;h++)this.words[h]=this.words[h]&s.words[h];return this.length=c.length,this._strip()},n.prototype.iand=function(s){return t((this.negative|s.negative)===0),this.iuand(s)},n.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},n.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},n.prototype.iuxor=function(s){var c,h;this.length>s.length?(c=this,h=s):(c=s,h=this);for(var f=0;f<h.length;f++)this.words[f]=c.words[f]^h.words[f];if(this!==c)for(;f<c.length;f++)this.words[f]=c.words[f];return this.length=c.length,this._strip()},n.prototype.ixor=function(s){return t((this.negative|s.negative)===0),this.iuxor(s)},n.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},n.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},n.prototype.inotn=function(s){t(typeof s=="number"&&s>=0);var c=Math.ceil(s/26)|0,h=s%26;this._expand(c),h>0&&c--;for(var f=0;f<c;f++)this.words[f]=~this.words[f]&67108863;return h>0&&(this.words[f]=~this.words[f]&67108863>>26-h),this._strip()},n.prototype.notn=function(s){return this.clone().inotn(s)},n.prototype.setn=function(s,c){t(typeof s=="number"&&s>=0);var h=s/26|0,f=s%26;return this._expand(h+1),c?this.words[h]=this.words[h]|1<<f:this.words[h]=this.words[h]&~(1<<f),this._strip()},n.prototype.iadd=function(s){var c;if(this.negative!==0&&s.negative===0)return this.negative=0,c=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,c=this.isub(s),s.negative=1,c._normSign();var h,f;this.length>s.length?(h=this,f=s):(h=s,f=this);for(var p=0,w=0;w<f.length;w++)c=(h.words[w]|0)+(f.words[w]|0)+p,this.words[w]=c&67108863,p=c>>>26;for(;p!==0&&w<h.length;w++)c=(h.words[w]|0)+p,this.words[w]=c&67108863,p=c>>>26;if(this.length=h.length,p!==0)this.words[this.length]=p,this.length++;else if(h!==this)for(;w<h.length;w++)this.words[w]=h.words[w];return this},n.prototype.add=function(s){var c;return s.negative!==0&&this.negative===0?(s.negative=0,c=this.sub(s),s.negative^=1,c):s.negative===0&&this.negative!==0?(this.negative=0,c=s.sub(this),this.negative=1,c):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},n.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var c=this.iadd(s);return s.negative=1,c._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var h=this.cmp(s);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var f,p;h>0?(f=this,p=s):(f=s,p=this);for(var w=0,k=0;k<p.length;k++)c=(f.words[k]|0)-(p.words[k]|0)+w,w=c>>26,this.words[k]=c&67108863;for(;w!==0&&k<f.length;k++)c=(f.words[k]|0)+w,w=c>>26,this.words[k]=c&67108863;if(w===0&&k<f.length&&f!==this)for(;k<f.length;k++)this.words[k]=f.words[k];return this.length=Math.max(this.length,k),f!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(s){return this.clone().isub(s)};function z(b,s,c){c.negative=s.negative^b.negative;var h=b.length+s.length|0;c.length=h,h=h-1|0;var f=b.words[0]|0,p=s.words[0]|0,w=f*p,k=w&67108863,d=w/67108864|0;c.words[0]=k;for(var o=1;o<h;o++){for(var g=d>>>26,K=d&67108863,q=Math.min(o,s.length-1),U=Math.max(0,o-b.length+1);U<=q;U++){var F=o-U|0;f=b.words[F]|0,p=s.words[U]|0,w=f*p+K,g+=w/67108864|0,K=w&67108863}c.words[o]=K|0,d=g|0}return d!==0?c.words[o]=d|0:c.length--,c._strip()}var W=function(s,c,h){var f=s.words,p=c.words,w=h.words,k=0,d,o,g,K=f[0]|0,q=K&8191,U=K>>>13,F=f[1]|0,te=F&8191,se=F>>>13,kt=f[2]|0,ie=kt&8191,ue=kt>>>13,rs=f[3]|0,ye=rs&8191,ge=rs>>>13,ns=f[4]|0,me=ns&8191,be=ns>>>13,ss=f[5]|0,we=ss&8191,ke=ss>>>13,is=f[6]|0,ve=is&8191,Se=is>>>13,os=f[7]|0,Ie=os&8191,_e=os>>>13,as=f[8]|0,Ae=as&8191,Be=as>>>13,cs=f[9]|0,Le=cs&8191,Re=cs>>>13,us=p[0]|0,xe=us&8191,Ee=us>>>13,hs=p[1]|0,Me=hs&8191,Pe=hs>>>13,ls=p[2]|0,Te=ls&8191,Ce=ls>>>13,fs=p[3]|0,ze=fs&8191,Ne=fs>>>13,ds=p[4]|0,Oe=ds&8191,Ke=ds>>>13,ps=p[5]|0,We=ps&8191,qe=ps>>>13,ys=p[6]|0,Ue=ys&8191,De=ys>>>13,gs=p[7]|0,$e=gs&8191,Fe=gs>>>13,ms=p[8]|0,Ve=ms&8191,He=ms>>>13,bs=p[9]|0,Ge=bs&8191,je=bs>>>13;h.negative=s.negative^c.negative,h.length=19,d=Math.imul(q,xe),o=Math.imul(q,Ee),o=o+Math.imul(U,xe)|0,g=Math.imul(U,Ee);var rn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(rn>>>26)|0,rn&=67108863,d=Math.imul(te,xe),o=Math.imul(te,Ee),o=o+Math.imul(se,xe)|0,g=Math.imul(se,Ee),d=d+Math.imul(q,Me)|0,o=o+Math.imul(q,Pe)|0,o=o+Math.imul(U,Me)|0,g=g+Math.imul(U,Pe)|0;var nn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(nn>>>26)|0,nn&=67108863,d=Math.imul(ie,xe),o=Math.imul(ie,Ee),o=o+Math.imul(ue,xe)|0,g=Math.imul(ue,Ee),d=d+Math.imul(te,Me)|0,o=o+Math.imul(te,Pe)|0,o=o+Math.imul(se,Me)|0,g=g+Math.imul(se,Pe)|0,d=d+Math.imul(q,Te)|0,o=o+Math.imul(q,Ce)|0,o=o+Math.imul(U,Te)|0,g=g+Math.imul(U,Ce)|0;var sn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(sn>>>26)|0,sn&=67108863,d=Math.imul(ye,xe),o=Math.imul(ye,Ee),o=o+Math.imul(ge,xe)|0,g=Math.imul(ge,Ee),d=d+Math.imul(ie,Me)|0,o=o+Math.imul(ie,Pe)|0,o=o+Math.imul(ue,Me)|0,g=g+Math.imul(ue,Pe)|0,d=d+Math.imul(te,Te)|0,o=o+Math.imul(te,Ce)|0,o=o+Math.imul(se,Te)|0,g=g+Math.imul(se,Ce)|0,d=d+Math.imul(q,ze)|0,o=o+Math.imul(q,Ne)|0,o=o+Math.imul(U,ze)|0,g=g+Math.imul(U,Ne)|0;var on=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(on>>>26)|0,on&=67108863,d=Math.imul(me,xe),o=Math.imul(me,Ee),o=o+Math.imul(be,xe)|0,g=Math.imul(be,Ee),d=d+Math.imul(ye,Me)|0,o=o+Math.imul(ye,Pe)|0,o=o+Math.imul(ge,Me)|0,g=g+Math.imul(ge,Pe)|0,d=d+Math.imul(ie,Te)|0,o=o+Math.imul(ie,Ce)|0,o=o+Math.imul(ue,Te)|0,g=g+Math.imul(ue,Ce)|0,d=d+Math.imul(te,ze)|0,o=o+Math.imul(te,Ne)|0,o=o+Math.imul(se,ze)|0,g=g+Math.imul(se,Ne)|0,d=d+Math.imul(q,Oe)|0,o=o+Math.imul(q,Ke)|0,o=o+Math.imul(U,Oe)|0,g=g+Math.imul(U,Ke)|0;var an=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(an>>>26)|0,an&=67108863,d=Math.imul(we,xe),o=Math.imul(we,Ee),o=o+Math.imul(ke,xe)|0,g=Math.imul(ke,Ee),d=d+Math.imul(me,Me)|0,o=o+Math.imul(me,Pe)|0,o=o+Math.imul(be,Me)|0,g=g+Math.imul(be,Pe)|0,d=d+Math.imul(ye,Te)|0,o=o+Math.imul(ye,Ce)|0,o=o+Math.imul(ge,Te)|0,g=g+Math.imul(ge,Ce)|0,d=d+Math.imul(ie,ze)|0,o=o+Math.imul(ie,Ne)|0,o=o+Math.imul(ue,ze)|0,g=g+Math.imul(ue,Ne)|0,d=d+Math.imul(te,Oe)|0,o=o+Math.imul(te,Ke)|0,o=o+Math.imul(se,Oe)|0,g=g+Math.imul(se,Ke)|0,d=d+Math.imul(q,We)|0,o=o+Math.imul(q,qe)|0,o=o+Math.imul(U,We)|0,g=g+Math.imul(U,qe)|0;var cn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(cn>>>26)|0,cn&=67108863,d=Math.imul(ve,xe),o=Math.imul(ve,Ee),o=o+Math.imul(Se,xe)|0,g=Math.imul(Se,Ee),d=d+Math.imul(we,Me)|0,o=o+Math.imul(we,Pe)|0,o=o+Math.imul(ke,Me)|0,g=g+Math.imul(ke,Pe)|0,d=d+Math.imul(me,Te)|0,o=o+Math.imul(me,Ce)|0,o=o+Math.imul(be,Te)|0,g=g+Math.imul(be,Ce)|0,d=d+Math.imul(ye,ze)|0,o=o+Math.imul(ye,Ne)|0,o=o+Math.imul(ge,ze)|0,g=g+Math.imul(ge,Ne)|0,d=d+Math.imul(ie,Oe)|0,o=o+Math.imul(ie,Ke)|0,o=o+Math.imul(ue,Oe)|0,g=g+Math.imul(ue,Ke)|0,d=d+Math.imul(te,We)|0,o=o+Math.imul(te,qe)|0,o=o+Math.imul(se,We)|0,g=g+Math.imul(se,qe)|0,d=d+Math.imul(q,Ue)|0,o=o+Math.imul(q,De)|0,o=o+Math.imul(U,Ue)|0,g=g+Math.imul(U,De)|0;var un=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(un>>>26)|0,un&=67108863,d=Math.imul(Ie,xe),o=Math.imul(Ie,Ee),o=o+Math.imul(_e,xe)|0,g=Math.imul(_e,Ee),d=d+Math.imul(ve,Me)|0,o=o+Math.imul(ve,Pe)|0,o=o+Math.imul(Se,Me)|0,g=g+Math.imul(Se,Pe)|0,d=d+Math.imul(we,Te)|0,o=o+Math.imul(we,Ce)|0,o=o+Math.imul(ke,Te)|0,g=g+Math.imul(ke,Ce)|0,d=d+Math.imul(me,ze)|0,o=o+Math.imul(me,Ne)|0,o=o+Math.imul(be,ze)|0,g=g+Math.imul(be,Ne)|0,d=d+Math.imul(ye,Oe)|0,o=o+Math.imul(ye,Ke)|0,o=o+Math.imul(ge,Oe)|0,g=g+Math.imul(ge,Ke)|0,d=d+Math.imul(ie,We)|0,o=o+Math.imul(ie,qe)|0,o=o+Math.imul(ue,We)|0,g=g+Math.imul(ue,qe)|0,d=d+Math.imul(te,Ue)|0,o=o+Math.imul(te,De)|0,o=o+Math.imul(se,Ue)|0,g=g+Math.imul(se,De)|0,d=d+Math.imul(q,$e)|0,o=o+Math.imul(q,Fe)|0,o=o+Math.imul(U,$e)|0,g=g+Math.imul(U,Fe)|0;var hn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(hn>>>26)|0,hn&=67108863,d=Math.imul(Ae,xe),o=Math.imul(Ae,Ee),o=o+Math.imul(Be,xe)|0,g=Math.imul(Be,Ee),d=d+Math.imul(Ie,Me)|0,o=o+Math.imul(Ie,Pe)|0,o=o+Math.imul(_e,Me)|0,g=g+Math.imul(_e,Pe)|0,d=d+Math.imul(ve,Te)|0,o=o+Math.imul(ve,Ce)|0,o=o+Math.imul(Se,Te)|0,g=g+Math.imul(Se,Ce)|0,d=d+Math.imul(we,ze)|0,o=o+Math.imul(we,Ne)|0,o=o+Math.imul(ke,ze)|0,g=g+Math.imul(ke,Ne)|0,d=d+Math.imul(me,Oe)|0,o=o+Math.imul(me,Ke)|0,o=o+Math.imul(be,Oe)|0,g=g+Math.imul(be,Ke)|0,d=d+Math.imul(ye,We)|0,o=o+Math.imul(ye,qe)|0,o=o+Math.imul(ge,We)|0,g=g+Math.imul(ge,qe)|0,d=d+Math.imul(ie,Ue)|0,o=o+Math.imul(ie,De)|0,o=o+Math.imul(ue,Ue)|0,g=g+Math.imul(ue,De)|0,d=d+Math.imul(te,$e)|0,o=o+Math.imul(te,Fe)|0,o=o+Math.imul(se,$e)|0,g=g+Math.imul(se,Fe)|0,d=d+Math.imul(q,Ve)|0,o=o+Math.imul(q,He)|0,o=o+Math.imul(U,Ve)|0,g=g+Math.imul(U,He)|0;var ln=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(ln>>>26)|0,ln&=67108863,d=Math.imul(Le,xe),o=Math.imul(Le,Ee),o=o+Math.imul(Re,xe)|0,g=Math.imul(Re,Ee),d=d+Math.imul(Ae,Me)|0,o=o+Math.imul(Ae,Pe)|0,o=o+Math.imul(Be,Me)|0,g=g+Math.imul(Be,Pe)|0,d=d+Math.imul(Ie,Te)|0,o=o+Math.imul(Ie,Ce)|0,o=o+Math.imul(_e,Te)|0,g=g+Math.imul(_e,Ce)|0,d=d+Math.imul(ve,ze)|0,o=o+Math.imul(ve,Ne)|0,o=o+Math.imul(Se,ze)|0,g=g+Math.imul(Se,Ne)|0,d=d+Math.imul(we,Oe)|0,o=o+Math.imul(we,Ke)|0,o=o+Math.imul(ke,Oe)|0,g=g+Math.imul(ke,Ke)|0,d=d+Math.imul(me,We)|0,o=o+Math.imul(me,qe)|0,o=o+Math.imul(be,We)|0,g=g+Math.imul(be,qe)|0,d=d+Math.imul(ye,Ue)|0,o=o+Math.imul(ye,De)|0,o=o+Math.imul(ge,Ue)|0,g=g+Math.imul(ge,De)|0,d=d+Math.imul(ie,$e)|0,o=o+Math.imul(ie,Fe)|0,o=o+Math.imul(ue,$e)|0,g=g+Math.imul(ue,Fe)|0,d=d+Math.imul(te,Ve)|0,o=o+Math.imul(te,He)|0,o=o+Math.imul(se,Ve)|0,g=g+Math.imul(se,He)|0,d=d+Math.imul(q,Ge)|0,o=o+Math.imul(q,je)|0,o=o+Math.imul(U,Ge)|0,g=g+Math.imul(U,je)|0;var fn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(fn>>>26)|0,fn&=67108863,d=Math.imul(Le,Me),o=Math.imul(Le,Pe),o=o+Math.imul(Re,Me)|0,g=Math.imul(Re,Pe),d=d+Math.imul(Ae,Te)|0,o=o+Math.imul(Ae,Ce)|0,o=o+Math.imul(Be,Te)|0,g=g+Math.imul(Be,Ce)|0,d=d+Math.imul(Ie,ze)|0,o=o+Math.imul(Ie,Ne)|0,o=o+Math.imul(_e,ze)|0,g=g+Math.imul(_e,Ne)|0,d=d+Math.imul(ve,Oe)|0,o=o+Math.imul(ve,Ke)|0,o=o+Math.imul(Se,Oe)|0,g=g+Math.imul(Se,Ke)|0,d=d+Math.imul(we,We)|0,o=o+Math.imul(we,qe)|0,o=o+Math.imul(ke,We)|0,g=g+Math.imul(ke,qe)|0,d=d+Math.imul(me,Ue)|0,o=o+Math.imul(me,De)|0,o=o+Math.imul(be,Ue)|0,g=g+Math.imul(be,De)|0,d=d+Math.imul(ye,$e)|0,o=o+Math.imul(ye,Fe)|0,o=o+Math.imul(ge,$e)|0,g=g+Math.imul(ge,Fe)|0,d=d+Math.imul(ie,Ve)|0,o=o+Math.imul(ie,He)|0,o=o+Math.imul(ue,Ve)|0,g=g+Math.imul(ue,He)|0,d=d+Math.imul(te,Ge)|0,o=o+Math.imul(te,je)|0,o=o+Math.imul(se,Ge)|0,g=g+Math.imul(se,je)|0;var dn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(dn>>>26)|0,dn&=67108863,d=Math.imul(Le,Te),o=Math.imul(Le,Ce),o=o+Math.imul(Re,Te)|0,g=Math.imul(Re,Ce),d=d+Math.imul(Ae,ze)|0,o=o+Math.imul(Ae,Ne)|0,o=o+Math.imul(Be,ze)|0,g=g+Math.imul(Be,Ne)|0,d=d+Math.imul(Ie,Oe)|0,o=o+Math.imul(Ie,Ke)|0,o=o+Math.imul(_e,Oe)|0,g=g+Math.imul(_e,Ke)|0,d=d+Math.imul(ve,We)|0,o=o+Math.imul(ve,qe)|0,o=o+Math.imul(Se,We)|0,g=g+Math.imul(Se,qe)|0,d=d+Math.imul(we,Ue)|0,o=o+Math.imul(we,De)|0,o=o+Math.imul(ke,Ue)|0,g=g+Math.imul(ke,De)|0,d=d+Math.imul(me,$e)|0,o=o+Math.imul(me,Fe)|0,o=o+Math.imul(be,$e)|0,g=g+Math.imul(be,Fe)|0,d=d+Math.imul(ye,Ve)|0,o=o+Math.imul(ye,He)|0,o=o+Math.imul(ge,Ve)|0,g=g+Math.imul(ge,He)|0,d=d+Math.imul(ie,Ge)|0,o=o+Math.imul(ie,je)|0,o=o+Math.imul(ue,Ge)|0,g=g+Math.imul(ue,je)|0;var pn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(pn>>>26)|0,pn&=67108863,d=Math.imul(Le,ze),o=Math.imul(Le,Ne),o=o+Math.imul(Re,ze)|0,g=Math.imul(Re,Ne),d=d+Math.imul(Ae,Oe)|0,o=o+Math.imul(Ae,Ke)|0,o=o+Math.imul(Be,Oe)|0,g=g+Math.imul(Be,Ke)|0,d=d+Math.imul(Ie,We)|0,o=o+Math.imul(Ie,qe)|0,o=o+Math.imul(_e,We)|0,g=g+Math.imul(_e,qe)|0,d=d+Math.imul(ve,Ue)|0,o=o+Math.imul(ve,De)|0,o=o+Math.imul(Se,Ue)|0,g=g+Math.imul(Se,De)|0,d=d+Math.imul(we,$e)|0,o=o+Math.imul(we,Fe)|0,o=o+Math.imul(ke,$e)|0,g=g+Math.imul(ke,Fe)|0,d=d+Math.imul(me,Ve)|0,o=o+Math.imul(me,He)|0,o=o+Math.imul(be,Ve)|0,g=g+Math.imul(be,He)|0,d=d+Math.imul(ye,Ge)|0,o=o+Math.imul(ye,je)|0,o=o+Math.imul(ge,Ge)|0,g=g+Math.imul(ge,je)|0;var yn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(yn>>>26)|0,yn&=67108863,d=Math.imul(Le,Oe),o=Math.imul(Le,Ke),o=o+Math.imul(Re,Oe)|0,g=Math.imul(Re,Ke),d=d+Math.imul(Ae,We)|0,o=o+Math.imul(Ae,qe)|0,o=o+Math.imul(Be,We)|0,g=g+Math.imul(Be,qe)|0,d=d+Math.imul(Ie,Ue)|0,o=o+Math.imul(Ie,De)|0,o=o+Math.imul(_e,Ue)|0,g=g+Math.imul(_e,De)|0,d=d+Math.imul(ve,$e)|0,o=o+Math.imul(ve,Fe)|0,o=o+Math.imul(Se,$e)|0,g=g+Math.imul(Se,Fe)|0,d=d+Math.imul(we,Ve)|0,o=o+Math.imul(we,He)|0,o=o+Math.imul(ke,Ve)|0,g=g+Math.imul(ke,He)|0,d=d+Math.imul(me,Ge)|0,o=o+Math.imul(me,je)|0,o=o+Math.imul(be,Ge)|0,g=g+Math.imul(be,je)|0;var gn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(gn>>>26)|0,gn&=67108863,d=Math.imul(Le,We),o=Math.imul(Le,qe),o=o+Math.imul(Re,We)|0,g=Math.imul(Re,qe),d=d+Math.imul(Ae,Ue)|0,o=o+Math.imul(Ae,De)|0,o=o+Math.imul(Be,Ue)|0,g=g+Math.imul(Be,De)|0,d=d+Math.imul(Ie,$e)|0,o=o+Math.imul(Ie,Fe)|0,o=o+Math.imul(_e,$e)|0,g=g+Math.imul(_e,Fe)|0,d=d+Math.imul(ve,Ve)|0,o=o+Math.imul(ve,He)|0,o=o+Math.imul(Se,Ve)|0,g=g+Math.imul(Se,He)|0,d=d+Math.imul(we,Ge)|0,o=o+Math.imul(we,je)|0,o=o+Math.imul(ke,Ge)|0,g=g+Math.imul(ke,je)|0;var mn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(mn>>>26)|0,mn&=67108863,d=Math.imul(Le,Ue),o=Math.imul(Le,De),o=o+Math.imul(Re,Ue)|0,g=Math.imul(Re,De),d=d+Math.imul(Ae,$e)|0,o=o+Math.imul(Ae,Fe)|0,o=o+Math.imul(Be,$e)|0,g=g+Math.imul(Be,Fe)|0,d=d+Math.imul(Ie,Ve)|0,o=o+Math.imul(Ie,He)|0,o=o+Math.imul(_e,Ve)|0,g=g+Math.imul(_e,He)|0,d=d+Math.imul(ve,Ge)|0,o=o+Math.imul(ve,je)|0,o=o+Math.imul(Se,Ge)|0,g=g+Math.imul(Se,je)|0;var bn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(bn>>>26)|0,bn&=67108863,d=Math.imul(Le,$e),o=Math.imul(Le,Fe),o=o+Math.imul(Re,$e)|0,g=Math.imul(Re,Fe),d=d+Math.imul(Ae,Ve)|0,o=o+Math.imul(Ae,He)|0,o=o+Math.imul(Be,Ve)|0,g=g+Math.imul(Be,He)|0,d=d+Math.imul(Ie,Ge)|0,o=o+Math.imul(Ie,je)|0,o=o+Math.imul(_e,Ge)|0,g=g+Math.imul(_e,je)|0;var wn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(wn>>>26)|0,wn&=67108863,d=Math.imul(Le,Ve),o=Math.imul(Le,He),o=o+Math.imul(Re,Ve)|0,g=Math.imul(Re,He),d=d+Math.imul(Ae,Ge)|0,o=o+Math.imul(Ae,je)|0,o=o+Math.imul(Be,Ge)|0,g=g+Math.imul(Be,je)|0;var kn=(k+d|0)+((o&8191)<<13)|0;k=(g+(o>>>13)|0)+(kn>>>26)|0,kn&=67108863,d=Math.imul(Le,Ge),o=Math.imul(Le,je),o=o+Math.imul(Re,Ge)|0,g=Math.imul(Re,je);var vn=(k+d|0)+((o&8191)<<13)|0;return k=(g+(o>>>13)|0)+(vn>>>26)|0,vn&=67108863,w[0]=rn,w[1]=nn,w[2]=sn,w[3]=on,w[4]=an,w[5]=cn,w[6]=un,w[7]=hn,w[8]=ln,w[9]=fn,w[10]=dn,w[11]=pn,w[12]=yn,w[13]=gn,w[14]=mn,w[15]=bn,w[16]=wn,w[17]=kn,w[18]=vn,k!==0&&(w[19]=k,h.length++),h};Math.imul||(W=z);function J(b,s,c){c.negative=s.negative^b.negative,c.length=b.length+s.length;for(var h=0,f=0,p=0;p<c.length-1;p++){var w=f;f=0;for(var k=h&67108863,d=Math.min(p,s.length-1),o=Math.max(0,p-b.length+1);o<=d;o++){var g=p-o,K=b.words[g]|0,q=s.words[o]|0,U=K*q,F=U&67108863;w=w+(U/67108864|0)|0,F=F+k|0,k=F&67108863,w=w+(F>>>26)|0,f+=w>>>26,w&=67108863}c.words[p]=k,h=w,w=f}return h!==0?c.words[p]=h:c.length--,c._strip()}function le(b,s,c){return J(b,s,c)}n.prototype.mulTo=function(s,c){var h,f=this.length+s.length;return this.length===10&&s.length===10?h=W(this,s,c):f<63?h=z(this,s,c):f<1024?h=J(this,s,c):h=le(this,s,c),h};function ee(b,s){this.x=b,this.y=s}ee.prototype.makeRBT=function(s){for(var c=new Array(s),h=n.prototype._countBits(s)-1,f=0;f<s;f++)c[f]=this.revBin(f,h,s);return c},ee.prototype.revBin=function(s,c,h){if(s===0||s===h-1)return s;for(var f=0,p=0;p<c;p++)f|=(s&1)<<c-p-1,s>>=1;return f},ee.prototype.permute=function(s,c,h,f,p,w){for(var k=0;k<w;k++)f[k]=c[s[k]],p[k]=h[s[k]]},ee.prototype.transform=function(s,c,h,f,p,w){this.permute(w,s,c,h,f,p);for(var k=1;k<p;k<<=1)for(var d=k<<1,o=Math.cos(2*Math.PI/d),g=Math.sin(2*Math.PI/d),K=0;K<p;K+=d)for(var q=o,U=g,F=0;F<k;F++){var te=h[K+F],se=f[K+F],kt=h[K+F+k],ie=f[K+F+k],ue=q*kt-U*ie;ie=q*ie+U*kt,kt=ue,h[K+F]=te+kt,f[K+F]=se+ie,h[K+F+k]=te-kt,f[K+F+k]=se-ie,F!==d&&(ue=o*q-g*U,U=o*U+g*q,q=ue)}},ee.prototype.guessLen13b=function(s,c){var h=Math.max(c,s)|1,f=h&1,p=0;for(h=h/2|0;h;h=h>>>1)p++;return 1<<p+1+f},ee.prototype.conjugate=function(s,c,h){if(!(h<=1))for(var f=0;f<h/2;f++){var p=s[f];s[f]=s[h-f-1],s[h-f-1]=p,p=c[f],c[f]=-c[h-f-1],c[h-f-1]=-p}},ee.prototype.normalize13b=function(s,c){for(var h=0,f=0;f<c/2;f++){var p=Math.round(s[2*f+1]/c)*8192+Math.round(s[2*f]/c)+h;s[f]=p&67108863,p<67108864?h=0:h=p/67108864|0}return s},ee.prototype.convert13b=function(s,c,h,f){for(var p=0,w=0;w<c;w++)p=p+(s[w]|0),h[2*w]=p&8191,p=p>>>13,h[2*w+1]=p&8191,p=p>>>13;for(w=2*c;w<f;++w)h[w]=0;t(p===0),t((p&-8192)===0)},ee.prototype.stub=function(s){for(var c=new Array(s),h=0;h<s;h++)c[h]=0;return c},ee.prototype.mulp=function(s,c,h){var f=2*this.guessLen13b(s.length,c.length),p=this.makeRBT(f),w=this.stub(f),k=new Array(f),d=new Array(f),o=new Array(f),g=new Array(f),K=new Array(f),q=new Array(f),U=h.words;U.length=f,this.convert13b(s.words,s.length,k,f),this.convert13b(c.words,c.length,g,f),this.transform(k,w,d,o,f,p),this.transform(g,w,K,q,f,p);for(var F=0;F<f;F++){var te=d[F]*K[F]-o[F]*q[F];o[F]=d[F]*q[F]+o[F]*K[F],d[F]=te}return this.conjugate(d,o,f),this.transform(d,o,U,w,f,p),this.conjugate(U,w,f),this.normalize13b(U,f),h.negative=s.negative^c.negative,h.length=s.length+c.length,h._strip()},n.prototype.mul=function(s){var c=new n(null);return c.words=new Array(this.length+s.length),this.mulTo(s,c)},n.prototype.mulf=function(s){var c=new n(null);return c.words=new Array(this.length+s.length),le(this,s,c)},n.prototype.imul=function(s){return this.clone().mulTo(s,this)},n.prototype.imuln=function(s){var c=s<0;c&&(s=-s),t(typeof s=="number"),t(s<67108864);for(var h=0,f=0;f<this.length;f++){var p=(this.words[f]|0)*s,w=(p&67108863)+(h&67108863);h>>=26,h+=p/67108864|0,h+=w>>>26,this.words[f]=w&67108863}return h!==0&&(this.words[f]=h,this.length++),c?this.ineg():this},n.prototype.muln=function(s){return this.clone().imuln(s)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(s){var c=L(s);if(c.length===0)return new n(1);for(var h=this,f=0;f<c.length&&c[f]===0;f++,h=h.sqr());if(++f<c.length)for(var p=h.sqr();f<c.length;f++,p=p.sqr())c[f]!==0&&(h=h.mul(p));return h},n.prototype.iushln=function(s){t(typeof s=="number"&&s>=0);var c=s%26,h=(s-c)/26,f=67108863>>>26-c<<26-c,p;if(c!==0){var w=0;for(p=0;p<this.length;p++){var k=this.words[p]&f,d=(this.words[p]|0)-k<<c;this.words[p]=d|w,w=k>>>26-c}w&&(this.words[p]=w,this.length++)}if(h!==0){for(p=this.length-1;p>=0;p--)this.words[p+h]=this.words[p];for(p=0;p<h;p++)this.words[p]=0;this.length+=h}return this._strip()},n.prototype.ishln=function(s){return t(this.negative===0),this.iushln(s)},n.prototype.iushrn=function(s,c,h){t(typeof s=="number"&&s>=0);var f;c?f=(c-c%26)/26:f=0;var p=s%26,w=Math.min((s-p)/26,this.length),k=67108863^67108863>>>p<<p,d=h;if(f-=w,f=Math.max(0,f),d){for(var o=0;o<w;o++)d.words[o]=this.words[o];d.length=w}if(w!==0)if(this.length>w)for(this.length-=w,o=0;o<this.length;o++)this.words[o]=this.words[o+w];else this.words[0]=0,this.length=1;var g=0;for(o=this.length-1;o>=0&&(g!==0||o>=f);o--){var K=this.words[o]|0;this.words[o]=g<<26-p|K>>>p,g=K&k}return d&&g!==0&&(d.words[d.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(s,c,h){return t(this.negative===0),this.iushrn(s,c,h)},n.prototype.shln=function(s){return this.clone().ishln(s)},n.prototype.ushln=function(s){return this.clone().iushln(s)},n.prototype.shrn=function(s){return this.clone().ishrn(s)},n.prototype.ushrn=function(s){return this.clone().iushrn(s)},n.prototype.testn=function(s){t(typeof s=="number"&&s>=0);var c=s%26,h=(s-c)/26,f=1<<c;if(this.length<=h)return!1;var p=this.words[h];return!!(p&f)},n.prototype.imaskn=function(s){t(typeof s=="number"&&s>=0);var c=s%26,h=(s-c)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(c!==0&&h++,this.length=Math.min(h,this.length),c!==0){var f=67108863^67108863>>>c<<c;this.words[this.length-1]&=f}return this._strip()},n.prototype.maskn=function(s){return this.clone().imaskn(s)},n.prototype.iaddn=function(s){return t(typeof s=="number"),t(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<=s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},n.prototype._iaddn=function(s){this.words[0]+=s;for(var c=0;c<this.length&&this.words[c]>=67108864;c++)this.words[c]-=67108864,c===this.length-1?this.words[c+1]=1:this.words[c+1]++;return this.length=Math.max(this.length,c+1),this},n.prototype.isubn=function(s){if(t(typeof s=="number"),t(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var c=0;c<this.length&&this.words[c]<0;c++)this.words[c]+=67108864,this.words[c+1]-=1;return this._strip()},n.prototype.addn=function(s){return this.clone().iaddn(s)},n.prototype.subn=function(s){return this.clone().isubn(s)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(s,c,h){var f=s.length+h,p;this._expand(f);var w,k=0;for(p=0;p<s.length;p++){w=(this.words[p+h]|0)+k;var d=(s.words[p]|0)*c;w-=d&67108863,k=(w>>26)-(d/67108864|0),this.words[p+h]=w&67108863}for(;p<this.length-h;p++)w=(this.words[p+h]|0)+k,k=w>>26,this.words[p+h]=w&67108863;if(k===0)return this._strip();for(t(k===-1),k=0,p=0;p<this.length;p++)w=-(this.words[p]|0)+k,k=w>>26,this.words[p]=w&67108863;return this.negative=1,this._strip()},n.prototype._wordDiv=function(s,c){var h=this.length-s.length,f=this.clone(),p=s,w=p.words[p.length-1]|0,k=this._countBits(w);h=26-k,h!==0&&(p=p.ushln(h),f.iushln(h),w=p.words[p.length-1]|0);var d=f.length-p.length,o;if(c!=="mod"){o=new n(null),o.length=d+1,o.words=new Array(o.length);for(var g=0;g<o.length;g++)o.words[g]=0}var K=f.clone()._ishlnsubmul(p,1,d);K.negative===0&&(f=K,o&&(o.words[d]=1));for(var q=d-1;q>=0;q--){var U=(f.words[p.length+q]|0)*67108864+(f.words[p.length+q-1]|0);for(U=Math.min(U/w|0,67108863),f._ishlnsubmul(p,U,q);f.negative!==0;)U--,f.negative=0,f._ishlnsubmul(p,1,q),f.isZero()||(f.negative^=1);o&&(o.words[q]=U)}return o&&o._strip(),f._strip(),c!=="div"&&h!==0&&f.iushrn(h),{div:o||null,mod:f}},n.prototype.divmod=function(s,c,h){if(t(!s.isZero()),this.isZero())return{div:new n(0),mod:new n(0)};var f,p,w;return this.negative!==0&&s.negative===0?(w=this.neg().divmod(s,c),c!=="mod"&&(f=w.div.neg()),c!=="div"&&(p=w.mod.neg(),h&&p.negative!==0&&p.iadd(s)),{div:f,mod:p}):this.negative===0&&s.negative!==0?(w=this.divmod(s.neg(),c),c!=="mod"&&(f=w.div.neg()),{div:f,mod:w.mod}):(this.negative&s.negative)!==0?(w=this.neg().divmod(s.neg(),c),c!=="div"&&(p=w.mod.neg(),h&&p.negative!==0&&p.isub(s)),{div:w.div,mod:p}):s.length>this.length||this.cmp(s)<0?{div:new n(0),mod:this}:s.length===1?c==="div"?{div:this.divn(s.words[0]),mod:null}:c==="mod"?{div:null,mod:new n(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new n(this.modrn(s.words[0]))}:this._wordDiv(s,c)},n.prototype.div=function(s){return this.divmod(s,"div",!1).div},n.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},n.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},n.prototype.divRound=function(s){var c=this.divmod(s);if(c.mod.isZero())return c.div;var h=c.div.negative!==0?c.mod.isub(s):c.mod,f=s.ushrn(1),p=s.andln(1),w=h.cmp(f);return w<0||p===1&&w===0?c.div:c.div.negative!==0?c.div.isubn(1):c.div.iaddn(1)},n.prototype.modrn=function(s){var c=s<0;c&&(s=-s),t(s<=67108863);for(var h=(1<<26)%s,f=0,p=this.length-1;p>=0;p--)f=(h*f+(this.words[p]|0))%s;return c?-f:f},n.prototype.modn=function(s){return this.modrn(s)},n.prototype.idivn=function(s){var c=s<0;c&&(s=-s),t(s<=67108863);for(var h=0,f=this.length-1;f>=0;f--){var p=(this.words[f]|0)+h*67108864;this.words[f]=p/s|0,h=p%s}return this._strip(),c?this.ineg():this},n.prototype.divn=function(s){return this.clone().idivn(s)},n.prototype.egcd=function(s){t(s.negative===0),t(!s.isZero());var c=this,h=s.clone();c.negative!==0?c=c.umod(s):c=c.clone();for(var f=new n(1),p=new n(0),w=new n(0),k=new n(1),d=0;c.isEven()&&h.isEven();)c.iushrn(1),h.iushrn(1),++d;for(var o=h.clone(),g=c.clone();!c.isZero();){for(var K=0,q=1;(c.words[0]&q)===0&&K<26;++K,q<<=1);if(K>0)for(c.iushrn(K);K-- >0;)(f.isOdd()||p.isOdd())&&(f.iadd(o),p.isub(g)),f.iushrn(1),p.iushrn(1);for(var U=0,F=1;(h.words[0]&F)===0&&U<26;++U,F<<=1);if(U>0)for(h.iushrn(U);U-- >0;)(w.isOdd()||k.isOdd())&&(w.iadd(o),k.isub(g)),w.iushrn(1),k.iushrn(1);c.cmp(h)>=0?(c.isub(h),f.isub(w),p.isub(k)):(h.isub(c),w.isub(f),k.isub(p))}return{a:w,b:k,gcd:h.iushln(d)}},n.prototype._invmp=function(s){t(s.negative===0),t(!s.isZero());var c=this,h=s.clone();c.negative!==0?c=c.umod(s):c=c.clone();for(var f=new n(1),p=new n(0),w=h.clone();c.cmpn(1)>0&&h.cmpn(1)>0;){for(var k=0,d=1;(c.words[0]&d)===0&&k<26;++k,d<<=1);if(k>0)for(c.iushrn(k);k-- >0;)f.isOdd()&&f.iadd(w),f.iushrn(1);for(var o=0,g=1;(h.words[0]&g)===0&&o<26;++o,g<<=1);if(o>0)for(h.iushrn(o);o-- >0;)p.isOdd()&&p.iadd(w),p.iushrn(1);c.cmp(h)>=0?(c.isub(h),f.isub(p)):(h.isub(c),p.isub(f))}var K;return c.cmpn(1)===0?K=f:K=p,K.cmpn(0)<0&&K.iadd(s),K},n.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var c=this.clone(),h=s.clone();c.negative=0,h.negative=0;for(var f=0;c.isEven()&&h.isEven();f++)c.iushrn(1),h.iushrn(1);do{for(;c.isEven();)c.iushrn(1);for(;h.isEven();)h.iushrn(1);var p=c.cmp(h);if(p<0){var w=c;c=h,h=w}else if(p===0||h.cmpn(1)===0)break;c.isub(h)}while(!0);return h.iushln(f)},n.prototype.invm=function(s){return this.egcd(s).a.umod(s)},n.prototype.isEven=function(){return(this.words[0]&1)===0},n.prototype.isOdd=function(){return(this.words[0]&1)===1},n.prototype.andln=function(s){return this.words[0]&s},n.prototype.bincn=function(s){t(typeof s=="number");var c=s%26,h=(s-c)/26,f=1<<c;if(this.length<=h)return this._expand(h+1),this.words[h]|=f,this;for(var p=f,w=h;p!==0&&w<this.length;w++){var k=this.words[w]|0;k+=p,p=k>>>26,k&=67108863,this.words[w]=k}return p!==0&&(this.words[w]=p,this.length++),this},n.prototype.isZero=function(){return this.length===1&&this.words[0]===0},n.prototype.cmpn=function(s){var c=s<0;if(this.negative!==0&&!c)return-1;if(this.negative===0&&c)return 1;this._strip();var h;if(this.length>1)h=1;else{c&&(s=-s),t(s<=67108863,"Number is too big");var f=this.words[0]|0;h=f===s?0:f<s?-1:1}return this.negative!==0?-h|0:h},n.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var c=this.ucmp(s);return this.negative!==0?-c|0:c},n.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var c=0,h=this.length-1;h>=0;h--){var f=this.words[h]|0,p=s.words[h]|0;if(f!==p){f<p?c=-1:f>p&&(c=1);break}}return c},n.prototype.gtn=function(s){return this.cmpn(s)===1},n.prototype.gt=function(s){return this.cmp(s)===1},n.prototype.gten=function(s){return this.cmpn(s)>=0},n.prototype.gte=function(s){return this.cmp(s)>=0},n.prototype.ltn=function(s){return this.cmpn(s)===-1},n.prototype.lt=function(s){return this.cmp(s)===-1},n.prototype.lten=function(s){return this.cmpn(s)<=0},n.prototype.lte=function(s){return this.cmp(s)<=0},n.prototype.eqn=function(s){return this.cmpn(s)===0},n.prototype.eq=function(s){return this.cmp(s)===0},n.red=function(s){return new pe(s)},n.prototype.toRed=function(s){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},n.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(s){return this.red=s,this},n.prototype.forceRed=function(s){return t(!this.red,"Already a number in reduction context"),this._forceRed(s)},n.prototype.redAdd=function(s){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},n.prototype.redIAdd=function(s){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},n.prototype.redSub=function(s){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},n.prototype.redISub=function(s){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},n.prototype.redShl=function(s){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},n.prototype.redMul=function(s){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},n.prototype.redIMul=function(s){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},n.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(s){return t(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var ut={k256:null,p224:null,p192:null,p25519:null};function ce(b,s){this.name=b,this.p=new n(s,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}ce.prototype._tmp=function(){var s=new n(null);return s.words=new Array(Math.ceil(this.n/13)),s},ce.prototype.ireduce=function(s){var c=s,h;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),h=c.bitLength();while(h>this.n);var f=h<this.n?-1:c.ucmp(this.p);return f===0?(c.words[0]=0,c.length=1):f>0?c.isub(this.p):c.strip!==void 0?c.strip():c._strip(),c},ce.prototype.split=function(s,c){s.iushrn(this.n,0,c)},ce.prototype.imulK=function(s){return s.imul(this.k)};function tt(){ce.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(tt,ce),tt.prototype.split=function(s,c){for(var h=4194303,f=Math.min(s.length,9),p=0;p<f;p++)c.words[p]=s.words[p];if(c.length=f,s.length<=9){s.words[0]=0,s.length=1;return}var w=s.words[9];for(c.words[c.length++]=w&h,p=10;p<s.length;p++){var k=s.words[p]|0;s.words[p-10]=(k&h)<<4|w>>>22,w=k}w>>>=22,s.words[p-10]=w,w===0&&s.length>10?s.length-=10:s.length-=9},tt.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var c=0,h=0;h<s.length;h++){var f=s.words[h]|0;c+=f*977,s.words[h]=c&67108863,c=f*64+(c/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function Bt(){ce.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(Bt,ce);function ts(){ce.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(ts,ce);function tn(){ce.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(tn,ce),tn.prototype.imulK=function(s){for(var c=0,h=0;h<s.length;h++){var f=(s.words[h]|0)*19+c,p=f&67108863;f>>>=26,s.words[h]=p,c=f}return c!==0&&(s.words[s.length++]=c),s},n._prime=function(s){if(ut[s])return ut[s];var c;if(s==="k256")c=new tt;else if(s==="p224")c=new Bt;else if(s==="p192")c=new ts;else if(s==="p25519")c=new tn;else throw new Error("Unknown prime "+s);return ut[s]=c,c};function pe(b){if(typeof b=="string"){var s=n._prime(b);this.m=s.p,this.prime=s}else t(b.gtn(1),"modulus must be greater than 1"),this.m=b,this.prime=null}pe.prototype._verify1=function(s){t(s.negative===0,"red works only with positives"),t(s.red,"red works only with red numbers")},pe.prototype._verify2=function(s,c){t((s.negative|c.negative)===0,"red works only with positives"),t(s.red&&s.red===c.red,"red works only with red numbers")},pe.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(I(s,s.umod(this.m)._forceRed(this)),s)},pe.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},pe.prototype.add=function(s,c){this._verify2(s,c);var h=s.add(c);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},pe.prototype.iadd=function(s,c){this._verify2(s,c);var h=s.iadd(c);return h.cmp(this.m)>=0&&h.isub(this.m),h},pe.prototype.sub=function(s,c){this._verify2(s,c);var h=s.sub(c);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},pe.prototype.isub=function(s,c){this._verify2(s,c);var h=s.isub(c);return h.cmpn(0)<0&&h.iadd(this.m),h},pe.prototype.shl=function(s,c){return this._verify1(s),this.imod(s.ushln(c))},pe.prototype.imul=function(s,c){return this._verify2(s,c),this.imod(s.imul(c))},pe.prototype.mul=function(s,c){return this._verify2(s,c),this.imod(s.mul(c))},pe.prototype.isqr=function(s){return this.imul(s,s.clone())},pe.prototype.sqr=function(s){return this.mul(s,s)},pe.prototype.sqrt=function(s){if(s.isZero())return s.clone();var c=this.m.andln(3);if(t(c%2===1),c===3){var h=this.m.add(new n(1)).iushrn(2);return this.pow(s,h)}for(var f=this.m.subn(1),p=0;!f.isZero()&&f.andln(1)===0;)p++,f.iushrn(1);t(!f.isZero());var w=new n(1).toRed(this),k=w.redNeg(),d=this.m.subn(1).iushrn(1),o=this.m.bitLength();for(o=new n(2*o*o).toRed(this);this.pow(o,d).cmp(k)!==0;)o.redIAdd(k);for(var g=this.pow(o,f),K=this.pow(s,f.addn(1).iushrn(1)),q=this.pow(s,f),U=p;q.cmp(w)!==0;){for(var F=q,te=0;F.cmp(w)!==0;te++)F=F.redSqr();t(te<U);var se=this.pow(g,new n(1).iushln(U-te-1));K=K.redMul(se),g=se.redSqr(),q=q.redMul(g),U=te}return K},pe.prototype.invm=function(s){var c=s._invmp(this.m);return c.negative!==0?(c.negative=0,this.imod(c).redNeg()):this.imod(c)},pe.prototype.pow=function(s,c){if(c.isZero())return new n(1).toRed(this);if(c.cmpn(1)===0)return s.clone();var h=4,f=new Array(1<<h);f[0]=new n(1).toRed(this),f[1]=s;for(var p=2;p<f.length;p++)f[p]=this.mul(f[p-1],s);var w=f[0],k=0,d=0,o=c.bitLength()%26;for(o===0&&(o=26),p=c.length-1;p>=0;p--){for(var g=c.words[p],K=o-1;K>=0;K--){var q=g>>K&1;if(w!==f[0]&&(w=this.sqr(w)),q===0&&k===0){d=0;continue}k<<=1,k|=q,d++,!(d!==h&&(p!==0||K!==0))&&(w=this.mul(w,f[k]),d=0,k=0)}o=26}return w},pe.prototype.convertTo=function(s){var c=s.umod(this.m);return c===s?c.clone():c},pe.prototype.convertFrom=function(s){var c=s.clone();return c.red=null,c},n.mont=function(s){return new Lt(s)};function Lt(b){pe.call(this,b),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(Lt,pe),Lt.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Lt.prototype.convertFrom=function(s){var c=this.imod(s.mul(this.rinv));return c.red=null,c},Lt.prototype.imul=function(s,c){if(s.isZero()||c.isZero())return s.words[0]=0,s.length=1,s;var h=s.imul(c),f=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=h.isub(f).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},Lt.prototype.mul=function(s,c){if(s.isZero()||c.isZero())return new n(0)._forceRed(this);var h=s.mul(c),f=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=h.isub(f).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},Lt.prototype.invm=function(s){var c=this.imod(s._invmp(this.m).mul(this.r2));return c._forceRed(this)}})(typeof An>"u"||An,vs)});var _s=fr(($a,Is)=>{"use strict";rt();nt();var yr=Bi().Buffer;function Ei(a){if(a.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<a.length;r++){var n=a.charAt(r),i=n.charCodeAt(0);if(e[i]!==255)throw new TypeError(n+" is ambiguous");e[i]=r}var u=a.length,l=a.charAt(0),m=Math.log(u)/Math.log(256),I=Math.log(256)/Math.log(u);function B(_){if((Array.isArray(_)||_ instanceof Uint8Array)&&(_=yr.from(_)),!yr.isBuffer(_))throw new TypeError("Expected Buffer");if(_.length===0)return"";for(var R=0,L=0,z=0,W=_.length;z!==W&&_[z]===0;)z++,R++;for(var J=(W-z)*I+1>>>0,le=new Uint8Array(J);z!==W;){for(var ee=_[z],ut=0,ce=J-1;(ee!==0||ut<L)&&ce!==-1;ce--,ut++)ee+=256*le[ce]>>>0,le[ce]=ee%u>>>0,ee=ee/u>>>0;if(ee!==0)throw new Error("Non-zero carry");L=ut,z++}for(var tt=J-L;tt!==J&&le[tt]===0;)tt++;for(var Bt=l.repeat(R);tt<J;++tt)Bt+=a.charAt(le[tt]);return Bt}function x(_){if(typeof _!="string")throw new TypeError("Expected String");if(_.length===0)return yr.alloc(0);var R=0;if(_[R]!==" "){for(var L=0,z=0;_[R]===l;)L++,R++;for(var W=(_.length-R)*m+1>>>0,J=new Uint8Array(W);_[R];){var le=e[_.charCodeAt(R)];if(le===255)return;for(var ee=0,ut=W-1;(le!==0||ee<z)&&ut!==-1;ut--,ee++)le+=u*J[ut]>>>0,J[ut]=le%256>>>0,le=le/256>>>0;if(le!==0)throw new Error("Non-zero carry");z=ee,R++}if(_[R]!==" "){for(var ce=W-z;ce!==W&&J[ce]===0;)ce++;var tt=yr.allocUnsafe(L+(W-ce));tt.fill(0,0,L);for(var Bt=L;ce!==W;)tt[Bt++]=J[ce++];return tt}}}function N(_){var R=x(_);if(R)return R;throw new Error("Non-base"+u+" character")}return{encode:B,decodeUnsafe:x,decode:N}}Is.exports=Ei});var Bs=fr((Ha,As)=>{rt();nt();var Mi=_s(),Pi="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";As.exports=Mi(Pi)});var xn=fr(S=>{"use strict";rt();nt();Object.defineProperty(S,"__esModule",{value:!0});S.s16=S.s8=S.nu64be=S.u48be=S.u40be=S.u32be=S.u24be=S.u16be=S.nu64=S.u48=S.u40=S.u32=S.u24=S.u16=S.u8=S.offset=S.greedy=S.Constant=S.UTF8=S.CString=S.Blob=S.Boolean=S.BitField=S.BitStructure=S.VariantLayout=S.Union=S.UnionLayoutDiscriminator=S.UnionDiscriminator=S.Structure=S.Sequence=S.DoubleBE=S.Double=S.FloatBE=S.Float=S.NearInt64BE=S.NearInt64=S.NearUInt64BE=S.NearUInt64=S.IntBE=S.Int=S.UIntBE=S.UInt=S.OffsetLayout=S.GreedyCount=S.ExternalLayout=S.bindConstructorLayout=S.nameWithProperty=S.Layout=S.uint8ArrayToBuffer=S.checkUint8Array=void 0;S.constant=S.utf8=S.cstr=S.blob=S.unionLayoutDiscriminator=S.union=S.seq=S.bits=S.struct=S.f64be=S.f64=S.f32be=S.f32=S.ns64be=S.s48be=S.s40be=S.s32be=S.s24be=S.s16be=S.ns64=S.s48=S.s40=S.s32=S.s24=void 0;var Ln=ks();function $t(a){if(!(a instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}S.checkUint8Array=$t;function Y(a){return $t(a),Ln.Buffer.from(a.buffer,a.byteOffset,a.length)}S.uint8ArrayToBuffer=Y;var Q=class{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){let t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}};S.Layout=Q;function Rn(a,e){return e.property?a+"["+e.property+"]":a}S.nameWithProperty=Rn;function Ti(a,e){if(typeof a!="function")throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(a,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Q))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");a.layout_=e,e.boundConstructor_=a,e.makeDestinationObject=()=>new a,Object.defineProperty(a.prototype,"encode",{value(t,r){return e.encode(this,t,r)},writable:!0}),Object.defineProperty(a,"decode",{value(t,r){return e.decode(t,r)},writable:!0})}S.bindConstructorLayout=Ti;var Qe=class extends Q{isCount(){throw new Error("ExternalLayout is abstract")}};S.ExternalLayout=Qe;var gr=class extends Qe{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return!0}decode(e,t=0){$t(e);let r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}};S.GreedyCount=gr;var Xt=class extends Qe{constructor(e,t=0,r){if(!(e instanceof Q))throw new TypeError("layout must be a Layout");if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof st||this.layout instanceof at}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,r=0){return this.layout.encode(e,t,r+this.offset)}};S.OffsetLayout=Xt;var st=class extends Q{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return Y(e).readUIntLE(t,this.span)}encode(e,t,r=0){return Y(t).writeUIntLE(e,r,this.span),this.span}};S.UInt=st;var at=class extends Q{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return Y(e).readUIntBE(t,this.span)}encode(e,t,r=0){return Y(t).writeUIntBE(e,r,this.span),this.span}};S.UIntBE=at;var gt=class extends Q{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return Y(e).readIntLE(t,this.span)}encode(e,t,r=0){return Y(t).writeIntLE(e,r,this.span),this.span}};S.Int=gt;var vt=class extends Q{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return Y(e).readIntBE(t,this.span)}encode(e,t,r=0){return Y(t).writeIntBE(e,r,this.span),this.span}};S.IntBE=vt;var Bn=Math.pow(2,32);function Tr(a){let e=Math.floor(a/Bn),t=a-e*Bn;return{hi32:e,lo32:t}}function Cr(a,e){return a*Bn+e}var mr=class extends Q{constructor(e){super(8,e)}decode(e,t=0){let r=Y(e),n=r.readUInt32LE(t),i=r.readUInt32LE(t+4);return Cr(i,n)}encode(e,t,r=0){let n=Tr(e),i=Y(t);return i.writeUInt32LE(n.lo32,r),i.writeUInt32LE(n.hi32,r+4),8}};S.NearUInt64=mr;var br=class extends Q{constructor(e){super(8,e)}decode(e,t=0){let r=Y(e),n=r.readUInt32BE(t),i=r.readUInt32BE(t+4);return Cr(n,i)}encode(e,t,r=0){let n=Tr(e),i=Y(t);return i.writeUInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}};S.NearUInt64BE=br;var wr=class extends Q{constructor(e){super(8,e)}decode(e,t=0){let r=Y(e),n=r.readUInt32LE(t),i=r.readInt32LE(t+4);return Cr(i,n)}encode(e,t,r=0){let n=Tr(e),i=Y(t);return i.writeUInt32LE(n.lo32,r),i.writeInt32LE(n.hi32,r+4),8}};S.NearInt64=wr;var kr=class extends Q{constructor(e){super(8,e)}decode(e,t=0){let r=Y(e),n=r.readInt32BE(t),i=r.readUInt32BE(t+4);return Cr(n,i)}encode(e,t,r=0){let n=Tr(e),i=Y(t);return i.writeInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}};S.NearInt64BE=kr;var vr=class extends Q{constructor(e){super(4,e)}decode(e,t=0){return Y(e).readFloatLE(t)}encode(e,t,r=0){return Y(t).writeFloatLE(e,r),4}};S.Float=vr;var Sr=class extends Q{constructor(e){super(4,e)}decode(e,t=0){return Y(e).readFloatBE(t)}encode(e,t,r=0){return Y(t).writeFloatBE(e,r),4}};S.FloatBE=Sr;var Ir=class extends Q{constructor(e){super(8,e)}decode(e,t=0){return Y(e).readDoubleLE(t)}encode(e,t,r=0){return Y(t).writeDoubleLE(e,r),8}};S.Double=Ir;var _r=class extends Q{constructor(e){super(8,e)}decode(e,t=0){return Y(e).readDoubleBE(t)}encode(e,t,r=0){return Y(t).writeDoubleBE(e,r),8}};S.DoubleBE=_r;var Ar=class extends Q{constructor(e,t,r){if(!(e instanceof Q))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof Qe&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(t instanceof Qe)&&0<e.span&&(n=t*e.span),super(n,r),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0,n=this.count;if(n instanceof Qe&&(n=n.decode(e,t)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let i=0;for(;i<n;)r+=this.elementLayout.getSpan(e,t+r),++i}return r}decode(e,t=0){let r=[],n=0,i=this.count;for(i instanceof Qe&&(i=i.decode(e,t));n<i;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),n+=1;return r}encode(e,t,r=0){let n=this.elementLayout,i=e.reduce((u,l)=>u+n.encode(l,t,r+u),0);return this.count instanceof Qe&&this.count.encode(e.length,t,r),i}};S.Sequence=Ar;var Br=class extends Q{constructor(e,t,r){if(!(Array.isArray(e)&&e.reduce((i,u)=>i&&u instanceof Q,!0)))throw new TypeError("fields must be array of Layout instances");typeof t=="boolean"&&r===void 0&&(r=t,t=void 0);for(let i of e)if(0>i.span&&i.property===void 0)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=e.reduce((i,u)=>i+u.getSpan(),0)}catch{}super(n,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;try{r=this.fields.reduce((n,i)=>{let u=i.getSpan(e,t);return t+=u,n+u},0)}catch{throw new RangeError("indeterminate span")}return r}decode(e,t=0){$t(e);let r=this.makeDestinationObject();for(let n of this.fields)if(n.property!==void 0&&(r[n.property]=n.decode(e,t)),t+=n.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r=0){let n=r,i=0,u=0;for(let l of this.fields){let m=l.span;if(u=0<m?m:0,l.property!==void 0){let I=e[l.property];I!==void 0&&(u=l.encode(I,t,r),0>m&&(m=l.getSpan(t,r)))}i=r,r+=m}return i+u-n}fromArray(e){let t=this.makeDestinationObject();for(let r of this.fields)r.property!==void 0&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}offsetOf(e){if(typeof e!="string")throw new TypeError("property must be string");let t=0;for(let r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}};S.Structure=Br;var Qt=class{constructor(e){this.property=e}decode(e,t){throw new Error("UnionDiscriminator is abstract")}encode(e,t,r){throw new Error("UnionDiscriminator is abstract")}};S.UnionDiscriminator=Qt;var Dt=class extends Qt{constructor(e,t){if(!(e instanceof Qe&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}};S.UnionLayoutDiscriminator=Dt;var er=class extends Q{constructor(e,t,r){let n;if(e instanceof st||e instanceof at)n=new Dt(new Xt(e));else if(e instanceof Qe&&e.isCount())n=new Dt(e);else if(e instanceof Qt)n=e;else throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(t===void 0&&(t=null),!(t===null||t instanceof Q))throw new TypeError("defaultLayout must be null or a Layout");if(t!==null){if(0>t.span)throw new Error("defaultLayout must have constant span");t.property===void 0&&(t=t.replicate("content"))}let i=-1;t&&(i=t.span,0<=i&&(e instanceof st||e instanceof at)&&(i+=n.layout.span)),super(i,r),this.discriminator=n,this.usesPrefixDiscriminator=e instanceof st||e instanceof at,this.defaultLayout=t,this.registry={};let u=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(l){return u(l)},this.configGetSourceVariant=function(l){u=l.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;let r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(Object.prototype.hasOwnProperty.call(e,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(e,this.defaultLayout.property))return;let t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||t.property&&Object.prototype.hasOwnProperty.call(e,t.property)))return t}else for(let t in this.registry){let r=this.registry[t];if(r.property&&Object.prototype.hasOwnProperty.call(e,r.property))return r}throw new Error("unable to infer src variant")}decode(e,t=0){let r,n=this.discriminator,i=n.decode(e,t),u=this.registry[i];if(u===void 0){let l=this.defaultLayout,m=0;this.usesPrefixDiscriminator&&(m=n.layout.span),r=this.makeDestinationObject(),r[n.property]=i,r[l.property]=l.decode(e,t+m)}else r=u.decode(e,t);return r}encode(e,t,r=0){let n=this.getSourceVariant(e);if(n===void 0){let i=this.discriminator,u=this.defaultLayout,l=0;return this.usesPrefixDiscriminator&&(l=i.layout.span),i.encode(e[i.property],t,r),l+u.encode(e[u.property],t,r+l)}return n.encode(e,t,r)}addVariant(e,t,r){let n=new Lr(this,e,t,r);return this.registry[e]=n,n}getVariant(e,t=0){let r;return e instanceof Uint8Array?r=this.discriminator.decode(e,t):r=e,this.registry[r]}};S.Union=er;var Lr=class extends Q{constructor(e,t,r,n){if(!(e instanceof er))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if(typeof r=="string"&&n===void 0&&(n=r,r=null),r){if(!(r instanceof Q))throw new TypeError("layout must be a Layout");if(e.defaultLayout!==null&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if(typeof n!="string")throw new TypeError("variant must have a String property")}let i=e.span;0>e.span&&(i=r?r.span:0,0<=i&&e.usesPrefixDiscriminator&&(i+=e.discriminator.layout.span)),super(i,n),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span);let n=0;return this.layout&&(n=this.layout.getSpan(e,t+r)),r+n}decode(e,t=0){let r=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+n):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r=0){let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let i=n;if(this.layout&&(this.layout.encode(e[this.property],t,r+n),i+=this.layout.getSpan(t,r+n),0<=this.union.span&&i>this.union.span))throw new Error("encoded variant overruns containing union");return i}fromArray(e){if(this.layout)return this.layout.fromArray(e)}};S.VariantLayout=Lr;function Ut(a){return 0>a&&(a+=4294967296),a}var tr=class extends Q{constructor(e,t,r){if(!(e instanceof st||e instanceof at))throw new TypeError("word must be a UInt or UIntBE layout");if(typeof t=="string"&&r===void 0&&(r=t,t=!1),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let n=0;this._packedSetValue=function(i){return n=Ut(i),this},this._packedGetValue=function(){return n}}decode(e,t=0){let r=this.makeDestinationObject(),n=this.word.decode(e,t);this._packedSetValue(n);for(let i of this.fields)i.property!==void 0&&(r[i.property]=i.decode(e));return r}encode(e,t,r=0){let n=this.word.decode(t,r);this._packedSetValue(n);for(let i of this.fields)if(i.property!==void 0){let u=e[i.property];u!==void 0&&i.encode(u)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){let r=new rr(this,e,t);return this.fields.push(r),r}addBoolean(e){let t=new Rr(this,e);return this.fields.push(t),t}fieldFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}};S.BitStructure=tr;var rr=class{constructor(e,t,r){if(!(e instanceof tr))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");let n=8*e.span,i=e.fields.reduce((u,l)=>u+l.bits,0);if(t+i>n)throw new Error("bits too long for span remainder ("+(n-i)+" of "+n+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,t===32&&(this.valueMask=4294967295),this.start=i,this.container.msb&&(this.start=n-i-t),this.wordMask=Ut(this.valueMask<<this.start),this.property=r}decode(e,t){let r=this.container._packedGetValue();return Ut(r&this.wordMask)>>>this.start}encode(e){if(typeof e!="number"||!Number.isInteger(e)||e!==Ut(e&this.valueMask))throw new TypeError(Rn("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);let t=this.container._packedGetValue(),r=Ut(e<<this.start);this.container._packedSetValue(Ut(t&~this.wordMask)|r)}};S.BitField=rr;var Rr=class extends rr{constructor(e,t){super(e,1,t)}decode(e,t){return!!super.decode(e,t)}encode(e){typeof e=="boolean"&&(e=+e),super.encode(e)}};S.Boolean=Rr;var xr=class extends Q{constructor(e,t){if(!(e instanceof Qe&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof Qe||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t=0){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),Y(e).slice(t,t+r)}encode(e,t,r){let n=this.length;if(this.length instanceof Qe&&(n=e.length),!(e instanceof Uint8Array&&n===e.length))throw new TypeError(Rn("Blob.encode",this)+" requires (length "+n+") Uint8Array as src");if(r+n>t.length)throw new RangeError("encoding overruns Uint8Array");let i=Y(e);return Y(t).write(i.toString("hex"),r,n,"hex"),this.length instanceof Qe&&this.length.encode(n,t,r),n}};S.Blob=xr;var Er=class extends Q{constructor(e){super(-1,e)}getSpan(e,t=0){$t(e);let r=t;for(;r<e.length&&e[r]!==0;)r+=1;return 1+r-t}decode(e,t=0){let r=this.getSpan(e,t);return Y(e).slice(t,t+r-1).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let n=Ln.Buffer.from(e,"utf8"),i=n.length;if(r+i>t.length)throw new RangeError("encoding overruns Buffer");let u=Y(t);return n.copy(u,r),u[r+i]=0,i+1}};S.CString=Er;var Mr=class extends Q{constructor(e,t){if(typeof e=="string"&&t===void 0&&(t=e,e=void 0),e===void 0)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t=0){return $t(e),e.length-t}decode(e,t=0){let r=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<r)throw new RangeError("text length exceeds maxSpan");return Y(e).slice(t,t+r).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let n=Ln.Buffer.from(e,"utf8"),i=n.length;if(0<=this.maxSpan&&this.maxSpan<i)throw new RangeError("text length exceeds maxSpan");if(r+i>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(Y(t),r),i}};S.UTF8=Mr;var Pr=class extends Q{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,r){return 0}};S.Constant=Pr;S.greedy=(a,e)=>new gr(a,e);S.offset=(a,e,t)=>new Xt(a,e,t);S.u8=a=>new st(1,a);S.u16=a=>new st(2,a);S.u24=a=>new st(3,a);S.u32=a=>new st(4,a);S.u40=a=>new st(5,a);S.u48=a=>new st(6,a);S.nu64=a=>new mr(a);S.u16be=a=>new at(2,a);S.u24be=a=>new at(3,a);S.u32be=a=>new at(4,a);S.u40be=a=>new at(5,a);S.u48be=a=>new at(6,a);S.nu64be=a=>new br(a);S.s8=a=>new gt(1,a);S.s16=a=>new gt(2,a);S.s24=a=>new gt(3,a);S.s32=a=>new gt(4,a);S.s40=a=>new gt(5,a);S.s48=a=>new gt(6,a);S.ns64=a=>new wr(a);S.s16be=a=>new vt(2,a);S.s24be=a=>new vt(3,a);S.s32be=a=>new vt(4,a);S.s40be=a=>new vt(5,a);S.s48be=a=>new vt(6,a);S.ns64be=a=>new kr(a);S.f32=a=>new vr(a);S.f32be=a=>new Sr(a);S.f64=a=>new Ir(a);S.f64be=a=>new _r(a);S.struct=(a,e,t)=>new Br(a,e,t);S.bits=(a,e,t)=>new tr(a,e,t);S.seq=(a,e,t)=>new Ar(a,e,t);S.union=(a,e,t)=>new er(a,e,t);S.unionLayoutDiscriminator=(a,e)=>new Dt(a,e);S.blob=(a,e)=>new xr(a,e);S.cstr=a=>new Er(a);S.utf8=(a,e)=>new Mr(a,e);S.constant=(a,e)=>new Pr(a,e)});rt();nt();ws();var Dn=Rt(Ss()),Ze=Rt(Bs());var Yt=Rt(Ri()),y=Rt(xn()),ai=Rt(xn()),lr=Rt(Li());rt();nt();var En=class extends TypeError{constructor(e,t){let r,{message:n,explanation:i,...u}=e,{path:l}=e,m=l.length===0?n:`At path: ${l.join(".")} -- ${n}`;super(i??m),i!=null&&(this.cause=m),Object.assign(this,u),this.name=this.constructor.name,this.failures=()=>r??(r=[e,...t()])}};function Ci(a){return nr(a)&&typeof a[Symbol.iterator]=="function"}function nr(a){return typeof a=="object"&&a!=null}function zr(a){return nr(a)&&!Array.isArray(a)}function ft(a){return typeof a=="symbol"?a.toString():typeof a=="string"?JSON.stringify(a):`${a}`}function zi(a){let{done:e,value:t}=a.next();return e?void 0:t}function Ni(a,e,t,r){if(a===!0)return;a===!1?a={}:typeof a=="string"&&(a={message:a});let{path:n,branch:i}=e,{type:u}=t,{refinement:l,message:m=`Expected a value of type \`${u}\`${l?` with refinement \`${l}\``:""}, but received: \`${ft(r)}\``}=a;return{value:r,type:u,refinement:l,key:n[n.length-1],path:n,branch:i,...a,message:m}}function*Ls(a,e,t,r){Ci(a)||(a=[a]);for(let n of a){let i=Ni(n,e,t,r);i&&(yield i)}}function*Mn(a,e,t={}){let{path:r=[],branch:n=[a],coerce:i=!1,mask:u=!1}=t,l={path:r,branch:n,mask:u};i&&(a=e.coercer(a,l));let m="valid";for(let I of e.validator(a,l))I.explanation=t.message,m="not_valid",yield[I,void 0];for(let[I,B,x]of e.entries(a,l)){let N=Mn(B,x,{path:I===void 0?r:[...r,I],branch:I===void 0?n:[...n,B],coerce:i,mask:u,message:t.message});for(let _ of N)_[0]?(m=_[0].refinement!=null?"not_refined":"not_valid",yield[_[0],void 0]):i&&(B=_[1],I===void 0?a=B:a instanceof Map?a.set(I,B):a instanceof Set?a.add(B):nr(a)&&(B!==void 0||I in a)&&(a[I]=B))}if(m!=="not_valid")for(let I of e.refiner(a,l))I.explanation=t.message,m="not_refined",yield[I,void 0];m==="valid"&&(yield[void 0,a])}var ht=class{constructor(e){let{type:t,schema:r,validator:n,refiner:i,coercer:u=m=>m,entries:l=function*(){}}=e;this.type=t,this.schema=r,this.entries=l,this.coercer=u,n?this.validator=(m,I)=>{let B=n(m,I);return Ls(B,I,this,m)}:this.validator=()=>[],i?this.refiner=(m,I)=>{let B=i(m,I);return Ls(B,I,this,m)}:this.refiner=()=>[]}assert(e,t){return Pn(e,this,t)}create(e,t){return P(e,this,t)}is(e){return Rs(e,this)}mask(e,t){return Oi(e,this,t)}validate(e,t={}){return sr(e,this,t)}};function Pn(a,e,t){let r=sr(a,e,{message:t});if(r[0])throw r[0]}function P(a,e,t){let r=sr(a,e,{coerce:!0,message:t});if(r[0])throw r[0];return r[1]}function Oi(a,e,t){let r=sr(a,e,{coerce:!0,mask:!0,message:t});if(r[0])throw r[0];return r[1]}function Rs(a,e){return!sr(a,e)[0]}function sr(a,e,t={}){let r=Mn(a,e,t),n=zi(r);return n[0]?[new En(n[0],function*(){for(let u of r)u[0]&&(yield u[0])}),void 0]:[void 0,n[1]]}function Et(a,e){return new ht({type:a,schema:null,validator:e})}function xs(){return Et("any",()=>!0)}function T(a){return new ht({type:"array",schema:a,*entries(e){if(a&&Array.isArray(e))for(let[t,r]of e.entries())yield[t,r,a]},coercer(e){return Array.isArray(e)?e.slice():e},validator(e){return Array.isArray(e)||`Expected an array value, but received: ${ft(e)}`}})}function dt(){return Et("boolean",a=>typeof a=="boolean")}function Nr(a){return Et("instance",e=>e instanceof a||`Expected a \`${a.name}\` instance, but received: ${ft(e)}`)}function he(a){let e=ft(a),t=typeof a;return new ht({type:"literal",schema:t==="string"||t==="number"||t==="boolean"?a:null,validator(r){return r===a||`Expected the literal \`${e}\`, but received: ${ft(r)}`}})}function Ki(){return Et("never",()=>!1)}function C(a){return new ht({...a,validator:(e,t)=>e===null||a.validator(e,t),refiner:(e,t)=>e===null||a.refiner(e,t)})}function v(){return Et("number",a=>typeof a=="number"&&!isNaN(a)||`Expected a number, but received: ${ft(a)}`)}function $(a){return new ht({...a,validator:(e,t)=>e===void 0||a.validator(e,t),refiner:(e,t)=>e===void 0||a.refiner(e,t)})}function Tn(a,e){return new ht({type:"record",schema:null,*entries(t){if(nr(t))for(let r in t){let n=t[r];yield[r,r,a],yield[r,n,e]}},validator(t){return zr(t)||`Expected an object, but received: ${ft(t)}`},coercer(t){return zr(t)?{...t}:t}})}function E(){return Et("string",a=>typeof a=="string"||`Expected a string, but received: ${ft(a)}`)}function Or(a){let e=Ki();return new ht({type:"tuple",schema:null,*entries(t){if(Array.isArray(t)){let r=Math.max(a.length,t.length);for(let n=0;n<r;n++)yield[n,t[n],a[n]||e]}},validator(t){return Array.isArray(t)||`Expected an array, but received: ${ft(t)}`},coercer(t){return Array.isArray(t)?t.slice():t}})}function A(a){let e=Object.keys(a);return new ht({type:"type",schema:a,*entries(t){if(nr(t))for(let r of e)yield[r,t[r],a[r]]},validator(t){return zr(t)||`Expected an object, but received: ${ft(t)}`},coercer(t){return zr(t)?{...t}:t}})}function et(a){let e=a.map(t=>t.type).join(" | ");return new ht({type:"union",schema:null,coercer(t,r){for(let n of a){let[i,u]=n.validate(t,{coerce:!0,mask:r.mask});if(!i)return u}return t},validator(t,r){let n=[];for(let i of a){let[...u]=Mn(t,i,r),[l]=u;if(l[0])for(let[m]of u)m&&n.push(m);else return[]}return[`Expected the value to satisfy a union of \`${e}\`, but received: ${ft(t)}`,...n]}})}function Mt(){return Et("unknown",()=>!0)}function Ft(a,e,t){return new ht({...a,coercer:(r,n)=>Rs(r,e)?a.coercer(t(r,n),n):a.coercer(r,n)})}var ci=Rt(xi());rt();nt();ws();var Wi=class extends In.default{constructor(e,t,r){super();Ye(this,"socket");this.socket=new window.WebSocket(e,r),this.socket.onopen=()=>this.emit("open"),this.socket.onmessage=n=>this.emit("message",n.data),this.socket.onerror=n=>this.emit("error",n),this.socket.onclose=n=>{this.emit("close",n.code,n.reason)}}send(e,t,r){let n=r||t;try{this.socket.send(e),n()}catch(i){n(i)}}close(e,t){this.socket.close(e,t)}addEventListener(e,t,r){this.socket.addEventListener(e,t,r)}};function Es(a,e){return new Wi(a,e)}var qi=class{encode(a){return JSON.stringify(a)}decode(a){return JSON.parse(a)}},Ms=class extends In.default{constructor(e,t="ws://localhost:8080",{autoconnect:r=!0,reconnect:n=!0,reconnect_interval:i=1e3,max_reconnects:u=5,...l}={},m,I){super();Ye(this,"address");Ye(this,"rpc_id");Ye(this,"queue");Ye(this,"options");Ye(this,"autoconnect");Ye(this,"ready");Ye(this,"reconnect");Ye(this,"reconnect_timer_id");Ye(this,"reconnect_interval");Ye(this,"max_reconnects");Ye(this,"rest_options");Ye(this,"current_reconnects");Ye(this,"generate_request_id");Ye(this,"socket");Ye(this,"webSocketFactory");Ye(this,"dataPack");this.webSocketFactory=e,this.queue={},this.rpc_id=0,this.address=t,this.autoconnect=r,this.ready=!1,this.reconnect=n,this.reconnect_timer_id=void 0,this.reconnect_interval=i,this.max_reconnects=u,this.rest_options=l,this.current_reconnects=0,this.generate_request_id=m||(()=>++this.rpc_id),I?this.dataPack=I:this.dataPack=new qi,this.autoconnect&&this._connect(this.address,{autoconnect:this.autoconnect,reconnect:this.reconnect,reconnect_interval:this.reconnect_interval,max_reconnects:this.max_reconnects,...this.rest_options})}connect(){this.socket||this._connect(this.address,{autoconnect:this.autoconnect,reconnect:this.reconnect,reconnect_interval:this.reconnect_interval,max_reconnects:this.max_reconnects,...this.rest_options})}call(e,t,r,n){return!n&&typeof r=="object"&&(n=r,r=null),new Promise((i,u)=>{if(!this.ready)return u(new Error("socket not ready"));let l=this.generate_request_id(e,t),m={jsonrpc:"2.0",method:e,params:t||void 0,id:l};this.socket.send(this.dataPack.encode(m),n,I=>{if(I)return u(I);this.queue[l]={promise:[i,u]},r&&(this.queue[l].timeout=setTimeout(()=>{delete this.queue[l],u(new Error("reply timeout"))},r))})})}async login(e){let t=await this.call("rpc.login",e);if(!t)throw new Error("authentication failed");return t}async listMethods(){return await this.call("__listMethods")}notify(e,t){return new Promise((r,n)=>{if(!this.ready)return n(new Error("socket not ready"));let i={jsonrpc:"2.0",method:e,params:t};this.socket.send(this.dataPack.encode(i),u=>{if(u)return n(u);r()})})}async subscribe(e){typeof e=="string"&&(e=[e]);let t=await this.call("rpc.on",e);if(typeof e=="string"&&t[e]!=="ok")throw new Error("Failed subscribing to an event '"+e+"' with: "+t[e]);return t}async unsubscribe(e){typeof e=="string"&&(e=[e]);let t=await this.call("rpc.off",e);if(typeof e=="string"&&t[e]!=="ok")throw new Error("Failed unsubscribing from an event with: "+t);return t}close(e,t){this.socket.close(e||1e3,t)}setAutoReconnect(e){this.reconnect=e}setReconnectInterval(e){this.reconnect_interval=e}setMaxReconnects(e){this.max_reconnects=e}_connect(e,t){clearTimeout(this.reconnect_timer_id),this.socket=this.webSocketFactory(e,t),this.socket.addEventListener("open",()=>{this.ready=!0,this.emit("open"),this.current_reconnects=0}),this.socket.addEventListener("message",({data:r})=>{r instanceof ArrayBuffer&&(r=D.from(r).toString());try{r=this.dataPack.decode(r)}catch{return}if(r.notification&&this.listeners(r.notification).length){if(!Object.keys(r.params).length)return this.emit(r.notification);let n=[r.notification];if(r.params.constructor===Object)n.push(r.params);else for(let i=0;i<r.params.length;i++)n.push(r.params[i]);return Promise.resolve().then(()=>{this.emit.apply(this,n)})}if(!this.queue[r.id])return r.method?Promise.resolve().then(()=>{this.emit(r.method,r?.params)}):void 0;"error"in r=="result"in r&&this.queue[r.id].promise[1](new Error('Server response malformed. Response must include either "result" or "error", but not both.')),this.queue[r.id].timeout&&clearTimeout(this.queue[r.id].timeout),r.error?this.queue[r.id].promise[1](r.error):this.queue[r.id].promise[0](r.result),delete this.queue[r.id]}),this.socket.addEventListener("error",r=>this.emit("error",r)),this.socket.addEventListener("close",({code:r,reason:n})=>{this.ready&&setTimeout(()=>this.emit("close",r,n),0),this.ready=!1,this.socket=void 0,r!==1e3&&(this.current_reconnects++,this.reconnect&&(this.max_reconnects>this.current_reconnects||this.max_reconnects===0)&&(this.reconnect_timer_id=setTimeout(()=>this._connect(e,t),this.reconnect_interval)))})}};var Ui=xt.utils.randomPrivateKey,Ps=()=>{let a=xt.utils.randomPrivateKey(),e=qr(a),t=new Uint8Array(64);return t.set(a),t.set(e,32),{publicKey:e,secretKey:t}},qr=xt.getPublicKey;function Ts(a){try{return xt.ExtendedPoint.fromHex(a),!0}catch{return!1}}var Yn=(a,e)=>xt.sign(a,e.slice(0,32)),Di=xt.verify,H=a=>D.isBuffer(a)?a:a instanceof Uint8Array?D.from(a.buffer,a.byteOffset,a.byteLength):D.from(a),Ur=class{constructor(e){Object.assign(this,e)}encode(){return D.from((0,Yt.serialize)(Wr,this))}static decode(e){return(0,Yt.deserialize)(Wr,this,e)}static decodeUnchecked(e){return(0,Yt.deserializeUnchecked)(Wr,this,e)}},Cs=class extends Ur{constructor(e){if(super(e),this.enum="",Object.keys(e).length!==1)throw new Error("Enum can only take single value");Object.keys(e).map(t=>{this.enum=t})}},Wr=new Map,ui,$i=32,wt=32;function Fi(a){return a._bn!==void 0}var zs=1,M=class extends Ur{constructor(e){if(super({}),this._bn=void 0,Fi(e))this._bn=e._bn;else{if(typeof e=="string"){let t=Ze.default.decode(e);if(t.length!=wt)throw new Error("Invalid public key input");this._bn=new Dn.default(t)}else this._bn=new Dn.default(e);if(this._bn.byteLength()>wt)throw new Error("Invalid public key input")}}static unique(){let e=new M(zs);return zs+=1,new M(e.toBuffer())}equals(e){return this._bn.eq(e._bn)}toBase58(){return Ze.default.encode(this.toBytes())}toJSON(){return this.toBase58()}toBytes(){let e=this.toBuffer();return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}toBuffer(){let e=this._bn.toArrayLike(D);if(e.length===wt)return e;let t=D.alloc(32);return e.copy(t,32-e.length),t}get[Symbol.toStringTag](){return`PublicKey(${this.toString()})`}toString(){return this.toBase58()}static async createWithSeed(e,t,r){let n=D.concat([e.toBuffer(),D.from(t),r.toBuffer()]),i=Sn(n);return new M(i)}static createProgramAddressSync(e,t){let r=D.alloc(0);e.forEach(function(i){if(i.length>$i)throw new TypeError("Max seed length exceeded");r=D.concat([r,H(i)])}),r=D.concat([r,t.toBuffer(),D.from("ProgramDerivedAddress")]);let n=Sn(r);if(Ts(n))throw new Error("Invalid seeds, address must fall off the curve");return new M(n)}static async createProgramAddress(e,t){return this.createProgramAddressSync(e,t)}static findProgramAddressSync(e,t){let r=255,n;for(;r!=0;){try{let i=e.concat(D.from([r]));n=this.createProgramAddressSync(i,t)}catch(i){if(i instanceof TypeError)throw i;r--;continue}return[n,r]}throw new Error("Unable to find a viable program address nonce")}static async findProgramAddress(e,t){return this.findProgramAddressSync(e,t)}static isOnCurve(e){let t=new M(e);return Ts(t.toBytes())}};ui=M;M.default=new ui("11111111111111111111111111111111");Wr.set(M,{kind:"struct",fields:[["_bn","u256"]]});var Ns=class{constructor(e){if(this._publicKey=void 0,this._secretKey=void 0,e){let t=H(e);if(e.length!==64)throw new Error("bad secret key size");this._publicKey=t.slice(32,64),this._secretKey=t.slice(0,32)}else this._secretKey=H(Ui()),this._publicKey=H(qr(this._secretKey))}get publicKey(){return new M(this._publicKey)}get secretKey(){return D.concat([this._secretKey,this._publicKey],64)}},mc=new M("BPFLoader1111111111111111111111111111111111"),zt=1280-40-8,Zn=127,Dr=64,$r=class extends Error{constructor(e){super(`Signature ${e} has expired: block height exceeded.`),this.signature=void 0,this.signature=e}};Object.defineProperty($r.prototype,"name",{value:"TransactionExpiredBlockheightExceededError"});var Fr=class extends Error{constructor(e,t){super(`Transaction was not confirmed in ${t.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${e} using the Solana Explorer or CLI tools.`),this.signature=void 0,this.signature=e}};Object.defineProperty(Fr.prototype,"name",{value:"TransactionExpiredTimeoutError"});var Tt=class extends Error{constructor(e){super(`Signature ${e} has expired: the nonce is no longer valid.`),this.signature=void 0,this.signature=e}};Object.defineProperty(Tt.prototype,"name",{value:"TransactionExpiredNonceInvalidError"});var Vt=class{constructor(e,t){this.staticAccountKeys=void 0,this.accountKeysFromLookups=void 0,this.staticAccountKeys=e,this.accountKeysFromLookups=t}keySegments(){let e=[this.staticAccountKeys];return this.accountKeysFromLookups&&(e.push(this.accountKeysFromLookups.writable),e.push(this.accountKeysFromLookups.readonly)),e}get(e){for(let t of this.keySegments()){if(e<t.length)return t[e];e-=t.length}}get length(){return this.keySegments().flat().length}compileInstructions(e){if(this.length>255+1)throw new Error("Account index overflow encountered during compilation");let r=new Map;this.keySegments().flat().forEach((i,u)=>{r.set(i.toBase58(),u)});let n=i=>{let u=r.get(i.toBase58());if(u===void 0)throw new Error("Encountered an unknown instruction account key during compilation");return u};return e.map(i=>({programIdIndex:n(i.programId),accountKeyIndexes:i.keys.map(u=>n(u.pubkey)),data:i.data}))}},G=(a="publicKey")=>y.blob(32,a),Vi=(a="signature")=>y.blob(64,a),Ct=(a="string")=>{let e=y.struct([y.u32("length"),y.u32("lengthPadding"),y.blob(y.offset(y.u32(),-8),"chars")],a),t=e.decode.bind(e),r=e.encode.bind(e),n=e;return n.decode=(i,u)=>t(i,u).chars.toString(),n.encode=(i,u,l)=>{let m={chars:D.from(i,"utf8")};return r(m,u,l)},n.alloc=i=>y.u32().span+y.u32().span+D.from(i,"utf8").length,n},Hi=(a="authorized")=>y.struct([G("staker"),G("withdrawer")],a),Gi=(a="lockup")=>y.struct([y.ns64("unixTimestamp"),y.ns64("epoch"),G("custodian")],a),ji=(a="voteInit")=>y.struct([G("nodePubkey"),G("authorizedVoter"),G("authorizedWithdrawer"),y.u8("commission")],a),Ji=(a="voteAuthorizeWithSeedArgs")=>y.struct([y.u32("voteAuthorizationType"),G("currentAuthorityDerivedKeyOwnerPubkey"),Ct("currentAuthorityDerivedKeySeed"),G("newAuthorized")],a);function hi(a,e){let t=n=>{if(n.span>=0)return n.span;if(typeof n.alloc=="function")return n.alloc(e[n.property]);if("count"in n&&"elementLayout"in n){let i=e[n.property];if(Array.isArray(i))return i.length*t(n.elementLayout)}else if("fields"in n)return hi({layout:n},e[n.property]);return 0},r=0;return a.layout.fields.forEach(n=>{r+=t(n)}),r}function it(a){let e=0,t=0;for(;;){let r=a.shift();if(e|=(r&127)<<t*7,t+=1,(r&128)===0)break}return e}function ct(a,e){let t=e;for(;;){let r=t&127;if(t>>=7,t==0){a.push(r);break}else r|=128,a.push(r)}}function X(a,e){if(!a)throw new Error(e||"Assertion failed")}var Ht=class{constructor(e,t){this.payer=void 0,this.keyMetaMap=void 0,this.payer=e,this.keyMetaMap=t}static compile(e,t){let r=new Map,n=u=>{let l=u.toBase58(),m=r.get(l);return m===void 0&&(m={isSigner:!1,isWritable:!1,isInvoked:!1},r.set(l,m)),m},i=n(t);i.isSigner=!0,i.isWritable=!0;for(let u of e){n(u.programId).isInvoked=!0;for(let l of u.keys){let m=n(l.pubkey);m.isSigner||=l.isSigner,m.isWritable||=l.isWritable}}return new Ht(t,r)}getMessageComponents(){let e=[...this.keyMetaMap.entries()];X(e.length<=256,"Max static account keys length exceeded");let t=e.filter(([,m])=>m.isSigner&&m.isWritable),r=e.filter(([,m])=>m.isSigner&&!m.isWritable),n=e.filter(([,m])=>!m.isSigner&&m.isWritable),i=e.filter(([,m])=>!m.isSigner&&!m.isWritable),u={numRequiredSignatures:t.length+r.length,numReadonlySignedAccounts:r.length,numReadonlyUnsignedAccounts:i.length};{X(t.length>0,"Expected at least one writable signer key");let[m]=t[0];X(m===this.payer.toBase58(),"Expected first writable signer key to be the fee payer")}let l=[...t.map(([m])=>new M(m)),...r.map(([m])=>new M(m)),...n.map(([m])=>new M(m)),...i.map(([m])=>new M(m))];return[u,l]}extractTableLookup(e){let[t,r]=this.drainKeysFoundInLookupTable(e.state.addresses,u=>!u.isSigner&&!u.isInvoked&&u.isWritable),[n,i]=this.drainKeysFoundInLookupTable(e.state.addresses,u=>!u.isSigner&&!u.isInvoked&&!u.isWritable);if(!(t.length===0&&n.length===0))return[{accountKey:e.key,writableIndexes:t,readonlyIndexes:n},{writable:r,readonly:i}]}drainKeysFoundInLookupTable(e,t){let r=new Array,n=new Array;for(let[i,u]of this.keyMetaMap.entries())if(t(u)){let l=new M(i),m=e.findIndex(I=>I.equals(l));m>=0&&(X(m<256,"Max lookup table index exceeded"),r.push(m),n.push(l),this.keyMetaMap.delete(i))}return[r,n]}},li="Reached end of buffer unexpectedly";function pt(a){if(a.length===0)throw new Error(li);return a.shift()}function ot(a,...e){let[t]=e;if(e.length===2?t+(e[1]??0)>a.length:t>=a.length)throw new Error(li);return a.splice(...e)}var lt=class{constructor(e){this.header=void 0,this.accountKeys=void 0,this.recentBlockhash=void 0,this.instructions=void 0,this.indexToProgramIds=new Map,this.header=e.header,this.accountKeys=e.accountKeys.map(t=>new M(t)),this.recentBlockhash=e.recentBlockhash,this.instructions=e.instructions,this.instructions.forEach(t=>this.indexToProgramIds.set(t.programIdIndex,this.accountKeys[t.programIdIndex]))}get version(){return"legacy"}get staticAccountKeys(){return this.accountKeys}get compiledInstructions(){return this.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:Ze.default.decode(e.data)}))}get addressTableLookups(){return[]}getAccountKeys(){return new Vt(this.staticAccountKeys)}static compile(e){let t=Ht.compile(e.instructions,e.payerKey),[r,n]=t.getMessageComponents(),u=new Vt(n).compileInstructions(e.instructions).map(l=>({programIdIndex:l.programIdIndex,accounts:l.accountKeyIndexes,data:Ze.default.encode(l.data)}));return new lt({header:r,accountKeys:n,recentBlockhash:e.recentBlockhash,instructions:u})}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures;if(e>=this.header.numRequiredSignatures){let r=e-t,i=this.accountKeys.length-t-this.header.numReadonlyUnsignedAccounts;return r<i}else{let r=t-this.header.numReadonlySignedAccounts;return e<r}}isProgramId(e){return this.indexToProgramIds.has(e)}programIds(){return[...this.indexToProgramIds.values()]}nonProgramIds(){return this.accountKeys.filter((e,t)=>!this.isProgramId(t))}serialize(){let e=this.accountKeys.length,t=[];ct(t,e);let r=this.instructions.map(x=>{let{accounts:N,programIdIndex:_}=x,R=Array.from(Ze.default.decode(x.data)),L=[];ct(L,N.length);let z=[];return ct(z,R.length),{programIdIndex:_,keyIndicesCount:D.from(L),keyIndices:N,dataLength:D.from(z),data:R}}),n=[];ct(n,r.length);let i=D.alloc(zt);D.from(n).copy(i);let u=n.length;r.forEach(x=>{let _=y.struct([y.u8("programIdIndex"),y.blob(x.keyIndicesCount.length,"keyIndicesCount"),y.seq(y.u8("keyIndex"),x.keyIndices.length,"keyIndices"),y.blob(x.dataLength.length,"dataLength"),y.seq(y.u8("userdatum"),x.data.length,"data")]).encode(x,i,u);u+=_}),i=i.slice(0,u);let l=y.struct([y.blob(1,"numRequiredSignatures"),y.blob(1,"numReadonlySignedAccounts"),y.blob(1,"numReadonlyUnsignedAccounts"),y.blob(t.length,"keyCount"),y.seq(G("key"),e,"keys"),G("recentBlockhash")]),m={numRequiredSignatures:D.from([this.header.numRequiredSignatures]),numReadonlySignedAccounts:D.from([this.header.numReadonlySignedAccounts]),numReadonlyUnsignedAccounts:D.from([this.header.numReadonlyUnsignedAccounts]),keyCount:D.from(t),keys:this.accountKeys.map(x=>H(x.toBytes())),recentBlockhash:Ze.default.decode(this.recentBlockhash)},I=D.alloc(2048),B=l.encode(m,I);return i.copy(I,B),I.slice(0,B+i.length)}static from(e){let t=[...e],r=pt(t);if(r!==(r&Zn))throw new Error("Versioned messages must be deserialized with VersionedMessage.deserialize()");let n=pt(t),i=pt(t),u=it(t),l=[];for(let N=0;N<u;N++){let _=ot(t,0,wt);l.push(new M(D.from(_)))}let m=ot(t,0,wt),I=it(t),B=[];for(let N=0;N<I;N++){let _=pt(t),R=it(t),L=ot(t,0,R),z=it(t),W=ot(t,0,z),J=Ze.default.encode(D.from(W));B.push({programIdIndex:_,accounts:L,data:J})}let x={header:{numRequiredSignatures:r,numReadonlySignedAccounts:n,numReadonlyUnsignedAccounts:i},recentBlockhash:Ze.default.encode(D.from(m)),accountKeys:l,instructions:B};return new lt(x)}},_t=class{constructor(e){this.header=void 0,this.staticAccountKeys=void 0,this.recentBlockhash=void 0,this.compiledInstructions=void 0,this.addressTableLookups=void 0,this.header=e.header,this.staticAccountKeys=e.staticAccountKeys,this.recentBlockhash=e.recentBlockhash,this.compiledInstructions=e.compiledInstructions,this.addressTableLookups=e.addressTableLookups}get version(){return 0}get numAccountKeysFromLookups(){let e=0;for(let t of this.addressTableLookups)e+=t.readonlyIndexes.length+t.writableIndexes.length;return e}getAccountKeys(e){let t;if(e&&"accountKeysFromLookups"in e&&e.accountKeysFromLookups){if(this.numAccountKeysFromLookups!=e.accountKeysFromLookups.writable.length+e.accountKeysFromLookups.readonly.length)throw new Error("Failed to get account keys because of a mismatch in the number of account keys from lookups");t=e.accountKeysFromLookups}else if(e&&"addressLookupTableAccounts"in e&&e.addressLookupTableAccounts)t=this.resolveAddressTableLookups(e.addressLookupTableAccounts);else if(this.addressTableLookups.length>0)throw new Error("Failed to get account keys because address table lookups were not resolved");return new Vt(this.staticAccountKeys,t)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures,r=this.staticAccountKeys.length;if(e>=r){let n=e-r,i=this.addressTableLookups.reduce((u,l)=>u+l.writableIndexes.length,0);return n<i}else if(e>=this.header.numRequiredSignatures){let n=e-t,u=r-t-this.header.numReadonlyUnsignedAccounts;return n<u}else{let n=t-this.header.numReadonlySignedAccounts;return e<n}}resolveAddressTableLookups(e){let t={writable:[],readonly:[]};for(let r of this.addressTableLookups){let n=e.find(i=>i.key.equals(r.accountKey));if(!n)throw new Error(`Failed to find address lookup table account for table key ${r.accountKey.toBase58()}`);for(let i of r.writableIndexes)if(i<n.state.addresses.length)t.writable.push(n.state.addresses[i]);else throw new Error(`Failed to find address for index ${i} in address lookup table ${r.accountKey.toBase58()}`);for(let i of r.readonlyIndexes)if(i<n.state.addresses.length)t.readonly.push(n.state.addresses[i]);else throw new Error(`Failed to find address for index ${i} in address lookup table ${r.accountKey.toBase58()}`)}return t}static compile(e){let t=Ht.compile(e.instructions,e.payerKey),r=new Array,n={writable:new Array,readonly:new Array},i=e.addressLookupTableAccounts||[];for(let B of i){let x=t.extractTableLookup(B);if(x!==void 0){let[N,{writable:_,readonly:R}]=x;r.push(N),n.writable.push(..._),n.readonly.push(...R)}}let[u,l]=t.getMessageComponents(),I=new Vt(l,n).compileInstructions(e.instructions);return new _t({header:u,staticAccountKeys:l,recentBlockhash:e.recentBlockhash,compiledInstructions:I,addressTableLookups:r})}serialize(){let e=Array();ct(e,this.staticAccountKeys.length);let t=this.serializeInstructions(),r=Array();ct(r,this.compiledInstructions.length);let n=this.serializeAddressTableLookups(),i=Array();ct(i,this.addressTableLookups.length);let u=y.struct([y.u8("prefix"),y.struct([y.u8("numRequiredSignatures"),y.u8("numReadonlySignedAccounts"),y.u8("numReadonlyUnsignedAccounts")],"header"),y.blob(e.length,"staticAccountKeysLength"),y.seq(G(),this.staticAccountKeys.length,"staticAccountKeys"),G("recentBlockhash"),y.blob(r.length,"instructionsLength"),y.blob(t.length,"serializedInstructions"),y.blob(i.length,"addressTableLookupsLength"),y.blob(n.length,"serializedAddressTableLookups")]),l=new Uint8Array(zt),m=1<<7,I=u.encode({prefix:m,header:this.header,staticAccountKeysLength:new Uint8Array(e),staticAccountKeys:this.staticAccountKeys.map(B=>B.toBytes()),recentBlockhash:Ze.default.decode(this.recentBlockhash),instructionsLength:new Uint8Array(r),serializedInstructions:t,addressTableLookupsLength:new Uint8Array(i),serializedAddressTableLookups:n},l);return l.slice(0,I)}serializeInstructions(){let e=0,t=new Uint8Array(zt);for(let r of this.compiledInstructions){let n=Array();ct(n,r.accountKeyIndexes.length);let i=Array();ct(i,r.data.length);let u=y.struct([y.u8("programIdIndex"),y.blob(n.length,"encodedAccountKeyIndexesLength"),y.seq(y.u8(),r.accountKeyIndexes.length,"accountKeyIndexes"),y.blob(i.length,"encodedDataLength"),y.blob(r.data.length,"data")]);e+=u.encode({programIdIndex:r.programIdIndex,encodedAccountKeyIndexesLength:new Uint8Array(n),accountKeyIndexes:r.accountKeyIndexes,encodedDataLength:new Uint8Array(i),data:r.data},t,e)}return t.slice(0,e)}serializeAddressTableLookups(){let e=0,t=new Uint8Array(zt);for(let r of this.addressTableLookups){let n=Array();ct(n,r.writableIndexes.length);let i=Array();ct(i,r.readonlyIndexes.length);let u=y.struct([G("accountKey"),y.blob(n.length,"encodedWritableIndexesLength"),y.seq(y.u8(),r.writableIndexes.length,"writableIndexes"),y.blob(i.length,"encodedReadonlyIndexesLength"),y.seq(y.u8(),r.readonlyIndexes.length,"readonlyIndexes")]);e+=u.encode({accountKey:r.accountKey.toBytes(),encodedWritableIndexesLength:new Uint8Array(n),writableIndexes:r.writableIndexes,encodedReadonlyIndexesLength:new Uint8Array(i),readonlyIndexes:r.readonlyIndexes},t,e)}return t.slice(0,e)}static deserialize(e){let t=[...e],r=pt(t),n=r&Zn;X(r!==n,"Expected versioned message but received legacy message");let i=n;X(i===0,`Expected versioned message with version 0 but found version ${i}`);let u={numRequiredSignatures:pt(t),numReadonlySignedAccounts:pt(t),numReadonlyUnsignedAccounts:pt(t)},l=[],m=it(t);for(let R=0;R<m;R++)l.push(new M(ot(t,0,wt)));let I=Ze.default.encode(ot(t,0,wt)),B=it(t),x=[];for(let R=0;R<B;R++){let L=pt(t),z=it(t),W=ot(t,0,z),J=it(t),le=new Uint8Array(ot(t,0,J));x.push({programIdIndex:L,accountKeyIndexes:W,data:le})}let N=it(t),_=[];for(let R=0;R<N;R++){let L=new M(ot(t,0,wt)),z=it(t),W=ot(t,0,z),J=it(t),le=ot(t,0,J);_.push({accountKey:L,writableIndexes:W,readonlyIndexes:le})}return new _t({header:u,staticAccountKeys:l,recentBlockhash:I,compiledInstructions:x,addressTableLookups:_})}},fi={deserializeMessageVersion(a){let e=a[0],t=e&Zn;return t===e?"legacy":t},deserialize:a=>{let e=fi.deserializeMessageVersion(a);if(e==="legacy")return lt.from(a);if(e===0)return _t.deserialize(a);throw new Error(`Transaction message version ${e} deserialization is not supported`)}},St=function(a){return a[a.BLOCKHEIGHT_EXCEEDED=0]="BLOCKHEIGHT_EXCEEDED",a[a.PROCESSED=1]="PROCESSED",a[a.TIMED_OUT=2]="TIMED_OUT",a[a.NONCE_INVALID=3]="NONCE_INVALID",a}({}),Yi=D.alloc(Dr).fill(0),ne=class{constructor(e){this.keys=void 0,this.programId=void 0,this.data=D.alloc(0),this.programId=e.programId,this.keys=e.keys,e.data&&(this.data=e.data)}toJSON(){return{keys:this.keys.map(({pubkey:e,isSigner:t,isWritable:r})=>({pubkey:e.toJSON(),isSigner:t,isWritable:r})),programId:this.programId.toJSON(),data:[...this.data]}}},Z=class{get signature(){return this.signatures.length>0?this.signatures[0].signature:null}constructor(e){if(this.signatures=[],this.feePayer=void 0,this.instructions=[],this.recentBlockhash=void 0,this.lastValidBlockHeight=void 0,this.nonceInfo=void 0,this.minNonceContextSlot=void 0,this._message=void 0,this._json=void 0,!!e)if(e.feePayer&&(this.feePayer=e.feePayer),e.signatures&&(this.signatures=e.signatures),Object.prototype.hasOwnProperty.call(e,"nonceInfo")){let{minContextSlot:t,nonceInfo:r}=e;this.minNonceContextSlot=t,this.nonceInfo=r}else if(Object.prototype.hasOwnProperty.call(e,"lastValidBlockHeight")){let{blockhash:t,lastValidBlockHeight:r}=e;this.recentBlockhash=t,this.lastValidBlockHeight=r}else{let{recentBlockhash:t,nonceInfo:r}=e;r&&(this.nonceInfo=r),this.recentBlockhash=t}}toJSON(){return{recentBlockhash:this.recentBlockhash||null,feePayer:this.feePayer?this.feePayer.toJSON():null,nonceInfo:this.nonceInfo?{nonce:this.nonceInfo.nonce,nonceInstruction:this.nonceInfo.nonceInstruction.toJSON()}:null,instructions:this.instructions.map(e=>e.toJSON()),signers:this.signatures.map(({publicKey:e})=>e.toJSON())}}add(...e){if(e.length===0)throw new Error("No instructions");return e.forEach(t=>{"instructions"in t?this.instructions=this.instructions.concat(t.instructions):"data"in t&&"programId"in t&&"keys"in t?this.instructions.push(t):this.instructions.push(new ne(t))}),this}compileMessage(){if(this._message&&JSON.stringify(this.toJSON())===JSON.stringify(this._json))return this._message;let e,t;if(this.nonceInfo?(e=this.nonceInfo.nonce,this.instructions[0]!=this.nonceInfo.nonceInstruction?t=[this.nonceInfo.nonceInstruction,...this.instructions]:t=this.instructions):(e=this.recentBlockhash,t=this.instructions),!e)throw new Error("Transaction recentBlockhash required");t.length<1&&console.warn("No instructions provided");let r;if(this.feePayer)r=this.feePayer;else if(this.signatures.length>0&&this.signatures[0].publicKey)r=this.signatures[0].publicKey;else throw new Error("Transaction fee payer required");for(let L=0;L<t.length;L++)if(t[L].programId===void 0)throw new Error(`Transaction instruction index ${L} has undefined program id`);let n=[],i=[];t.forEach(L=>{L.keys.forEach(W=>{i.push({...W})});let z=L.programId.toString();n.includes(z)||n.push(z)}),n.forEach(L=>{i.push({pubkey:new M(L),isSigner:!1,isWritable:!1})});let u=[];i.forEach(L=>{let z=L.pubkey.toString(),W=u.findIndex(J=>J.pubkey.toString()===z);W>-1?(u[W].isWritable=u[W].isWritable||L.isWritable,u[W].isSigner=u[W].isSigner||L.isSigner):u.push(L)}),u.sort(function(L,z){if(L.isSigner!==z.isSigner)return L.isSigner?-1:1;if(L.isWritable!==z.isWritable)return L.isWritable?-1:1;let W={localeMatcher:"best fit",usage:"sort",sensitivity:"variant",ignorePunctuation:!1,numeric:!1,caseFirst:"lower"};return L.pubkey.toBase58().localeCompare(z.pubkey.toBase58(),"en",W)});let l=u.findIndex(L=>L.pubkey.equals(r));if(l>-1){let[L]=u.splice(l,1);L.isSigner=!0,L.isWritable=!0,u.unshift(L)}else u.unshift({pubkey:r,isSigner:!0,isWritable:!0});for(let L of this.signatures){let z=u.findIndex(W=>W.pubkey.equals(L.publicKey));if(z>-1)u[z].isSigner||(u[z].isSigner=!0,console.warn("Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts should sign a transaction. This behavior is deprecated and will throw an error in the next major version release."));else throw new Error(`unknown signer: ${L.publicKey.toString()}`)}let m=0,I=0,B=0,x=[],N=[];u.forEach(({pubkey:L,isSigner:z,isWritable:W})=>{z?(x.push(L.toString()),m+=1,W||(I+=1)):(N.push(L.toString()),W||(B+=1))});let _=x.concat(N),R=t.map(L=>{let{data:z,programId:W}=L;return{programIdIndex:_.indexOf(W.toString()),accounts:L.keys.map(J=>_.indexOf(J.pubkey.toString())),data:Ze.default.encode(z)}});return R.forEach(L=>{X(L.programIdIndex>=0),L.accounts.forEach(z=>X(z>=0))}),new lt({header:{numRequiredSignatures:m,numReadonlySignedAccounts:I,numReadonlyUnsignedAccounts:B},accountKeys:_,recentBlockhash:e,instructions:R})}_compile(){let e=this.compileMessage(),t=e.accountKeys.slice(0,e.header.numRequiredSignatures);return this.signatures.length===t.length&&this.signatures.every((n,i)=>t[i].equals(n.publicKey))||(this.signatures=t.map(r=>({signature:null,publicKey:r}))),e}serializeMessage(){return this._compile().serialize()}async getEstimatedFee(e){return(await e.getFeeForMessage(this.compileMessage())).value}setSigners(...e){if(e.length===0)throw new Error("No signers");let t=new Set;this.signatures=e.filter(r=>{let n=r.toString();return t.has(n)?!1:(t.add(n),!0)}).map(r=>({signature:null,publicKey:r}))}sign(...e){if(e.length===0)throw new Error("No signers");let t=new Set,r=[];for(let i of e){let u=i.publicKey.toString();t.has(u)||(t.add(u),r.push(i))}this.signatures=r.map(i=>({signature:null,publicKey:i.publicKey}));let n=this._compile();this._partialSign(n,...r)}partialSign(...e){if(e.length===0)throw new Error("No signers");let t=new Set,r=[];for(let i of e){let u=i.publicKey.toString();t.has(u)||(t.add(u),r.push(i))}let n=this._compile();this._partialSign(n,...r)}_partialSign(e,...t){let r=e.serialize();t.forEach(n=>{let i=Yn(r,n.secretKey);this._addSignature(n.publicKey,H(i))})}addSignature(e,t){this._compile(),this._addSignature(e,t)}_addSignature(e,t){X(t.length===64);let r=this.signatures.findIndex(n=>e.equals(n.publicKey));if(r<0)throw new Error(`unknown signer: ${e.toString()}`);this.signatures[r].signature=D.from(t)}verifySignatures(e=!0){return!this._getMessageSignednessErrors(this.serializeMessage(),e)}_getMessageSignednessErrors(e,t){let r={};for(let{signature:n,publicKey:i}of this.signatures)n===null?t&&(r.missing||=[]).push(i):Di(n,e,i.toBytes())||(r.invalid||=[]).push(i);return r.invalid||r.missing?r:void 0}serialize(e){let{requireAllSignatures:t,verifySignatures:r}=Object.assign({requireAllSignatures:!0,verifySignatures:!0},e),n=this.serializeMessage();if(r){let i=this._getMessageSignednessErrors(n,t);if(i){let u="Signature verification failed.";throw i.invalid&&(u+=`
|
|
Invalid signature for public key${i.invalid.length===1?"":"(s)"} [\`${i.invalid.map(l=>l.toBase58()).join("`, `")}\`].`),i.missing&&(u+=`
|
|
Missing signature for public key${i.missing.length===1?"":"(s)"} [\`${i.missing.map(l=>l.toBase58()).join("`, `")}\`].`),new Error(u)}}return this._serialize(n)}_serialize(e){let{signatures:t}=this,r=[];ct(r,t.length);let n=r.length+t.length*64+e.length,i=D.alloc(n);return X(t.length<256),D.from(r).copy(i,0),t.forEach(({signature:u},l)=>{u!==null&&(X(u.length===64,"signature has invalid length"),D.from(u).copy(i,r.length+l*64))}),e.copy(i,r.length+t.length*64),X(i.length<=zt,`Transaction too large: ${i.length} > ${zt}`),i}get keys(){return X(this.instructions.length===1),this.instructions[0].keys.map(e=>e.pubkey)}get programId(){return X(this.instructions.length===1),this.instructions[0].programId}get data(){return X(this.instructions.length===1),this.instructions[0].data}static from(e){let t=[...e],r=it(t),n=[];for(let i=0;i<r;i++){let u=ot(t,0,Dr);n.push(Ze.default.encode(D.from(u)))}return Z.populate(lt.from(t),n)}static populate(e,t=[]){let r=new Z;return r.recentBlockhash=e.recentBlockhash,e.header.numRequiredSignatures>0&&(r.feePayer=e.accountKeys[0]),t.forEach((n,i)=>{let u={signature:n==Ze.default.encode(Yi)?null:Ze.default.decode(n),publicKey:e.accountKeys[i]};r.signatures.push(u)}),e.instructions.forEach(n=>{let i=n.accounts.map(u=>{let l=e.accountKeys[u];return{pubkey:l,isSigner:r.signatures.some(m=>m.publicKey.toString()===l.toString())||e.isAccountSigner(u),isWritable:e.isAccountWritable(u)}});r.instructions.push(new ne({keys:i,programId:e.accountKeys[n.programIdIndex],data:Ze.default.decode(n.data)}))}),r._message=e,r._json=r.toJSON(),r}},Vr=class{constructor(e){this.payerKey=void 0,this.instructions=void 0,this.recentBlockhash=void 0,this.payerKey=e.payerKey,this.instructions=e.instructions,this.recentBlockhash=e.recentBlockhash}static decompile(e,t){let{header:r,compiledInstructions:n,recentBlockhash:i}=e,{numRequiredSignatures:u,numReadonlySignedAccounts:l,numReadonlyUnsignedAccounts:m}=r,I=u-l;X(I>0,"Message header is invalid");let B=e.staticAccountKeys.length-u-m;X(B>=0,"Message header is invalid");let x=e.getAccountKeys(t),N=x.get(0);if(N===void 0)throw new Error("Failed to decompile message because no account keys were found");let _=[];for(let R of n){let L=[];for(let W of R.accountKeyIndexes){let J=x.get(W);if(J===void 0)throw new Error(`Failed to find key for account key index ${W}`);let le=W<u,ee;le?ee=W<I:W<x.staticAccountKeys.length?ee=W-u<B:ee=W-x.staticAccountKeys.length<x.accountKeysFromLookups.writable.length,L.push({pubkey:J,isSigner:W<r.numRequiredSignatures,isWritable:ee})}let z=x.get(R.programIdIndex);if(z===void 0)throw new Error(`Failed to find program id for program id index ${R.programIdIndex}`);_.push(new ne({programId:z,data:H(R.data),keys:L}))}return new Vr({payerKey:N,instructions:_,recentBlockhash:i})}compileToLegacyMessage(){return lt.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions})}compileToV0Message(e){return _t.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions,addressLookupTableAccounts:e})}},Hr=class{get version(){return this.message.version}constructor(e,t){if(this.signatures=void 0,this.message=void 0,t!==void 0)X(t.length===e.header.numRequiredSignatures,"Expected signatures length to be equal to the number of required signatures"),this.signatures=t;else{let r=[];for(let n=0;n<e.header.numRequiredSignatures;n++)r.push(new Uint8Array(Dr));this.signatures=r}this.message=e}serialize(){let e=this.message.serialize(),t=Array();ct(t,this.signatures.length);let r=y.struct([y.blob(t.length,"encodedSignaturesLength"),y.seq(Vi(),this.signatures.length,"signatures"),y.blob(e.length,"serializedMessage")]),n=new Uint8Array(2048),i=r.encode({encodedSignaturesLength:new Uint8Array(t),signatures:this.signatures,serializedMessage:e},n);return n.slice(0,i)}static deserialize(e){let t=[...e],r=[],n=it(t);for(let u=0;u<n;u++)r.push(new Uint8Array(ot(t,0,Dr)));let i=fi.deserialize(new Uint8Array(t));return new Hr(i,r)}sign(e){let t=this.message.serialize(),r=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures);for(let n of e){let i=r.findIndex(u=>u.equals(n.publicKey));X(i>=0,`Cannot sign with non signer key ${n.publicKey.toBase58()}`),this.signatures[i]=Yn(t,n.secretKey)}}addSignature(e,t){X(t.byteLength===64,"Signature must be 64 bytes long");let n=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures).findIndex(i=>i.equals(e));X(n>=0,`Can not add signature; \`${e.toBase58()}\` is not required to sign this transaction`),this.signatures[n]=t}},Zi=160,Xi=64,Qi=Zi/Xi,di=1e3/Qi,mt=new M("SysvarC1ock11111111111111111111111111111111"),bc=new M("SysvarEpochSchedu1e111111111111111111111111"),wc=new M("Sysvar1nstructions1111111111111111111111111"),Cn=new M("SysvarRecentB1ockHashes11111111111111111111"),or=new M("SysvarRent111111111111111111111111111111111"),kc=new M("SysvarRewards111111111111111111111111111111"),vc=new M("SysvarS1otHashes111111111111111111111111111"),Sc=new M("SysvarS1otHistory11111111111111111111111111"),zn=new M("SysvarStakeHistory1111111111111111111111111"),Gt=class extends Error{constructor({action:e,signature:t,transactionMessage:r,logs:n}){let i=n?`Logs:
|
|
${JSON.stringify(n.slice(-10),null,2)}. `:"",u="\nCatch the `SendTransactionError` and call `getLogs()` on it for full details.",l;switch(e){case"send":l=`Transaction ${t} resulted in an error.
|
|
${r}. `+i+u;break;case"simulate":l=`Simulation failed.
|
|
Message: ${r}.
|
|
`+i+u;break;default:l=`Unknown action '${(m=>m)(e)}'`}super(l),this.signature=void 0,this.transactionMessage=void 0,this.transactionLogs=void 0,this.signature=t,this.transactionMessage=r,this.transactionLogs=n||void 0}get transactionError(){return{message:this.transactionMessage,logs:Array.isArray(this.transactionLogs)?this.transactionLogs:void 0}}get logs(){let e=this.transactionLogs;if(!(e!=null&&typeof e=="object"&&"then"in e))return e}async getLogs(e){return Array.isArray(this.transactionLogs)||(this.transactionLogs=new Promise((t,r)=>{e.getTransaction(this.signature).then(n=>{if(n&&n.meta&&n.meta.logMessages){let i=n.meta.logMessages;this.transactionLogs=i,t(i)}else r(new Error("Log messages not found"))}).catch(r)})),await this.transactionLogs}},Ic={JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP:-32001,JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE:-32002,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE:-32003,JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE:-32004,JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY:-32005,JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE:-32006,JSON_RPC_SERVER_ERROR_SLOT_SKIPPED:-32007,JSON_RPC_SERVER_ERROR_NO_SNAPSHOT:-32008,JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED:-32009,JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX:-32010,JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE:-32011,JSON_RPC_SCAN_ERROR:-32012,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH:-32013,JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET:-32014,JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION:-32015,JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED:-32016},O=class extends Error{constructor({code:e,message:t,data:r},n){super(n!=null?`${n}: ${t}`:t),this.code=void 0,this.data=void 0,this.code=e,this.data=r,this.name="SolanaJSONRPCError"}};async function Os(a,e,t,r){let n=r&&{skipPreflight:r.skipPreflight,preflightCommitment:r.preflightCommitment||r.commitment,maxRetries:r.maxRetries,minContextSlot:r.minContextSlot},i=await a.sendTransaction(e,t,n),u;if(e.recentBlockhash!=null&&e.lastValidBlockHeight!=null)u=(await a.confirmTransaction({abortSignal:r?.abortSignal,signature:i,blockhash:e.recentBlockhash,lastValidBlockHeight:e.lastValidBlockHeight},r&&r.commitment)).value;else if(e.minNonceContextSlot!=null&&e.nonceInfo!=null){let{nonceInstruction:l}=e.nonceInfo,m=l.keys[0].pubkey;u=(await a.confirmTransaction({abortSignal:r?.abortSignal,minContextSlot:e.minNonceContextSlot,nonceAccountPubkey:m,nonceValue:e.nonceInfo.nonce,signature:i},r&&r.commitment)).value}else r?.abortSignal!=null&&console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable."),u=(await a.confirmTransaction(i,r&&r.commitment)).value;if(u.err)throw i!=null?new Gt({action:"send",signature:i,transactionMessage:`Status: (${JSON.stringify(u)})`}):new Error(`Transaction ${i} failed (${JSON.stringify(u)})`);return i}function Pt(a){return new Promise(e=>setTimeout(e,a))}function j(a,e){let t=a.layout.span>=0?a.layout.span:hi(a,e),r=D.alloc(t),n=Object.assign({instruction:a.index},e);return a.layout.encode(n,r),r}function re(a,e){let t;try{t=a.layout.decode(e)}catch(r){throw new Error("invalid instruction; "+r)}if(t.instruction!==a.index)throw new Error(`invalid instruction; instruction index mismatch ${t.instruction} != ${a.index}`);return t}var eo=y.nu64("lamportsPerSignature"),pi=y.struct([y.u32("version"),y.u32("state"),G("authorizedPubkey"),G("nonce"),y.struct([eo],"feeCalculator")]),Ks=pi.span,ar=class{constructor(e){this.authorizedPubkey=void 0,this.nonce=void 0,this.feeCalculator=void 0,this.authorizedPubkey=e.authorizedPubkey,this.nonce=e.nonce,this.feeCalculator=e.feeCalculator}static fromAccountData(e){let t=pi.decode(H(e),0);return new ar({authorizedPubkey:new M(t.authorizedPubkey),nonce:new M(t.nonce).toString(),feeCalculator:t.feeCalculator})}},to=a=>{let e=a.decode.bind(a),t=a.encode.bind(a);return{decode:e,encode:t}},ro=a=>e=>{let t=(0,ai.blob)(a,e),{encode:r,decode:n}=to(t),i=t;return i.decode=(u,l)=>{let m=n(u,l);return(0,lr.toBigIntLE)(D.from(m))},i.encode=(u,l,m)=>{let I=(0,lr.toBufferLE)(u,a);return r(I,l,m)},i},jt=ro(8),Ws=class{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);let r=y.u32("instruction").decode(e.data),n;for(let[i,u]of Object.entries(ae))if(u.index==r){n=i;break}if(!n)throw new Error("Instruction type incorrect; not a SystemInstruction");return n}static decodeCreateAccount(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{lamports:t,space:r,programId:n}=re(ae.Create,e.data);return{fromPubkey:e.keys[0].pubkey,newAccountPubkey:e.keys[1].pubkey,lamports:t,space:r,programId:new M(n)}}static decodeTransfer(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{lamports:t}=re(ae.Transfer,e.data);return{fromPubkey:e.keys[0].pubkey,toPubkey:e.keys[1].pubkey,lamports:t}}static decodeTransferWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{lamports:t,seed:r,programId:n}=re(ae.TransferWithSeed,e.data);return{fromPubkey:e.keys[0].pubkey,basePubkey:e.keys[1].pubkey,toPubkey:e.keys[2].pubkey,lamports:t,seed:r,programId:new M(n)}}static decodeAllocate(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);let{space:t}=re(ae.Allocate,e.data);return{accountPubkey:e.keys[0].pubkey,space:t}}static decodeAllocateWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);let{base:t,seed:r,space:n,programId:i}=re(ae.AllocateWithSeed,e.data);return{accountPubkey:e.keys[0].pubkey,basePubkey:new M(t),seed:r,space:n,programId:new M(i)}}static decodeAssign(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);let{programId:t}=re(ae.Assign,e.data);return{accountPubkey:e.keys[0].pubkey,programId:new M(t)}}static decodeAssignWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);let{base:t,seed:r,programId:n}=re(ae.AssignWithSeed,e.data);return{accountPubkey:e.keys[0].pubkey,basePubkey:new M(t),seed:r,programId:new M(n)}}static decodeCreateWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{base:t,seed:r,lamports:n,space:i,programId:u}=re(ae.CreateWithSeed,e.data);return{fromPubkey:e.keys[0].pubkey,newAccountPubkey:e.keys[1].pubkey,basePubkey:new M(t),seed:r,lamports:n,space:i,programId:new M(u)}}static decodeNonceInitialize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{authorized:t}=re(ae.InitializeNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,authorizedPubkey:new M(t)}}static decodeNonceAdvance(e){return this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3),re(ae.AdvanceNonceAccount,e.data),{noncePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[2].pubkey}}static decodeNonceWithdraw(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,5);let{lamports:t}=re(ae.WithdrawNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,toPubkey:e.keys[1].pubkey,authorizedPubkey:e.keys[4].pubkey,lamports:t}}static decodeNonceAuthorize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{authorized:t}=re(ae.AuthorizeNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[1].pubkey,newAuthorizedPubkey:new M(t)}}static checkProgramId(e){if(!e.equals(Je.programId))throw new Error("invalid instruction; programId is not SystemProgram")}static checkKeyLength(e,t){if(e.length<t)throw new Error(`invalid instruction; found ${e.length} keys, expected at least ${t}`)}},ae=Object.freeze({Create:{index:0,layout:y.struct([y.u32("instruction"),y.ns64("lamports"),y.ns64("space"),G("programId")])},Assign:{index:1,layout:y.struct([y.u32("instruction"),G("programId")])},Transfer:{index:2,layout:y.struct([y.u32("instruction"),jt("lamports")])},CreateWithSeed:{index:3,layout:y.struct([y.u32("instruction"),G("base"),Ct("seed"),y.ns64("lamports"),y.ns64("space"),G("programId")])},AdvanceNonceAccount:{index:4,layout:y.struct([y.u32("instruction")])},WithdrawNonceAccount:{index:5,layout:y.struct([y.u32("instruction"),y.ns64("lamports")])},InitializeNonceAccount:{index:6,layout:y.struct([y.u32("instruction"),G("authorized")])},AuthorizeNonceAccount:{index:7,layout:y.struct([y.u32("instruction"),G("authorized")])},Allocate:{index:8,layout:y.struct([y.u32("instruction"),y.ns64("space")])},AllocateWithSeed:{index:9,layout:y.struct([y.u32("instruction"),G("base"),Ct("seed"),y.ns64("space"),G("programId")])},AssignWithSeed:{index:10,layout:y.struct([y.u32("instruction"),G("base"),Ct("seed"),G("programId")])},TransferWithSeed:{index:11,layout:y.struct([y.u32("instruction"),jt("lamports"),Ct("seed"),G("programId")])},UpgradeNonceAccount:{index:12,layout:y.struct([y.u32("instruction")])}}),Je=class{constructor(){}static createAccount(e){let t=ae.Create,r=j(t,{lamports:e.lamports,space:e.space,programId:H(e.programId.toBuffer())});return new ne({keys:[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!0,isWritable:!0}],programId:this.programId,data:r})}static transfer(e){let t,r;if("basePubkey"in e){let n=ae.TransferWithSeed;t=j(n,{lamports:BigInt(e.lamports),seed:e.seed,programId:H(e.programId.toBuffer())}),r=[{pubkey:e.fromPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}else{let n=ae.Transfer;t=j(n,{lamports:BigInt(e.lamports)}),r=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}return new ne({keys:r,programId:this.programId,data:t})}static assign(e){let t,r;if("basePubkey"in e){let n=ae.AssignWithSeed;t=j(n,{base:H(e.basePubkey.toBuffer()),seed:e.seed,programId:H(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let n=ae.Assign;t=j(n,{programId:H(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new ne({keys:r,programId:this.programId,data:t})}static createAccountWithSeed(e){let t=ae.CreateWithSeed,r=j(t,{base:H(e.basePubkey.toBuffer()),seed:e.seed,lamports:e.lamports,space:e.space,programId:H(e.programId.toBuffer())}),n=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!1,isWritable:!0}];return e.basePubkey.equals(e.fromPubkey)||n.push({pubkey:e.basePubkey,isSigner:!0,isWritable:!1}),new ne({keys:n,programId:this.programId,data:r})}static createNonceAccount(e){let t=new Z;"basePubkey"in e&&"seed"in e?t.add(Je.createAccountWithSeed({fromPubkey:e.fromPubkey,newAccountPubkey:e.noncePubkey,basePubkey:e.basePubkey,seed:e.seed,lamports:e.lamports,space:Ks,programId:this.programId})):t.add(Je.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.noncePubkey,lamports:e.lamports,space:Ks,programId:this.programId}));let r={noncePubkey:e.noncePubkey,authorizedPubkey:e.authorizedPubkey};return t.add(this.nonceInitialize(r)),t}static nonceInitialize(e){let t=ae.InitializeNonceAccount,r=j(t,{authorized:H(e.authorizedPubkey.toBuffer())}),n={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:Cn,isSigner:!1,isWritable:!1},{pubkey:or,isSigner:!1,isWritable:!1}],programId:this.programId,data:r};return new ne(n)}static nonceAdvance(e){let t=ae.AdvanceNonceAccount,r=j(t),n={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:Cn,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:r};return new ne(n)}static nonceWithdraw(e){let t=ae.WithdrawNonceAccount,r=j(t,{lamports:e.lamports});return new ne({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0},{pubkey:Cn,isSigner:!1,isWritable:!1},{pubkey:or,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:r})}static nonceAuthorize(e){let t=ae.AuthorizeNonceAccount,r=j(t,{authorized:H(e.newAuthorizedPubkey.toBuffer())});return new ne({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:r})}static allocate(e){let t,r;if("basePubkey"in e){let n=ae.AllocateWithSeed;t=j(n,{base:H(e.basePubkey.toBuffer()),seed:e.seed,space:e.space,programId:H(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let n=ae.Allocate;t=j(n,{space:e.space}),r=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new ne({keys:r,programId:this.programId,data:t})}};Je.programId=new M("11111111111111111111111111111111");var no=zt-300,At=class{constructor(){}static getMinNumSignatures(e){return 2*(Math.ceil(e/At.chunkSize)+1+1)}static async load(e,t,r,n,i){{let x=await e.getMinimumBalanceForRentExemption(i.length),N=await e.getAccountInfo(r.publicKey,"confirmed"),_=null;if(N!==null){if(N.executable)return console.error("Program load failed, account is already executable"),!1;N.data.length!==i.length&&(_=_||new Z,_.add(Je.allocate({accountPubkey:r.publicKey,space:i.length}))),N.owner.equals(n)||(_=_||new Z,_.add(Je.assign({accountPubkey:r.publicKey,programId:n}))),N.lamports<x&&(_=_||new Z,_.add(Je.transfer({fromPubkey:t.publicKey,toPubkey:r.publicKey,lamports:x-N.lamports})))}else _=new Z().add(Je.createAccount({fromPubkey:t.publicKey,newAccountPubkey:r.publicKey,lamports:x>0?x:1,space:i.length,programId:n}));_!==null&&await Os(e,_,[t,r],{commitment:"confirmed"})}let u=y.struct([y.u32("instruction"),y.u32("offset"),y.u32("bytesLength"),y.u32("bytesLengthPadding"),y.seq(y.u8("byte"),y.offset(y.u32(),-8),"bytes")]),l=At.chunkSize,m=0,I=i,B=[];for(;I.length>0;){let x=I.slice(0,l),N=D.alloc(l+16);u.encode({instruction:0,offset:m,bytes:x,bytesLength:0,bytesLengthPadding:0},N);let _=new Z().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0}],programId:n,data:N});B.push(Os(e,_,[t,r],{commitment:"confirmed"})),e._rpcEndpoint.includes("solana.com")&&await Pt(1e3/4),m+=l,I=I.slice(l)}await Promise.all(B);{let x=y.struct([y.u32("instruction")]),N=D.alloc(x.span);x.encode({instruction:1},N);let _=new Z().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0},{pubkey:or,isSigner:!1,isWritable:!1}],programId:n,data:N}),R="processed",L=await e.sendTransaction(_,[t,r],{preflightCommitment:R}),{context:z,value:W}=await e.confirmTransaction({signature:L,lastValidBlockHeight:_.lastValidBlockHeight,blockhash:_.recentBlockhash},R);if(W.err)throw new Error(`Transaction ${L} failed (${JSON.stringify(W)})`);for(;;){try{if(await e.getSlot({commitment:R})>z.slot)break}catch{}await new Promise(J=>setTimeout(J,Math.round(di/2)))}}return!0}};At.chunkSize=no;var _c=new M("BPFLoader2111111111111111111111111111111111"),qs=class{static getMinNumSignatures(e){return At.getMinNumSignatures(e)}static load(e,t,r,n,i){return At.load(e,t,r,i,n)}};function so(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var Nn,Us;function io(){if(Us)return Nn;Us=1;var a=Object.prototype.toString,e=Object.keys||function(r){var n=[];for(var i in r)n.push(i);return n};function t(r,n){var i,u,l,m,I,B,x;if(r===!0)return"true";if(r===!1)return"false";switch(typeof r){case"object":if(r===null)return null;if(r.toJSON&&typeof r.toJSON=="function")return t(r.toJSON(),n);if(x=a.call(r),x==="[object Array]"){for(l="[",u=r.length-1,i=0;i<u;i++)l+=t(r[i],!0)+",";return u>-1&&(l+=t(r[i],!0)),l+"]"}else if(x==="[object Object]"){for(m=e(r).sort(),u=m.length,l="",i=0;i<u;)I=m[i],B=t(r[I],!1),B!==void 0&&(l&&(l+=","),l+=JSON.stringify(I)+":"+B),i++;return"{"+l+"}"}else return JSON.stringify(r);case"function":case"undefined":return n?null:void 0;case"string":return JSON.stringify(r);default:return isFinite(r)?r:null}}return Nn=function(r){var n=t(r,!1);if(n!==void 0)return""+n},Nn}var oo=io(),Ds=so(oo),ir=32;function On(a){let e=0;for(;a>1;)a/=2,e++;return e}function ao(a){return a===0?1:(a--,a|=a>>1,a|=a>>2,a|=a>>4,a|=a>>8,a|=a>>16,a|=a>>32,a+1)}var $n=class{constructor(e,t,r,n,i){this.slotsPerEpoch=void 0,this.leaderScheduleSlotOffset=void 0,this.warmup=void 0,this.firstNormalEpoch=void 0,this.firstNormalSlot=void 0,this.slotsPerEpoch=e,this.leaderScheduleSlotOffset=t,this.warmup=r,this.firstNormalEpoch=n,this.firstNormalSlot=i}getEpoch(e){return this.getEpochAndSlotIndex(e)[0]}getEpochAndSlotIndex(e){if(e<this.firstNormalSlot){let t=On(ao(e+ir+1))-On(ir)-1,r=this.getSlotsInEpoch(t),n=e-(r-ir);return[t,n]}else{let t=e-this.firstNormalSlot,r=Math.floor(t/this.slotsPerEpoch),n=this.firstNormalEpoch+r,i=t%this.slotsPerEpoch;return[n,i]}}getFirstSlotInEpoch(e){return e<=this.firstNormalEpoch?(Math.pow(2,e)-1)*ir:(e-this.firstNormalEpoch)*this.slotsPerEpoch+this.firstNormalSlot}getLastSlotInEpoch(e){return this.getFirstSlotInEpoch(e)+this.getSlotsInEpoch(e)-1}getSlotsInEpoch(e){return e<this.firstNormalEpoch?Math.pow(2,e+On(ir)):this.slotsPerEpoch}},co=globalThis.fetch,Fn=class extends Ms{constructor(e,t,r){let n=i=>{let u=Es(i,{autoconnect:!0,max_reconnects:5,reconnect:!0,reconnect_interval:1e3,...t});return"socket"in u?this.underlyingSocket=u.socket:this.underlyingSocket=u,u};super(n,e,t,r),this.underlyingSocket=void 0}call(...e){let t=this.underlyingSocket?.readyState;return t===1?super.call(...e):Promise.reject(new Error("Tried to call a JSON-RPC method `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+")"))}notify(...e){let t=this.underlyingSocket?.readyState;return t===1?super.notify(...e):Promise.reject(new Error("Tried to send a JSON-RPC notification `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+")"))}};function uo(a,e){let t;try{t=a.layout.decode(e)}catch(r){throw new Error("invalid instruction; "+r)}if(t.typeIndex!==a.index)throw new Error(`invalid account data; account type mismatch ${t.typeIndex} != ${a.index}`);return t}var $s=56,Gr=class{constructor(e){this.key=void 0,this.state=void 0,this.key=e.key,this.state=e.state}isActive(){let e=BigInt("0xffffffffffffffff");return this.state.deactivationSlot===e}static deserialize(e){let t=uo(ho,e),r=e.length-$s;X(r>=0,"lookup table is invalid"),X(r%32===0,"lookup table is invalid");let n=r/32,{addresses:i}=y.struct([y.seq(G(),n,"addresses")]).decode(e.slice($s));return{deactivationSlot:t.deactivationSlot,lastExtendedSlot:t.lastExtendedSlot,lastExtendedSlotStartIndex:t.lastExtendedStartIndex,authority:t.authority.length!==0?new M(t.authority[0]):void 0,addresses:i.map(u=>new M(u))}}},ho={index:1,layout:y.struct([y.u32("typeIndex"),jt("deactivationSlot"),y.nu64("lastExtendedSlot"),y.u8("lastExtendedStartIndex"),y.u8(),y.seq(G(),y.offset(y.u8(),-1),"authority")])},lo=/^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;function fo(a){let e=a.match(lo);if(e==null)throw TypeError(`Failed to validate endpoint URL \`${a}\``);let[t,r,n,i]=e,u=a.startsWith("https:")?"wss:":"ws:",l=n==null?null:parseInt(n.slice(1),10),m=l==null?"":`:${l+1}`;return`${u}//${r}${m}${i}`}var fe=Ft(Nr(M),E(),a=>new M(a)),yi=Or([E(),he("base64")]),Xn=Ft(Nr(D),yi,a=>D.from(a[0],"base64")),po=30*1e3;function yo(a){if(/^https?:/.test(a)===!1)throw new TypeError("Endpoint URL must start with `http:` or `https:`.");return a}function oe(a){let e,t;if(typeof a=="string")e=a;else if(a){let{commitment:r,...n}=a;e=r,t=n}return{commitment:e,config:t}}function Fs(a){return a.map(e=>"memcmp"in e?{...e,memcmp:{...e.memcmp,encoding:e.memcmp.encoding??"base58"}}:e)}function gi(a){return et([A({jsonrpc:he("2.0"),id:E(),result:a}),A({jsonrpc:he("2.0"),id:E(),error:A({code:Mt(),message:E(),data:$(xs())})})])}var go=gi(Mt());function V(a){return Ft(gi(a),go,e=>"error"in e?e:{...e,result:P(e.result,a)})}function de(a){return V(A({context:A({slot:v()}),value:a}))}function Qr(a){return A({context:A({slot:v()}),value:a})}function Kn(a,e){return a===0?new _t({header:e.header,staticAccountKeys:e.accountKeys.map(t=>new M(t)),recentBlockhash:e.recentBlockhash,compiledInstructions:e.instructions.map(t=>({programIdIndex:t.programIdIndex,accountKeyIndexes:t.accounts,data:Ze.default.decode(t.data)})),addressTableLookups:e.addressTableLookups}):new lt(e)}var mo=A({foundation:v(),foundationTerm:v(),initial:v(),taper:v(),terminal:v()}),bo=V(T(C(A({epoch:v(),effectiveSlot:v(),amount:v(),postBalance:v(),commission:$(C(v()))})))),wo=T(A({slot:v(),prioritizationFee:v()})),ko=A({total:v(),validator:v(),foundation:v(),epoch:v()}),vo=A({epoch:v(),slotIndex:v(),slotsInEpoch:v(),absoluteSlot:v(),blockHeight:$(v()),transactionCount:$(v())}),So=A({slotsPerEpoch:v(),leaderScheduleSlotOffset:v(),warmup:dt(),firstNormalEpoch:v(),firstNormalSlot:v()}),Io=Tn(E(),T(v())),Wt=C(et([A({}),E()])),_o=A({err:Wt}),Ao=he("receivedSignature"),Bo=A({"solana-core":E(),"feature-set":$(v())}),Lo=A({program:E(),programId:fe,parsed:Mt()}),Ro=A({programId:fe,accounts:T(fe),data:E()}),Vs=de(A({err:C(et([A({}),E()])),logs:C(T(E())),accounts:$(C(T(C(A({executable:dt(),owner:E(),lamports:v(),data:T(E()),rentEpoch:$(v())}))))),unitsConsumed:$(v()),returnData:$(C(A({programId:E(),data:Or([E(),he("base64")])}))),innerInstructions:$(C(T(A({index:v(),instructions:T(et([Lo,Ro]))}))))})),xo=de(A({byIdentity:Tn(E(),T(v())),range:A({firstSlot:v(),lastSlot:v()})}));function Eo(a,e,t,r,n,i){let u=t||co,l;i!=null&&console.warn("You have supplied an `httpAgent` when creating a `Connection` in a browser environment.It has been ignored; `httpAgent` is only used in Node environments.");let m;return r&&(m=async(B,x)=>{let N=await new Promise((_,R)=>{try{r(B,x,(L,z)=>_([L,z]))}catch(L){R(L)}});return await u(...N)}),new ci.default(async(B,x)=>{let N={method:"POST",body:B,agent:l,headers:Object.assign({"Content-Type":"application/json"},e||{},Ma)};try{let _=5,R,L=500;for(;m?R=await m(a,N):R=await u(a,N),!(R.status!==429||n===!0||(_-=1,_===0));)console.error(`Server responded with ${R.status} ${R.statusText}. Retrying after ${L}ms delay...`),await Pt(L),L*=2;let z=await R.text();R.ok?x(null,z):x(new Error(`${R.status} ${R.statusText}: ${z}`))}catch(_){_ instanceof Error&&x(_)}},{})}function Mo(a){return(e,t)=>new Promise((r,n)=>{a.request(e,t,(i,u)=>{if(i){n(i);return}r(u)})})}function Po(a){return e=>new Promise((t,r)=>{e.length===0&&t([]);let n=e.map(i=>a.request(i.methodName,i.args));a.request(n,(i,u)=>{if(i){r(i);return}t(u)})})}var To=V(mo),Co=V(ko),zo=V(wo),No=V(vo),Oo=V(So),Ko=V(Io),Wo=V(v()),qo=de(A({total:v(),circulating:v(),nonCirculating:v(),nonCirculatingAccounts:T(fe)})),Vn=A({amount:E(),uiAmount:C(v()),decimals:v(),uiAmountString:$(E())}),Uo=de(T(A({address:fe,amount:E(),uiAmount:C(v()),decimals:v(),uiAmountString:$(E())}))),Do=de(T(A({pubkey:fe,account:A({executable:dt(),owner:fe,lamports:v(),data:Xn,rentEpoch:v()})}))),Hn=A({program:E(),parsed:Mt(),space:v()}),$o=de(T(A({pubkey:fe,account:A({executable:dt(),owner:fe,lamports:v(),data:Hn,rentEpoch:v()})}))),Fo=de(T(A({lamports:v(),address:fe}))),cr=A({executable:dt(),owner:fe,lamports:v(),data:Xn,rentEpoch:v()}),Vo=A({pubkey:fe,account:cr}),Ho=Ft(et([Nr(D),Hn]),et([yi,Hn]),a=>Array.isArray(a)?P(a,Xn):a),Gn=A({executable:dt(),owner:fe,lamports:v(),data:Ho,rentEpoch:v()}),Go=A({pubkey:fe,account:Gn}),jo=A({state:et([he("active"),he("inactive"),he("activating"),he("deactivating")]),active:v(),inactive:v()}),Jo=V(T(A({signature:E(),slot:v(),err:Wt,memo:C(E()),blockTime:$(C(v()))}))),Yo=V(T(A({signature:E(),slot:v(),err:Wt,memo:C(E()),blockTime:$(C(v()))}))),Zo=A({subscription:v(),result:Qr(cr)}),Xo=A({pubkey:fe,account:cr}),Qo=A({subscription:v(),result:Qr(Xo)}),ea=A({parent:v(),slot:v(),root:v()}),ta=A({subscription:v(),result:ea}),ra=et([A({type:et([he("firstShredReceived"),he("completed"),he("optimisticConfirmation"),he("root")]),slot:v(),timestamp:v()}),A({type:he("createdBank"),parent:v(),slot:v(),timestamp:v()}),A({type:he("frozen"),slot:v(),timestamp:v(),stats:A({numTransactionEntries:v(),numSuccessfulTransactions:v(),numFailedTransactions:v(),maxTransactionsPerEntry:v()})}),A({type:he("dead"),slot:v(),timestamp:v(),err:E()})]),na=A({subscription:v(),result:ra}),sa=A({subscription:v(),result:Qr(et([_o,Ao]))}),ia=A({subscription:v(),result:v()}),oa=A({pubkey:E(),gossip:C(E()),tpu:C(E()),rpc:C(E()),version:C(E())}),Hs=A({votePubkey:E(),nodePubkey:E(),activatedStake:v(),epochVoteAccount:dt(),epochCredits:T(Or([v(),v(),v()])),commission:v(),lastVote:v(),rootSlot:C(v())}),aa=V(A({current:T(Hs),delinquent:T(Hs)})),ca=et([he("processed"),he("confirmed"),he("finalized")]),ua=A({slot:v(),confirmations:C(v()),err:Wt,confirmationStatus:$(ca)}),ha=de(T(C(ua))),la=V(v()),mi=A({accountKey:fe,writableIndexes:T(v()),readonlyIndexes:T(v())}),Qn=A({signatures:T(E()),message:A({accountKeys:T(E()),header:A({numRequiredSignatures:v(),numReadonlySignedAccounts:v(),numReadonlyUnsignedAccounts:v()}),instructions:T(A({accounts:T(v()),data:E(),programIdIndex:v()})),recentBlockhash:E(),addressTableLookups:$(T(mi))})}),bi=A({pubkey:fe,signer:dt(),writable:dt(),source:$(et([he("transaction"),he("lookupTable")]))}),wi=A({accountKeys:T(bi),signatures:T(E())}),ki=A({parsed:Mt(),program:E(),programId:fe}),vi=A({accounts:T(fe),data:E(),programId:fe}),fa=et([vi,ki]),da=et([A({parsed:Mt(),program:E(),programId:E()}),A({accounts:T(E()),data:E(),programId:E()})]),Si=Ft(fa,da,a=>"accounts"in a?P(a,vi):P(a,ki)),Ii=A({signatures:T(E()),message:A({accountKeys:T(bi),instructions:T(Si),recentBlockhash:E(),addressTableLookups:$(C(T(mi)))})}),jr=A({accountIndex:v(),mint:E(),owner:$(E()),uiTokenAmount:Vn}),_i=A({writable:T(fe),readonly:T(fe)}),en=A({err:Wt,fee:v(),innerInstructions:$(C(T(A({index:v(),instructions:T(A({accounts:T(v()),data:E(),programIdIndex:v()}))})))),preBalances:T(v()),postBalances:T(v()),logMessages:$(C(T(E()))),preTokenBalances:$(C(T(jr))),postTokenBalances:$(C(T(jr))),loadedAddresses:$(_i),computeUnitsConsumed:$(v())}),es=A({err:Wt,fee:v(),innerInstructions:$(C(T(A({index:v(),instructions:T(Si)})))),preBalances:T(v()),postBalances:T(v()),logMessages:$(C(T(E()))),preTokenBalances:$(C(T(jr))),postTokenBalances:$(C(T(jr))),loadedAddresses:$(_i),computeUnitsConsumed:$(v())}),Zt=et([he(0),he("legacy")]),qt=A({pubkey:E(),lamports:v(),postBalance:C(v()),rewardType:C(E()),commission:$(C(v()))}),pa=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),transactions:T(A({transaction:Qn,meta:C(en),version:$(Zt)})),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),ya=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),ga=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),transactions:T(A({transaction:wi,meta:C(en),version:$(Zt)})),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),ma=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),transactions:T(A({transaction:Ii,meta:C(es),version:$(Zt)})),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),ba=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),transactions:T(A({transaction:wi,meta:C(es),version:$(Zt)})),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),wa=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),rewards:$(T(qt)),blockTime:C(v()),blockHeight:C(v())}))),ka=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),transactions:T(A({transaction:Qn,meta:C(en)})),rewards:$(T(qt)),blockTime:C(v())}))),Gs=V(C(A({blockhash:E(),previousBlockhash:E(),parentSlot:v(),signatures:T(E()),blockTime:C(v())}))),Wn=V(C(A({slot:v(),meta:C(en),blockTime:$(C(v())),transaction:Qn,version:$(Zt)}))),Kr=V(C(A({slot:v(),transaction:Ii,meta:C(es),blockTime:$(C(v())),version:$(Zt)}))),va=de(A({blockhash:E(),feeCalculator:A({lamportsPerSignature:v()})})),Sa=de(A({blockhash:E(),lastValidBlockHeight:v()})),Ia=de(dt()),_a=A({slot:v(),numTransactions:v(),numSlots:v(),samplePeriodSecs:v()}),Aa=V(T(_a)),Ba=de(C(A({feeCalculator:A({lamportsPerSignature:v()})}))),La=V(E()),Ra=V(E()),xa=A({err:Wt,logs:T(E()),signature:E()}),Ea=A({result:Qr(xa),subscription:v()}),Ma={"solana-client":"js/1.0.0-maintenance"},js=class{constructor(e,t){this._commitment=void 0,this._confirmTransactionInitialTimeout=void 0,this._rpcEndpoint=void 0,this._rpcWsEndpoint=void 0,this._rpcClient=void 0,this._rpcRequest=void 0,this._rpcBatchRequest=void 0,this._rpcWebSocket=void 0,this._rpcWebSocketConnected=!1,this._rpcWebSocketHeartbeat=null,this._rpcWebSocketIdleTimeout=null,this._rpcWebSocketGeneration=0,this._disableBlockhashCaching=!1,this._pollingBlockhash=!1,this._blockhashInfo={latestBlockhash:null,lastFetch:0,transactionSignatures:[],simulatedSignatures:[]},this._nextClientSubscriptionId=0,this._subscriptionDisposeFunctionsByClientSubscriptionId={},this._subscriptionHashByClientSubscriptionId={},this._subscriptionStateChangeCallbacksByHash={},this._subscriptionCallbacksByServerSubscriptionId={},this._subscriptionsByHash={},this._subscriptionsAutoDisposedByRpc=new Set,this.getBlockHeight=(()=>{let I={};return async B=>{let{commitment:x,config:N}=oe(B),_=this._buildArgs([],x,void 0,N),R=Ds(_);return I[R]=I[R]??(async()=>{try{let L=await this._rpcRequest("getBlockHeight",_),z=P(L,V(v()));if("error"in z)throw new O(z.error,"failed to get block height information");return z.result}finally{delete I[R]}})(),await I[R]}})();let r,n,i,u,l,m;t&&typeof t=="string"?this._commitment=t:t&&(this._commitment=t.commitment,this._confirmTransactionInitialTimeout=t.confirmTransactionInitialTimeout,r=t.wsEndpoint,n=t.httpHeaders,i=t.fetch,u=t.fetchMiddleware,l=t.disableRetryOnRateLimit,m=t.httpAgent),this._rpcEndpoint=yo(e),this._rpcWsEndpoint=r||fo(e),this._rpcClient=Eo(e,n,i,u,l,m),this._rpcRequest=Mo(this._rpcClient),this._rpcBatchRequest=Po(this._rpcClient),this._rpcWebSocket=new Fn(this._rpcWsEndpoint,{autoconnect:!1,max_reconnects:1/0}),this._rpcWebSocket.on("open",this._wsOnOpen.bind(this)),this._rpcWebSocket.on("error",this._wsOnError.bind(this)),this._rpcWebSocket.on("close",this._wsOnClose.bind(this)),this._rpcWebSocket.on("accountNotification",this._wsOnAccountNotification.bind(this)),this._rpcWebSocket.on("programNotification",this._wsOnProgramAccountNotification.bind(this)),this._rpcWebSocket.on("slotNotification",this._wsOnSlotNotification.bind(this)),this._rpcWebSocket.on("slotsUpdatesNotification",this._wsOnSlotUpdatesNotification.bind(this)),this._rpcWebSocket.on("signatureNotification",this._wsOnSignatureNotification.bind(this)),this._rpcWebSocket.on("rootNotification",this._wsOnRootNotification.bind(this)),this._rpcWebSocket.on("logsNotification",this._wsOnLogsNotification.bind(this))}get commitment(){return this._commitment}get rpcEndpoint(){return this._rpcEndpoint}async getBalanceAndContext(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgs([e.toBase58()],r,void 0,n),u=await this._rpcRequest("getBalance",i),l=P(u,de(v()));if("error"in l)throw new O(l.error,`failed to get balance for ${e.toBase58()}`);return l.result}async getBalance(e,t){return await this.getBalanceAndContext(e,t).then(r=>r.value).catch(r=>{throw new Error("failed to get balance of account "+e.toBase58()+": "+r)})}async getBlockTime(e){let t=await this._rpcRequest("getBlockTime",[e]),r=P(t,V(C(v())));if("error"in r)throw new O(r.error,`failed to get block time for slot ${e}`);return r.result}async getMinimumLedgerSlot(){let e=await this._rpcRequest("minimumLedgerSlot",[]),t=P(e,V(v()));if("error"in t)throw new O(t.error,"failed to get minimum ledger slot");return t.result}async getFirstAvailableBlock(){let e=await this._rpcRequest("getFirstAvailableBlock",[]),t=P(e,Wo);if("error"in t)throw new O(t.error,"failed to get first available block");return t.result}async getSupply(e){let t={};typeof e=="string"?t={commitment:e}:e?t={...e,commitment:e&&e.commitment||this.commitment}:t={commitment:this.commitment};let r=await this._rpcRequest("getSupply",[t]),n=P(r,qo);if("error"in n)throw new O(n.error,"failed to get supply");return n.result}async getTokenSupply(e,t){let r=this._buildArgs([e.toBase58()],t),n=await this._rpcRequest("getTokenSupply",r),i=P(n,de(Vn));if("error"in i)throw new O(i.error,"failed to get token supply");return i.result}async getTokenAccountBalance(e,t){let r=this._buildArgs([e.toBase58()],t),n=await this._rpcRequest("getTokenAccountBalance",r),i=P(n,de(Vn));if("error"in i)throw new O(i.error,"failed to get token account balance");return i.result}async getTokenAccountsByOwner(e,t,r){let{commitment:n,config:i}=oe(r),u=[e.toBase58()];"mint"in t?u.push({mint:t.mint.toBase58()}):u.push({programId:t.programId.toBase58()});let l=this._buildArgs(u,n,"base64",i),m=await this._rpcRequest("getTokenAccountsByOwner",l),I=P(m,Do);if("error"in I)throw new O(I.error,`failed to get token accounts owned by account ${e.toBase58()}`);return I.result}async getParsedTokenAccountsByOwner(e,t,r){let n=[e.toBase58()];"mint"in t?n.push({mint:t.mint.toBase58()}):n.push({programId:t.programId.toBase58()});let i=this._buildArgs(n,r,"jsonParsed"),u=await this._rpcRequest("getTokenAccountsByOwner",i),l=P(u,$o);if("error"in l)throw new O(l.error,`failed to get token accounts owned by account ${e.toBase58()}`);return l.result}async getLargestAccounts(e){let t={...e,commitment:e&&e.commitment||this.commitment},r=t.filter||t.commitment?[t]:[],n=await this._rpcRequest("getLargestAccounts",r),i=P(n,Fo);if("error"in i)throw new O(i.error,"failed to get largest accounts");return i.result}async getTokenLargestAccounts(e,t){let r=this._buildArgs([e.toBase58()],t),n=await this._rpcRequest("getTokenLargestAccounts",r),i=P(n,Uo);if("error"in i)throw new O(i.error,"failed to get token largest accounts");return i.result}async getAccountInfoAndContext(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgs([e.toBase58()],r,"base64",n),u=await this._rpcRequest("getAccountInfo",i),l=P(u,de(C(cr)));if("error"in l)throw new O(l.error,`failed to get info about account ${e.toBase58()}`);return l.result}async getParsedAccountInfo(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgs([e.toBase58()],r,"jsonParsed",n),u=await this._rpcRequest("getAccountInfo",i),l=P(u,de(C(Gn)));if("error"in l)throw new O(l.error,`failed to get info about account ${e.toBase58()}`);return l.result}async getAccountInfo(e,t){try{return(await this.getAccountInfoAndContext(e,t)).value}catch(r){throw new Error("failed to get info about account "+e.toBase58()+": "+r)}}async getMultipleParsedAccounts(e,t){let{commitment:r,config:n}=oe(t),i=e.map(I=>I.toBase58()),u=this._buildArgs([i],r,"jsonParsed",n),l=await this._rpcRequest("getMultipleAccounts",u),m=P(l,de(T(C(Gn))));if("error"in m)throw new O(m.error,`failed to get info for accounts ${i}`);return m.result}async getMultipleAccountsInfoAndContext(e,t){let{commitment:r,config:n}=oe(t),i=e.map(I=>I.toBase58()),u=this._buildArgs([i],r,"base64",n),l=await this._rpcRequest("getMultipleAccounts",u),m=P(l,de(T(C(cr))));if("error"in m)throw new O(m.error,`failed to get info for accounts ${i}`);return m.result}async getMultipleAccountsInfo(e,t){return(await this.getMultipleAccountsInfoAndContext(e,t)).value}async getStakeActivation(e,t,r){let{commitment:n,config:i}=oe(t),u=this._buildArgs([e.toBase58()],n,void 0,{...i,epoch:r??i?.epoch}),l=await this._rpcRequest("getStakeActivation",u),m=P(l,V(jo));if("error"in m)throw new O(m.error,`failed to get Stake Activation ${e.toBase58()}`);return m.result}async getProgramAccounts(e,t){let{commitment:r,config:n}=oe(t),{encoding:i,...u}=n||{},l=this._buildArgs([e.toBase58()],r,i||"base64",{...u,...u.filters?{filters:Fs(u.filters)}:null}),m=await this._rpcRequest("getProgramAccounts",l),I=T(Vo),B=u.withContext===!0?P(m,de(I)):P(m,V(I));if("error"in B)throw new O(B.error,`failed to get accounts owned by program ${e.toBase58()}`);return B.result}async getParsedProgramAccounts(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgs([e.toBase58()],r,"jsonParsed",n),u=await this._rpcRequest("getProgramAccounts",i),l=P(u,V(T(Go)));if("error"in l)throw new O(l.error,`failed to get accounts owned by program ${e.toBase58()}`);return l.result}async confirmTransaction(e,t){let r;if(typeof e=="string")r=e;else{let i=e;if(i.abortSignal?.aborted)return Promise.reject(i.abortSignal.reason);r=i.signature}let n;try{n=Ze.default.decode(r)}catch{throw new Error("signature must be base58 encoded: "+r)}return X(n.length===64,"signature has invalid length"),typeof e=="string"?await this.confirmTransactionUsingLegacyTimeoutStrategy({commitment:t||this.commitment,signature:r}):"lastValidBlockHeight"in e?await this.confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:t||this.commitment,strategy:e}):await this.confirmTransactionUsingDurableNonceStrategy({commitment:t||this.commitment,strategy:e})}getCancellationPromise(e){return new Promise((t,r)=>{e!=null&&(e.aborted?r(e.reason):e.addEventListener("abort",()=>{r(e.reason)}))})}getTransactionConfirmationPromise({commitment:e,signature:t}){let r,n,i=!1,u=new Promise((m,I)=>{try{r=this.onSignature(t,(x,N)=>{r=void 0;let _={context:N,value:x};m({__type:St.PROCESSED,response:_})},e);let B=new Promise(x=>{r==null?x():n=this._onSubscriptionStateChange(r,N=>{N==="subscribed"&&x()})});(async()=>{if(await B,i)return;let x=await this.getSignatureStatus(t);if(i||x==null)return;let{context:N,value:_}=x;if(_!=null)if(_?.err)I(_.err);else{switch(e){case"confirmed":case"single":case"singleGossip":{if(_.confirmationStatus==="processed")return;break}case"finalized":case"max":case"root":{if(_.confirmationStatus==="processed"||_.confirmationStatus==="confirmed")return;break}case"processed":case"recent":}i=!0,m({__type:St.PROCESSED,response:{context:N,value:_}})}})()}catch(B){I(B)}});return{abortConfirmation:()=>{n&&(n(),n=void 0),r!=null&&(this.removeSignatureListener(r),r=void 0)},confirmationPromise:u}}async confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:e,strategy:{abortSignal:t,lastValidBlockHeight:r,signature:n}}){let i=!1,u=new Promise(x=>{let N=async()=>{try{return await this.getBlockHeight(e)}catch{return-1}};(async()=>{let _=await N();if(!i){for(;_<=r;)if(await Pt(1e3),i||(_=await N(),i))return;x({__type:St.BLOCKHEIGHT_EXCEEDED})}})()}),{abortConfirmation:l,confirmationPromise:m}=this.getTransactionConfirmationPromise({commitment:e,signature:n}),I=this.getCancellationPromise(t),B;try{let x=await Promise.race([I,m,u]);if(x.__type===St.PROCESSED)B=x.response;else throw new $r(n)}finally{i=!0,l()}return B}async confirmTransactionUsingDurableNonceStrategy({commitment:e,strategy:{abortSignal:t,minContextSlot:r,nonceAccountPubkey:n,nonceValue:i,signature:u}}){let l=!1,m=new Promise(_=>{let R=i,L=null,z=async()=>{try{let{context:W,value:J}=await this.getNonceAndContext(n,{commitment:e,minContextSlot:r});return L=W.slot,J?.nonce}catch{return R}};(async()=>{if(R=await z(),!l)for(;;){if(i!==R){_({__type:St.NONCE_INVALID,slotInWhichNonceDidAdvance:L});return}if(await Pt(2e3),l||(R=await z(),l))return}})()}),{abortConfirmation:I,confirmationPromise:B}=this.getTransactionConfirmationPromise({commitment:e,signature:u}),x=this.getCancellationPromise(t),N;try{let _=await Promise.race([x,B,m]);if(_.__type===St.PROCESSED)N=_.response;else{let R;for(;;){let L=await this.getSignatureStatus(u);if(L==null)break;if(L.context.slot<(_.slotInWhichNonceDidAdvance??r)){await Pt(400);continue}R=L;break}if(R?.value){let L=e||"finalized",{confirmationStatus:z}=R.value;switch(L){case"processed":case"recent":if(z!=="processed"&&z!=="confirmed"&&z!=="finalized")throw new Tt(u);break;case"confirmed":case"single":case"singleGossip":if(z!=="confirmed"&&z!=="finalized")throw new Tt(u);break;case"finalized":case"max":case"root":if(z!=="finalized")throw new Tt(u);break;default:(W=>{})(L)}N={context:R.context,value:{err:R.value.err}}}else throw new Tt(u)}}finally{l=!0,I()}return N}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:e,signature:t}){let r,n=new Promise(m=>{let I=this._confirmTransactionInitialTimeout||6e4;switch(e){case"processed":case"recent":case"single":case"confirmed":case"singleGossip":{I=this._confirmTransactionInitialTimeout||3e4;break}}r=setTimeout(()=>m({__type:St.TIMED_OUT,timeoutMs:I}),I)}),{abortConfirmation:i,confirmationPromise:u}=this.getTransactionConfirmationPromise({commitment:e,signature:t}),l;try{let m=await Promise.race([u,n]);if(m.__type===St.PROCESSED)l=m.response;else throw new Fr(t,m.timeoutMs/1e3)}finally{clearTimeout(r),i()}return l}async getClusterNodes(){let e=await this._rpcRequest("getClusterNodes",[]),t=P(e,V(T(oa)));if("error"in t)throw new O(t.error,"failed to get cluster nodes");return t.result}async getVoteAccounts(e){let t=this._buildArgs([],e),r=await this._rpcRequest("getVoteAccounts",t),n=P(r,aa);if("error"in n)throw new O(n.error,"failed to get vote accounts");return n.result}async getSlot(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,void 0,r),i=await this._rpcRequest("getSlot",n),u=P(i,V(v()));if("error"in u)throw new O(u.error,"failed to get slot");return u.result}async getSlotLeader(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,void 0,r),i=await this._rpcRequest("getSlotLeader",n),u=P(i,V(E()));if("error"in u)throw new O(u.error,"failed to get slot leader");return u.result}async getSlotLeaders(e,t){let r=[e,t],n=await this._rpcRequest("getSlotLeaders",r),i=P(n,V(T(fe)));if("error"in i)throw new O(i.error,"failed to get slot leaders");return i.result}async getSignatureStatus(e,t){let{context:r,value:n}=await this.getSignatureStatuses([e],t);X(n.length===1);let i=n[0];return{context:r,value:i}}async getSignatureStatuses(e,t){let r=[e];t&&r.push(t);let n=await this._rpcRequest("getSignatureStatuses",r),i=P(n,ha);if("error"in i)throw new O(i.error,"failed to get signature status");return i.result}async getTransactionCount(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,void 0,r),i=await this._rpcRequest("getTransactionCount",n),u=P(i,V(v()));if("error"in u)throw new O(u.error,"failed to get transaction count");return u.result}async getTotalSupply(e){return(await this.getSupply({commitment:e,excludeNonCirculatingAccountsList:!0})).value.total}async getInflationGovernor(e){let t=this._buildArgs([],e),r=await this._rpcRequest("getInflationGovernor",t),n=P(r,To);if("error"in n)throw new O(n.error,"failed to get inflation");return n.result}async getInflationReward(e,t,r){let{commitment:n,config:i}=oe(r),u=this._buildArgs([e.map(I=>I.toBase58())],n,void 0,{...i,epoch:t??i?.epoch}),l=await this._rpcRequest("getInflationReward",u),m=P(l,bo);if("error"in m)throw new O(m.error,"failed to get inflation reward");return m.result}async getInflationRate(){let e=await this._rpcRequest("getInflationRate",[]),t=P(e,Co);if("error"in t)throw new O(t.error,"failed to get inflation rate");return t.result}async getEpochInfo(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,void 0,r),i=await this._rpcRequest("getEpochInfo",n),u=P(i,No);if("error"in u)throw new O(u.error,"failed to get epoch info");return u.result}async getEpochSchedule(){let e=await this._rpcRequest("getEpochSchedule",[]),t=P(e,Oo);if("error"in t)throw new O(t.error,"failed to get epoch schedule");let r=t.result;return new $n(r.slotsPerEpoch,r.leaderScheduleSlotOffset,r.warmup,r.firstNormalEpoch,r.firstNormalSlot)}async getLeaderSchedule(){let e=await this._rpcRequest("getLeaderSchedule",[]),t=P(e,Ko);if("error"in t)throw new O(t.error,"failed to get leader schedule");return t.result}async getMinimumBalanceForRentExemption(e,t){let r=this._buildArgs([e],t),n=await this._rpcRequest("getMinimumBalanceForRentExemption",r),i=P(n,la);return"error"in i?(console.warn("Unable to fetch minimum balance for rent exemption"),0):i.result}async getRecentBlockhashAndContext(e){let t=this._buildArgs([],e),r=await this._rpcRequest("getRecentBlockhash",t),n=P(r,va);if("error"in n)throw new O(n.error,"failed to get recent blockhash");return n.result}async getRecentPerformanceSamples(e){let t=await this._rpcRequest("getRecentPerformanceSamples",e?[e]:[]),r=P(t,Aa);if("error"in r)throw new O(r.error,"failed to get recent performance samples");return r.result}async getFeeCalculatorForBlockhash(e,t){let r=this._buildArgs([e],t),n=await this._rpcRequest("getFeeCalculatorForBlockhash",r),i=P(n,Ba);if("error"in i)throw new O(i.error,"failed to get fee calculator");let{context:u,value:l}=i.result;return{context:u,value:l!==null?l.feeCalculator:null}}async getFeeForMessage(e,t){let r=H(e.serialize()).toString("base64"),n=this._buildArgs([r],t),i=await this._rpcRequest("getFeeForMessage",n),u=P(i,de(C(v())));if("error"in u)throw new O(u.error,"failed to get fee for message");if(u.result===null)throw new Error("invalid blockhash");return u.result}async getRecentPrioritizationFees(e){let t=e?.lockedWritableAccounts?.map(u=>u.toBase58()),r=t?.length?[t]:[],n=await this._rpcRequest("getRecentPrioritizationFees",r),i=P(n,zo);if("error"in i)throw new O(i.error,"failed to get recent prioritization fees");return i.result}async getRecentBlockhash(e){try{return(await this.getRecentBlockhashAndContext(e)).value}catch(t){throw new Error("failed to get recent blockhash: "+t)}}async getLatestBlockhash(e){try{return(await this.getLatestBlockhashAndContext(e)).value}catch(t){throw new Error("failed to get recent blockhash: "+t)}}async getLatestBlockhashAndContext(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,void 0,r),i=await this._rpcRequest("getLatestBlockhash",n),u=P(i,Sa);if("error"in u)throw new O(u.error,"failed to get latest blockhash");return u.result}async isBlockhashValid(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgs([e],r,void 0,n),u=await this._rpcRequest("isBlockhashValid",i),l=P(u,Ia);if("error"in l)throw new O(l.error,"failed to determine if the blockhash `"+e+"`is valid");return l.result}async getVersion(){let e=await this._rpcRequest("getVersion",[]),t=P(e,V(Bo));if("error"in t)throw new O(t.error,"failed to get version");return t.result}async getGenesisHash(){let e=await this._rpcRequest("getGenesisHash",[]),t=P(e,V(E()));if("error"in t)throw new O(t.error,"failed to get genesis hash");return t.result}async getBlock(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgsAtLeastConfirmed([e],r,void 0,n),u=await this._rpcRequest("getBlock",i);try{switch(n?.transactionDetails){case"accounts":{let l=P(u,ga);if("error"in l)throw l.error;return l.result}case"none":{let l=P(u,ya);if("error"in l)throw l.error;return l.result}default:{let l=P(u,pa);if("error"in l)throw l.error;let{result:m}=l;return m?{...m,transactions:m.transactions.map(({transaction:I,meta:B,version:x})=>({meta:B,transaction:{...I,message:Kn(x,I.message)},version:x}))}:null}}}catch(l){throw new O(l,"failed to get confirmed block")}}async getParsedBlock(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgsAtLeastConfirmed([e],r,"jsonParsed",n),u=await this._rpcRequest("getBlock",i);try{switch(n?.transactionDetails){case"accounts":{let l=P(u,ba);if("error"in l)throw l.error;return l.result}case"none":{let l=P(u,wa);if("error"in l)throw l.error;return l.result}default:{let l=P(u,ma);if("error"in l)throw l.error;return l.result}}}catch(l){throw new O(l,"failed to get block")}}async getBlockProduction(e){let t,r;if(typeof e=="string")r=e;else if(e){let{commitment:l,...m}=e;r=l,t=m}let n=this._buildArgs([],r,"base64",t),i=await this._rpcRequest("getBlockProduction",n),u=P(i,xo);if("error"in u)throw new O(u.error,"failed to get block production information");return u.result}async getTransaction(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgsAtLeastConfirmed([e],r,void 0,n),u=await this._rpcRequest("getTransaction",i),l=P(u,Wn);if("error"in l)throw new O(l.error,"failed to get transaction");let m=l.result;return m&&{...m,transaction:{...m.transaction,message:Kn(m.version,m.transaction.message)}}}async getParsedTransaction(e,t){let{commitment:r,config:n}=oe(t),i=this._buildArgsAtLeastConfirmed([e],r,"jsonParsed",n),u=await this._rpcRequest("getTransaction",i),l=P(u,Kr);if("error"in l)throw new O(l.error,"failed to get transaction");return l.result}async getParsedTransactions(e,t){let{commitment:r,config:n}=oe(t),i=e.map(m=>({methodName:"getTransaction",args:this._buildArgsAtLeastConfirmed([m],r,"jsonParsed",n)}));return(await this._rpcBatchRequest(i)).map(m=>{let I=P(m,Kr);if("error"in I)throw new O(I.error,"failed to get transactions");return I.result})}async getTransactions(e,t){let{commitment:r,config:n}=oe(t),i=e.map(m=>({methodName:"getTransaction",args:this._buildArgsAtLeastConfirmed([m],r,void 0,n)}));return(await this._rpcBatchRequest(i)).map(m=>{let I=P(m,Wn);if("error"in I)throw new O(I.error,"failed to get transactions");let B=I.result;return B&&{...B,transaction:{...B.transaction,message:Kn(B.version,B.transaction.message)}}})}async getConfirmedBlock(e,t){let r=this._buildArgsAtLeastConfirmed([e],t),n=await this._rpcRequest("getConfirmedBlock",r),i=P(n,ka);if("error"in i)throw new O(i.error,"failed to get confirmed block");let u=i.result;if(!u)throw new Error("Confirmed block "+e+" not found");let l={...u,transactions:u.transactions.map(({transaction:m,meta:I})=>{let B=new lt(m.message);return{meta:I,transaction:{...m,message:B}}})};return{...l,transactions:l.transactions.map(({transaction:m,meta:I})=>({meta:I,transaction:Z.populate(m.message,m.signatures)}))}}async getBlocks(e,t,r){let n=this._buildArgsAtLeastConfirmed(t!==void 0?[e,t]:[e],r),i=await this._rpcRequest("getBlocks",n),u=P(i,V(T(v())));if("error"in u)throw new O(u.error,"failed to get blocks");return u.result}async getBlockSignatures(e,t){let r=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:"signatures",rewards:!1}),n=await this._rpcRequest("getBlock",r),i=P(n,Gs);if("error"in i)throw new O(i.error,"failed to get block");let u=i.result;if(!u)throw new Error("Block "+e+" not found");return u}async getConfirmedBlockSignatures(e,t){let r=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:"signatures",rewards:!1}),n=await this._rpcRequest("getConfirmedBlock",r),i=P(n,Gs);if("error"in i)throw new O(i.error,"failed to get confirmed block");let u=i.result;if(!u)throw new Error("Confirmed block "+e+" not found");return u}async getConfirmedTransaction(e,t){let r=this._buildArgsAtLeastConfirmed([e],t),n=await this._rpcRequest("getConfirmedTransaction",r),i=P(n,Wn);if("error"in i)throw new O(i.error,"failed to get transaction");let u=i.result;if(!u)return u;let l=new lt(u.transaction.message),m=u.transaction.signatures;return{...u,transaction:Z.populate(l,m)}}async getParsedConfirmedTransaction(e,t){let r=this._buildArgsAtLeastConfirmed([e],t,"jsonParsed"),n=await this._rpcRequest("getConfirmedTransaction",r),i=P(n,Kr);if("error"in i)throw new O(i.error,"failed to get confirmed transaction");return i.result}async getParsedConfirmedTransactions(e,t){let r=e.map(u=>({methodName:"getConfirmedTransaction",args:this._buildArgsAtLeastConfirmed([u],t,"jsonParsed")}));return(await this._rpcBatchRequest(r)).map(u=>{let l=P(u,Kr);if("error"in l)throw new O(l.error,"failed to get confirmed transactions");return l.result})}async getConfirmedSignaturesForAddress(e,t,r){let n={},i=await this.getFirstAvailableBlock();for(;!("until"in n)&&(t--,!(t<=0||t<i));)try{let m=await this.getConfirmedBlockSignatures(t,"finalized");m.signatures.length>0&&(n.until=m.signatures[m.signatures.length-1].toString())}catch(m){if(m instanceof Error&&m.message.includes("skipped"))continue;throw m}let u=await this.getSlot("finalized");for(;!("before"in n)&&(r++,!(r>u));)try{let m=await this.getConfirmedBlockSignatures(r);m.signatures.length>0&&(n.before=m.signatures[m.signatures.length-1].toString())}catch(m){if(m instanceof Error&&m.message.includes("skipped"))continue;throw m}return(await this.getConfirmedSignaturesForAddress2(e,n)).map(m=>m.signature)}async getConfirmedSignaturesForAddress2(e,t,r){let n=this._buildArgsAtLeastConfirmed([e.toBase58()],r,void 0,t),i=await this._rpcRequest("getConfirmedSignaturesForAddress2",n),u=P(i,Jo);if("error"in u)throw new O(u.error,"failed to get confirmed signatures for address");return u.result}async getSignaturesForAddress(e,t,r){let n=this._buildArgsAtLeastConfirmed([e.toBase58()],r,void 0,t),i=await this._rpcRequest("getSignaturesForAddress",n),u=P(i,Yo);if("error"in u)throw new O(u.error,"failed to get signatures for address");return u.result}async getAddressLookupTable(e,t){let{context:r,value:n}=await this.getAccountInfoAndContext(e,t),i=null;return n!==null&&(i=new Gr({key:e,state:Gr.deserialize(n.data)})),{context:r,value:i}}async getNonceAndContext(e,t){let{context:r,value:n}=await this.getAccountInfoAndContext(e,t),i=null;return n!==null&&(i=ar.fromAccountData(n.data)),{context:r,value:i}}async getNonce(e,t){return await this.getNonceAndContext(e,t).then(r=>r.value).catch(r=>{throw new Error("failed to get nonce for account "+e.toBase58()+": "+r)})}async requestAirdrop(e,t){let r=await this._rpcRequest("requestAirdrop",[e.toBase58(),t]),n=P(r,La);if("error"in n)throw new O(n.error,`airdrop to ${e.toBase58()} failed`);return n.result}async _blockhashWithExpiryBlockHeight(e){if(!e){for(;this._pollingBlockhash;)await Pt(100);let r=Date.now()-this._blockhashInfo.lastFetch>=po;if(this._blockhashInfo.latestBlockhash!==null&&!r)return this._blockhashInfo.latestBlockhash}return await this._pollNewBlockhash()}async _pollNewBlockhash(){this._pollingBlockhash=!0;try{let e=Date.now(),t=this._blockhashInfo.latestBlockhash,r=t?t.blockhash:null;for(let n=0;n<50;n++){let i=await this.getLatestBlockhash("finalized");if(r!==i.blockhash)return this._blockhashInfo={latestBlockhash:i,lastFetch:Date.now(),transactionSignatures:[],simulatedSignatures:[]},i;await Pt(di/2)}throw new Error(`Unable to obtain a new blockhash after ${Date.now()-e}ms`)}finally{this._pollingBlockhash=!1}}async getStakeMinimumDelegation(e){let{commitment:t,config:r}=oe(e),n=this._buildArgs([],t,"base64",r),i=await this._rpcRequest("getStakeMinimumDelegation",n),u=P(i,de(v()));if("error"in u)throw new O(u.error,"failed to get stake minimum delegation");return u.result}async simulateTransaction(e,t,r){if("message"in e){let L=e.serialize(),z=D.from(L).toString("base64");if(Array.isArray(t)||r!==void 0)throw new Error("Invalid arguments");let W=t||{};W.encoding="base64","commitment"in W||(W.commitment=this.commitment),t&&typeof t=="object"&&"innerInstructions"in t&&(W.innerInstructions=t.innerInstructions);let J=[z,W],le=await this._rpcRequest("simulateTransaction",J),ee=P(le,Vs);if("error"in ee)throw new Error("failed to simulate transaction: "+ee.error.message);return ee.result}let n;if(e instanceof Z){let R=e;n=new Z,n.feePayer=R.feePayer,n.instructions=e.instructions,n.nonceInfo=R.nonceInfo,n.signatures=R.signatures}else n=Z.populate(e),n._message=n._json=void 0;if(t!==void 0&&!Array.isArray(t))throw new Error("Invalid arguments");let i=t;if(n.nonceInfo&&i)n.sign(...i);else{let R=this._disableBlockhashCaching;for(;;){let L=await this._blockhashWithExpiryBlockHeight(R);if(n.lastValidBlockHeight=L.lastValidBlockHeight,n.recentBlockhash=L.blockhash,!i)break;if(n.sign(...i),!n.signature)throw new Error("!signature");let z=n.signature.toString("base64");if(!this._blockhashInfo.simulatedSignatures.includes(z)&&!this._blockhashInfo.transactionSignatures.includes(z)){this._blockhashInfo.simulatedSignatures.push(z);break}else R=!0}}let u=n._compile(),l=u.serialize(),I=n._serialize(l).toString("base64"),B={encoding:"base64",commitment:this.commitment};if(r){let R=(Array.isArray(r)?r:u.nonProgramIds()).map(L=>L.toBase58());B.accounts={encoding:"base64",addresses:R}}i&&(B.sigVerify=!0),t&&typeof t=="object"&&"innerInstructions"in t&&(B.innerInstructions=t.innerInstructions);let x=[I,B],N=await this._rpcRequest("simulateTransaction",x),_=P(N,Vs);if("error"in _){let R;if("data"in _.error&&(R=_.error.data.logs,R&&Array.isArray(R))){let L=`
|
|
`,z=L+R.join(L);console.error(_.error.message,z)}throw new Gt({action:"simulate",signature:"",transactionMessage:_.error.message,logs:R})}return _.result}async sendTransaction(e,t,r){if("version"in e){if(t&&Array.isArray(t))throw new Error("Invalid arguments");let u=e.serialize();return await this.sendRawTransaction(u,t)}if(t===void 0||!Array.isArray(t))throw new Error("Invalid arguments");let n=t;if(e.nonceInfo)e.sign(...n);else{let u=this._disableBlockhashCaching;for(;;){let l=await this._blockhashWithExpiryBlockHeight(u);if(e.lastValidBlockHeight=l.lastValidBlockHeight,e.recentBlockhash=l.blockhash,e.sign(...n),!e.signature)throw new Error("!signature");let m=e.signature.toString("base64");if(this._blockhashInfo.transactionSignatures.includes(m))u=!0;else{this._blockhashInfo.transactionSignatures.push(m);break}}}let i=e.serialize();return await this.sendRawTransaction(i,r)}async sendRawTransaction(e,t){let r=H(e).toString("base64");return await this.sendEncodedTransaction(r,t)}async sendEncodedTransaction(e,t){let r={encoding:"base64"},n=t&&t.skipPreflight,i=n===!0?"processed":t&&t.preflightCommitment||this.commitment;t&&t.maxRetries!=null&&(r.maxRetries=t.maxRetries),t&&t.minContextSlot!=null&&(r.minContextSlot=t.minContextSlot),n&&(r.skipPreflight=n),i&&(r.preflightCommitment=i);let u=[e,r],l=await this._rpcRequest("sendTransaction",u),m=P(l,Ra);if("error"in m){let I;throw"data"in m.error&&(I=m.error.data.logs),new Gt({action:n?"send":"simulate",signature:"",transactionMessage:m.error.message,logs:I})}return m.result}_wsOnOpen(){this._rpcWebSocketConnected=!0,this._rpcWebSocketHeartbeat=setInterval(()=>{(async()=>{try{await this._rpcWebSocket.notify("ping")}catch{}})()},5e3),this._updateSubscriptions()}_wsOnError(e){this._rpcWebSocketConnected=!1,console.error("ws error:",e.message)}_wsOnClose(e){if(this._rpcWebSocketConnected=!1,this._rpcWebSocketGeneration=(this._rpcWebSocketGeneration+1)%Number.MAX_SAFE_INTEGER,this._rpcWebSocketIdleTimeout&&(clearTimeout(this._rpcWebSocketIdleTimeout),this._rpcWebSocketIdleTimeout=null),this._rpcWebSocketHeartbeat&&(clearInterval(this._rpcWebSocketHeartbeat),this._rpcWebSocketHeartbeat=null),e===1e3){this._updateSubscriptions();return}this._subscriptionCallbacksByServerSubscriptionId={},Object.entries(this._subscriptionsByHash).forEach(([t,r])=>{this._setSubscription(t,{...r,state:"pending"})})}_setSubscription(e,t){let r=this._subscriptionsByHash[e]?.state;if(this._subscriptionsByHash[e]=t,r!==t.state){let n=this._subscriptionStateChangeCallbacksByHash[e];n&&n.forEach(i=>{try{i(t.state)}catch{}})}}_onSubscriptionStateChange(e,t){let r=this._subscriptionHashByClientSubscriptionId[e];if(r==null)return()=>{};let n=this._subscriptionStateChangeCallbacksByHash[r]||=new Set;return n.add(t),()=>{n.delete(t),n.size===0&&delete this._subscriptionStateChangeCallbacksByHash[r]}}async _updateSubscriptions(){if(Object.keys(this._subscriptionsByHash).length===0){this._rpcWebSocketConnected&&(this._rpcWebSocketConnected=!1,this._rpcWebSocketIdleTimeout=setTimeout(()=>{this._rpcWebSocketIdleTimeout=null;try{this._rpcWebSocket.close()}catch(r){r instanceof Error&&console.log(`Error when closing socket connection: ${r.message}`)}},500));return}if(this._rpcWebSocketIdleTimeout!==null&&(clearTimeout(this._rpcWebSocketIdleTimeout),this._rpcWebSocketIdleTimeout=null,this._rpcWebSocketConnected=!0),!this._rpcWebSocketConnected){this._rpcWebSocket.connect();return}let e=this._rpcWebSocketGeneration,t=()=>e===this._rpcWebSocketGeneration;await Promise.all(Object.keys(this._subscriptionsByHash).map(async r=>{let n=this._subscriptionsByHash[r];if(n!==void 0)switch(n.state){case"pending":case"unsubscribed":if(n.callbacks.size===0){delete this._subscriptionsByHash[r],n.state==="unsubscribed"&&delete this._subscriptionCallbacksByServerSubscriptionId[n.serverSubscriptionId],await this._updateSubscriptions();return}await(async()=>{let{args:i,method:u}=n;try{this._setSubscription(r,{...n,state:"subscribing"});let l=await this._rpcWebSocket.call(u,i);this._setSubscription(r,{...n,serverSubscriptionId:l,state:"subscribed"}),this._subscriptionCallbacksByServerSubscriptionId[l]=n.callbacks,await this._updateSubscriptions()}catch(l){if(console.error(`Received ${l instanceof Error?"":"JSON-RPC "}error calling \`${u}\``,{args:i,error:l}),!t())return;this._setSubscription(r,{...n,state:"pending"}),await this._updateSubscriptions()}})();break;case"subscribed":n.callbacks.size===0&&await(async()=>{let{serverSubscriptionId:i,unsubscribeMethod:u}=n;if(this._subscriptionsAutoDisposedByRpc.has(i))this._subscriptionsAutoDisposedByRpc.delete(i);else{this._setSubscription(r,{...n,state:"unsubscribing"}),this._setSubscription(r,{...n,state:"unsubscribing"});try{await this._rpcWebSocket.call(u,[i])}catch(l){if(l instanceof Error&&console.error(`${u} error:`,l.message),!t())return;this._setSubscription(r,{...n,state:"subscribed"}),await this._updateSubscriptions();return}}this._setSubscription(r,{...n,state:"unsubscribed"}),await this._updateSubscriptions()})();break}}))}_handleServerNotification(e,t){let r=this._subscriptionCallbacksByServerSubscriptionId[e];r!==void 0&&r.forEach(n=>{try{n(...t)}catch(i){console.error(i)}})}_wsOnAccountNotification(e){let{result:t,subscription:r}=P(e,Zo);this._handleServerNotification(r,[t.value,t.context])}_makeSubscription(e,t){let r=this._nextClientSubscriptionId++,n=Ds([e.method,t]),i=this._subscriptionsByHash[n];return i===void 0?this._subscriptionsByHash[n]={...e,args:t,callbacks:new Set([e.callback]),state:"pending"}:i.callbacks.add(e.callback),this._subscriptionHashByClientSubscriptionId[r]=n,this._subscriptionDisposeFunctionsByClientSubscriptionId[r]=async()=>{delete this._subscriptionDisposeFunctionsByClientSubscriptionId[r],delete this._subscriptionHashByClientSubscriptionId[r];let u=this._subscriptionsByHash[n];X(u!==void 0,`Could not find a \`Subscription\` when tearing down client subscription #${r}`),u.callbacks.delete(e.callback),await this._updateSubscriptions()},this._updateSubscriptions(),r}onAccountChange(e,t,r){let{commitment:n,config:i}=oe(r),u=this._buildArgs([e.toBase58()],n||this._commitment||"finalized","base64",i);return this._makeSubscription({callback:t,method:"accountSubscribe",unsubscribeMethod:"accountUnsubscribe"},u)}async removeAccountChangeListener(e){await this._unsubscribeClientSubscription(e,"account change")}_wsOnProgramAccountNotification(e){let{result:t,subscription:r}=P(e,Qo);this._handleServerNotification(r,[{accountId:t.value.pubkey,accountInfo:t.value.account},t.context])}onProgramAccountChange(e,t,r,n){let{commitment:i,config:u}=oe(r),l=this._buildArgs([e.toBase58()],i||this._commitment||"finalized","base64",u||(n?{filters:Fs(n)}:void 0));return this._makeSubscription({callback:t,method:"programSubscribe",unsubscribeMethod:"programUnsubscribe"},l)}async removeProgramAccountChangeListener(e){await this._unsubscribeClientSubscription(e,"program account change")}onLogs(e,t,r){let n=this._buildArgs([typeof e=="object"?{mentions:[e.toString()]}:e],r||this._commitment||"finalized");return this._makeSubscription({callback:t,method:"logsSubscribe",unsubscribeMethod:"logsUnsubscribe"},n)}async removeOnLogsListener(e){await this._unsubscribeClientSubscription(e,"logs")}_wsOnLogsNotification(e){let{result:t,subscription:r}=P(e,Ea);this._handleServerNotification(r,[t.value,t.context])}_wsOnSlotNotification(e){let{result:t,subscription:r}=P(e,ta);this._handleServerNotification(r,[t])}onSlotChange(e){return this._makeSubscription({callback:e,method:"slotSubscribe",unsubscribeMethod:"slotUnsubscribe"},[])}async removeSlotChangeListener(e){await this._unsubscribeClientSubscription(e,"slot change")}_wsOnSlotUpdatesNotification(e){let{result:t,subscription:r}=P(e,na);this._handleServerNotification(r,[t])}onSlotUpdate(e){return this._makeSubscription({callback:e,method:"slotsUpdatesSubscribe",unsubscribeMethod:"slotsUpdatesUnsubscribe"},[])}async removeSlotUpdateListener(e){await this._unsubscribeClientSubscription(e,"slot update")}async _unsubscribeClientSubscription(e,t){let r=this._subscriptionDisposeFunctionsByClientSubscriptionId[e];r?await r():console.warn(`Ignored unsubscribe request because an active subscription with id \`${e}\` for '${t}' events could not be found.`)}_buildArgs(e,t,r,n){let i=t||this._commitment;if(i||r||n){let u={};r&&(u.encoding=r),i&&(u.commitment=i),n&&(u=Object.assign(u,n)),e.push(u)}return e}_buildArgsAtLeastConfirmed(e,t,r,n){let i=t||this._commitment;if(i&&!["confirmed","finalized"].includes(i))throw new Error("Using Connection with default commitment: `"+this._commitment+"`, but method requires at least `confirmed`");return this._buildArgs(e,t,r,n)}_wsOnSignatureNotification(e){let{result:t,subscription:r}=P(e,sa);t.value!=="receivedSignature"&&this._subscriptionsAutoDisposedByRpc.add(r),this._handleServerNotification(r,t.value==="receivedSignature"?[{type:"received"},t.context]:[{type:"status",result:t.value},t.context])}onSignature(e,t,r){let n=this._buildArgs([e],r||this._commitment||"finalized"),i=this._makeSubscription({callback:(u,l)=>{if(u.type==="status"){t(u.result,l);try{this.removeSignatureListener(i)}catch{}}},method:"signatureSubscribe",unsubscribeMethod:"signatureUnsubscribe"},n);return i}onSignatureWithOptions(e,t,r){let{commitment:n,...i}={...r,commitment:r&&r.commitment||this._commitment||"finalized"},u=this._buildArgs([e],n,void 0,i),l=this._makeSubscription({callback:(m,I)=>{t(m,I);try{this.removeSignatureListener(l)}catch{}},method:"signatureSubscribe",unsubscribeMethod:"signatureUnsubscribe"},u);return l}async removeSignatureListener(e){await this._unsubscribeClientSubscription(e,"signature result")}_wsOnRootNotification(e){let{result:t,subscription:r}=P(e,ia);this._handleServerNotification(r,[t])}onRootChange(e){return this._makeSubscription({callback:e,method:"rootSubscribe",unsubscribeMethod:"rootUnsubscribe"},[])}async removeRootChangeListener(e){await this._unsubscribeClientSubscription(e,"root change")}},Nt=class{constructor(e){this._keypair=void 0,this._keypair=e??Ps()}static generate(){return new Nt(Ps())}static fromSecretKey(e,t){if(e.byteLength!==64)throw new Error("bad secret key size");let r=e.slice(32,64);if(!t||!t.skipValidation){let n=e.slice(0,32),i=qr(n);for(let u=0;u<32;u++)if(r[u]!==i[u])throw new Error("provided secretKey is invalid")}return new Nt({publicKey:r,secretKey:e})}static fromSeed(e){let t=qr(e),r=new Uint8Array(64);return r.set(e),r.set(t,32),new Nt({publicKey:t,secretKey:r})}get publicKey(){return new M(this._keypair.publicKey)}get secretKey(){return new Uint8Array(this._keypair.secretKey)}},It=Object.freeze({CreateLookupTable:{index:0,layout:y.struct([y.u32("instruction"),jt("recentSlot"),y.u8("bumpSeed")])},FreezeLookupTable:{index:1,layout:y.struct([y.u32("instruction")])},ExtendLookupTable:{index:2,layout:y.struct([y.u32("instruction"),jt(),y.seq(G(),y.offset(y.u32(),-8),"addresses")])},DeactivateLookupTable:{index:3,layout:y.struct([y.u32("instruction")])},CloseLookupTable:{index:4,layout:y.struct([y.u32("instruction")])}}),Js=class{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);let r=y.u32("instruction").decode(e.data),n;for(let[i,u]of Object.entries(It))if(u.index==r){n=i;break}if(!n)throw new Error("Invalid Instruction. Should be a LookupTable Instruction");return n}static decodeCreateLookupTable(e){this.checkProgramId(e.programId),this.checkKeysLength(e.keys,4);let{recentSlot:t}=re(It.CreateLookupTable,e.data);return{authority:e.keys[1].pubkey,payer:e.keys[2].pubkey,recentSlot:Number(t)}}static decodeExtendLookupTable(e){if(this.checkProgramId(e.programId),e.keys.length<2)throw new Error(`invalid instruction; found ${e.keys.length} keys, expected at least 2`);let{addresses:t}=re(It.ExtendLookupTable,e.data);return{lookupTable:e.keys[0].pubkey,authority:e.keys[1].pubkey,payer:e.keys.length>2?e.keys[2].pubkey:void 0,addresses:t.map(r=>new M(r))}}static decodeCloseLookupTable(e){return this.checkProgramId(e.programId),this.checkKeysLength(e.keys,3),{lookupTable:e.keys[0].pubkey,authority:e.keys[1].pubkey,recipient:e.keys[2].pubkey}}static decodeFreezeLookupTable(e){return this.checkProgramId(e.programId),this.checkKeysLength(e.keys,2),{lookupTable:e.keys[0].pubkey,authority:e.keys[1].pubkey}}static decodeDeactivateLookupTable(e){return this.checkProgramId(e.programId),this.checkKeysLength(e.keys,2),{lookupTable:e.keys[0].pubkey,authority:e.keys[1].pubkey}}static checkProgramId(e){if(!e.equals(Jr.programId))throw new Error("invalid instruction; programId is not AddressLookupTable Program")}static checkKeysLength(e,t){if(e.length<t)throw new Error(`invalid instruction; found ${e.length} keys, expected at least ${t}`)}},Jr=class{constructor(){}static createLookupTable(e){let[t,r]=M.findProgramAddressSync([e.authority.toBuffer(),(0,lr.toBufferLE)(BigInt(e.recentSlot),8)],this.programId),n=It.CreateLookupTable,i=j(n,{recentSlot:BigInt(e.recentSlot),bumpSeed:r}),u=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:Je.programId,isSigner:!1,isWritable:!1}];return[new ne({programId:this.programId,keys:u,data:i}),t]}static freezeLookupTable(e){let t=It.FreezeLookupTable,r=j(t),n=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new ne({programId:this.programId,keys:n,data:r})}static extendLookupTable(e){let t=It.ExtendLookupTable,r=j(t,{addresses:e.addresses.map(i=>i.toBytes())}),n=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return e.payer&&n.push({pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:Je.programId,isSigner:!1,isWritable:!1}),new ne({programId:this.programId,keys:n,data:r})}static deactivateLookupTable(e){let t=It.DeactivateLookupTable,r=j(t),n=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new ne({programId:this.programId,keys:n,data:r})}static closeLookupTable(e){let t=It.CloseLookupTable,r=j(t),n=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.recipient,isSigner:!1,isWritable:!0}];return new ne({programId:this.programId,keys:n,data:r})}};Jr.programId=new M("AddressLookupTab1e1111111111111111111111111");var Ys=class{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);let r=y.u8("instruction").decode(e.data),n;for(let[i,u]of Object.entries(bt))if(u.index==r){n=i;break}if(!n)throw new Error("Instruction type incorrect; not a ComputeBudgetInstruction");return n}static decodeRequestUnits(e){this.checkProgramId(e.programId);let{units:t,additionalFee:r}=re(bt.RequestUnits,e.data);return{units:t,additionalFee:r}}static decodeRequestHeapFrame(e){this.checkProgramId(e.programId);let{bytes:t}=re(bt.RequestHeapFrame,e.data);return{bytes:t}}static decodeSetComputeUnitLimit(e){this.checkProgramId(e.programId);let{units:t}=re(bt.SetComputeUnitLimit,e.data);return{units:t}}static decodeSetComputeUnitPrice(e){this.checkProgramId(e.programId);let{microLamports:t}=re(bt.SetComputeUnitPrice,e.data);return{microLamports:t}}static checkProgramId(e){if(!e.equals(Yr.programId))throw new Error("invalid instruction; programId is not ComputeBudgetProgram")}},bt=Object.freeze({RequestUnits:{index:0,layout:y.struct([y.u8("instruction"),y.u32("units"),y.u32("additionalFee")])},RequestHeapFrame:{index:1,layout:y.struct([y.u8("instruction"),y.u32("bytes")])},SetComputeUnitLimit:{index:2,layout:y.struct([y.u8("instruction"),y.u32("units")])},SetComputeUnitPrice:{index:3,layout:y.struct([y.u8("instruction"),jt("microLamports")])}}),Yr=class{constructor(){}static requestUnits(e){let t=bt.RequestUnits,r=j(t,e);return new ne({keys:[],programId:this.programId,data:r})}static requestHeapFrame(e){let t=bt.RequestHeapFrame,r=j(t,e);return new ne({keys:[],programId:this.programId,data:r})}static setComputeUnitLimit(e){let t=bt.SetComputeUnitLimit,r=j(t,e);return new ne({keys:[],programId:this.programId,data:r})}static setComputeUnitPrice(e){let t=bt.SetComputeUnitPrice,r=j(t,{microLamports:BigInt(e.microLamports)});return new ne({keys:[],programId:this.programId,data:r})}};Yr.programId=new M("ComputeBudget111111111111111111111111111111");var Zs=64,Xs=32,Qs=64,ei=y.struct([y.u8("numSignatures"),y.u8("padding"),y.u16("signatureOffset"),y.u16("signatureInstructionIndex"),y.u16("publicKeyOffset"),y.u16("publicKeyInstructionIndex"),y.u16("messageDataOffset"),y.u16("messageDataSize"),y.u16("messageInstructionIndex")]),ur=class{constructor(){}static createInstructionWithPublicKey(e){let{publicKey:t,message:r,signature:n,instructionIndex:i}=e;X(t.length===Xs,`Public Key must be ${Xs} bytes but received ${t.length} bytes`),X(n.length===Qs,`Signature must be ${Qs} bytes but received ${n.length} bytes`);let u=ei.span,l=u+t.length,m=l+n.length,I=1,B=D.alloc(m+r.length),x=i??65535;return ei.encode({numSignatures:I,padding:0,signatureOffset:l,signatureInstructionIndex:x,publicKeyOffset:u,publicKeyInstructionIndex:x,messageDataOffset:m,messageDataSize:r.length,messageInstructionIndex:x},B),B.fill(t,u),B.fill(n,l),B.fill(r,m),new ne({keys:[],programId:ur.programId,data:B})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:r,instructionIndex:n}=e;X(t.length===Zs,`Private key must be ${Zs} bytes but received ${t.length} bytes`);try{let i=Nt.fromSecretKey(t),u=i.publicKey.toBytes(),l=Yn(r,i.secretKey);return this.createInstructionWithPublicKey({publicKey:u,message:r,signature:l,instructionIndex:n})}catch(i){throw new Error(`Error creating instruction; ${i}`)}}};ur.programId=new M("Ed25519SigVerify111111111111111111111111111");var Pa=(a,e)=>{let t=dr.sign(a,e);return[t.toCompactRawBytes(),t.recovery]};dr.utils.isValidPrivateKey;var Ta=dr.getPublicKey,ti=32,qn=20,ri=64,Ca=11,Un=y.struct([y.u8("numSignatures"),y.u16("signatureOffset"),y.u8("signatureInstructionIndex"),y.u16("ethAddressOffset"),y.u8("ethAddressInstructionIndex"),y.u16("messageDataOffset"),y.u16("messageDataSize"),y.u8("messageInstructionIndex"),y.blob(20,"ethAddress"),y.blob(64,"signature"),y.u8("recoveryId")]),Ot=class{constructor(){}static publicKeyToEthAddress(e){X(e.length===ri,`Public key must be ${ri} bytes but received ${e.length} bytes`);try{return D.from(_n(H(e))).slice(-qn)}catch(t){throw new Error(`Error constructing Ethereum address: ${t}`)}}static createInstructionWithPublicKey(e){let{publicKey:t,message:r,signature:n,recoveryId:i,instructionIndex:u}=e;return Ot.createInstructionWithEthAddress({ethAddress:Ot.publicKeyToEthAddress(t),message:r,signature:n,recoveryId:i,instructionIndex:u})}static createInstructionWithEthAddress(e){let{ethAddress:t,message:r,signature:n,recoveryId:i,instructionIndex:u=0}=e,l;typeof t=="string"?t.startsWith("0x")?l=D.from(t.substr(2),"hex"):l=D.from(t,"hex"):l=t,X(l.length===qn,`Address must be ${qn} bytes but received ${l.length} bytes`);let m=1+Ca,I=m,B=m+l.length,x=B+n.length+1,N=1,_=D.alloc(Un.span+r.length);return Un.encode({numSignatures:N,signatureOffset:B,signatureInstructionIndex:u,ethAddressOffset:I,ethAddressInstructionIndex:u,messageDataOffset:x,messageDataSize:r.length,messageInstructionIndex:u,signature:H(n),ethAddress:H(l),recoveryId:i},_),_.fill(H(r),Un.span),new ne({keys:[],programId:Ot.programId,data:_})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:r,instructionIndex:n}=e;X(t.length===ti,`Private key must be ${ti} bytes but received ${t.length} bytes`);try{let i=H(t),u=Ta(i,!1).slice(1),l=D.from(_n(H(r))),[m,I]=Pa(l,i);return this.createInstructionWithPublicKey({publicKey:u,message:r,signature:m,recoveryId:I,instructionIndex:n})}catch(i){throw new Error(`Error creating instruction; ${i}`)}}};Ot.programId=new M("KeccakSecp256k11111111111111111111111111111");var Ai,za=new M("StakeConfig11111111111111111111111111111111"),jn=class{constructor(e,t){this.staker=void 0,this.withdrawer=void 0,this.staker=e,this.withdrawer=t}},Jt=class{constructor(e,t,r){this.unixTimestamp=void 0,this.epoch=void 0,this.custodian=void 0,this.unixTimestamp=e,this.epoch=t,this.custodian=r}};Ai=Jt;Jt.default=new Ai(0,0,M.default);var ni=class{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);let r=y.u32("instruction").decode(e.data),n;for(let[i,u]of Object.entries(Xe))if(u.index==r){n=i;break}if(!n)throw new Error("Instruction type incorrect; not a StakeInstruction");return n}static decodeInitialize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{authorized:t,lockup:r}=re(Xe.Initialize,e.data);return{stakePubkey:e.keys[0].pubkey,authorized:new jn(new M(t.staker),new M(t.withdrawer)),lockup:new Jt(r.unixTimestamp,r.epoch,new M(r.custodian))}}static decodeDelegate(e){return this.checkProgramId(e.programId),this.checkKeyLength(e.keys,6),re(Xe.Delegate,e.data),{stakePubkey:e.keys[0].pubkey,votePubkey:e.keys[1].pubkey,authorizedPubkey:e.keys[5].pubkey}}static decodeAuthorize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{newAuthorized:t,stakeAuthorizationType:r}=re(Xe.Authorize,e.data),n={stakePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[2].pubkey,newAuthorizedPubkey:new M(t),stakeAuthorizationType:{index:r}};return e.keys.length>3&&(n.custodianPubkey=e.keys[3].pubkey),n}static decodeAuthorizeWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);let{newAuthorized:t,stakeAuthorizationType:r,authoritySeed:n,authorityOwner:i}=re(Xe.AuthorizeWithSeed,e.data),u={stakePubkey:e.keys[0].pubkey,authorityBase:e.keys[1].pubkey,authoritySeed:n,authorityOwner:new M(i),newAuthorizedPubkey:new M(t),stakeAuthorizationType:{index:r}};return e.keys.length>3&&(u.custodianPubkey=e.keys[3].pubkey),u}static decodeSplit(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{lamports:t}=re(Xe.Split,e.data);return{stakePubkey:e.keys[0].pubkey,splitStakePubkey:e.keys[1].pubkey,authorizedPubkey:e.keys[2].pubkey,lamports:t}}static decodeMerge(e){return this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3),re(Xe.Merge,e.data),{stakePubkey:e.keys[0].pubkey,sourceStakePubKey:e.keys[1].pubkey,authorizedPubkey:e.keys[4].pubkey}}static decodeWithdraw(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,5);let{lamports:t}=re(Xe.Withdraw,e.data),r={stakePubkey:e.keys[0].pubkey,toPubkey:e.keys[1].pubkey,authorizedPubkey:e.keys[4].pubkey,lamports:t};return e.keys.length>5&&(r.custodianPubkey=e.keys[5].pubkey),r}static decodeDeactivate(e){return this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3),re(Xe.Deactivate,e.data),{stakePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[2].pubkey}}static checkProgramId(e){if(!e.equals(hr.programId))throw new Error("invalid instruction; programId is not StakeProgram")}static checkKeyLength(e,t){if(e.length<t)throw new Error(`invalid instruction; found ${e.length} keys, expected at least ${t}`)}},Xe=Object.freeze({Initialize:{index:0,layout:y.struct([y.u32("instruction"),Hi(),Gi()])},Authorize:{index:1,layout:y.struct([y.u32("instruction"),G("newAuthorized"),y.u32("stakeAuthorizationType")])},Delegate:{index:2,layout:y.struct([y.u32("instruction")])},Split:{index:3,layout:y.struct([y.u32("instruction"),y.ns64("lamports")])},Withdraw:{index:4,layout:y.struct([y.u32("instruction"),y.ns64("lamports")])},Deactivate:{index:5,layout:y.struct([y.u32("instruction")])},Merge:{index:7,layout:y.struct([y.u32("instruction")])},AuthorizeWithSeed:{index:8,layout:y.struct([y.u32("instruction"),G("newAuthorized"),y.u32("stakeAuthorizationType"),Ct("authoritySeed"),G("authorityOwner")])}}),Ac=Object.freeze({Staker:{index:0},Withdrawer:{index:1}}),hr=class{constructor(){}static initialize(e){let{stakePubkey:t,authorized:r,lockup:n}=e,i=n||Jt.default,u=Xe.Initialize,l=j(u,{authorized:{staker:H(r.staker.toBuffer()),withdrawer:H(r.withdrawer.toBuffer())},lockup:{unixTimestamp:i.unixTimestamp,epoch:i.epoch,custodian:H(i.custodian.toBuffer())}}),m={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:or,isSigner:!1,isWritable:!1}],programId:this.programId,data:l};return new ne(m)}static createAccountWithSeed(e){let t=new Z;t.add(Je.createAccountWithSeed({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,basePubkey:e.basePubkey,seed:e.seed,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:r,authorized:n,lockup:i}=e;return t.add(this.initialize({stakePubkey:r,authorized:n,lockup:i}))}static createAccount(e){let t=new Z;t.add(Je.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:r,authorized:n,lockup:i}=e;return t.add(this.initialize({stakePubkey:r,authorized:n,lockup:i}))}static delegate(e){let{stakePubkey:t,authorizedPubkey:r,votePubkey:n}=e,i=Xe.Delegate,u=j(i);return new Z().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:zn,isSigner:!1,isWritable:!1},{pubkey:za,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:u})}static authorize(e){let{stakePubkey:t,authorizedPubkey:r,newAuthorizedPubkey:n,stakeAuthorizationType:i,custodianPubkey:u}=e,l=Xe.Authorize,m=j(l,{newAuthorized:H(n.toBuffer()),stakeAuthorizationType:i.index}),I=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}];return u&&I.push({pubkey:u,isSigner:!0,isWritable:!1}),new Z().add({keys:I,programId:this.programId,data:m})}static authorizeWithSeed(e){let{stakePubkey:t,authorityBase:r,authoritySeed:n,authorityOwner:i,newAuthorizedPubkey:u,stakeAuthorizationType:l,custodianPubkey:m}=e,I=Xe.AuthorizeWithSeed,B=j(I,{newAuthorized:H(u.toBuffer()),stakeAuthorizationType:l.index,authoritySeed:n,authorityOwner:H(i.toBuffer())}),x=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1},{pubkey:mt,isSigner:!1,isWritable:!1}];return m&&x.push({pubkey:m,isSigner:!0,isWritable:!1}),new Z().add({keys:x,programId:this.programId,data:B})}static splitInstruction(e){let{stakePubkey:t,authorizedPubkey:r,splitStakePubkey:n,lamports:i}=e,u=Xe.Split,l=j(u,{lamports:i});return new ne({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:l})}static split(e,t){let r=new Z;return r.add(Je.createAccount({fromPubkey:e.authorizedPubkey,newAccountPubkey:e.splitStakePubkey,lamports:t,space:this.space,programId:this.programId})),r.add(this.splitInstruction(e))}static splitWithSeed(e,t){let{stakePubkey:r,authorizedPubkey:n,splitStakePubkey:i,basePubkey:u,seed:l,lamports:m}=e,I=new Z;return I.add(Je.allocate({accountPubkey:i,basePubkey:u,seed:l,space:this.space,programId:this.programId})),t&&t>0&&I.add(Je.transfer({fromPubkey:e.authorizedPubkey,toPubkey:i,lamports:t})),I.add(this.splitInstruction({stakePubkey:r,authorizedPubkey:n,splitStakePubkey:i,lamports:m}))}static merge(e){let{stakePubkey:t,sourceStakePubKey:r,authorizedPubkey:n}=e,i=Xe.Merge,u=j(i);return new Z().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:zn,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:u})}static withdraw(e){let{stakePubkey:t,authorizedPubkey:r,toPubkey:n,lamports:i,custodianPubkey:u}=e,l=Xe.Withdraw,m=j(l,{lamports:i}),I=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:zn,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}];return u&&I.push({pubkey:u,isSigner:!0,isWritable:!1}),new Z().add({keys:I,programId:this.programId,data:m})}static deactivate(e){let{stakePubkey:t,authorizedPubkey:r}=e,n=Xe.Deactivate,i=j(n);return new Z().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:i})}};hr.programId=new M("Stake11111111111111111111111111111111111111");hr.space=200;var Jn=class{constructor(e,t,r,n){this.nodePubkey=void 0,this.authorizedVoter=void 0,this.authorizedWithdrawer=void 0,this.commission=void 0,this.nodePubkey=e,this.authorizedVoter=t,this.authorizedWithdrawer=r,this.commission=n}},si=class{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);let r=y.u32("instruction").decode(e.data),n;for(let[i,u]of Object.entries(yt))if(u.index==r){n=i;break}if(!n)throw new Error("Instruction type incorrect; not a VoteInstruction");return n}static decodeInitializeAccount(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,4);let{voteInit:t}=re(yt.InitializeAccount,e.data);return{votePubkey:e.keys[0].pubkey,nodePubkey:e.keys[3].pubkey,voteInit:new Jn(new M(t.nodePubkey),new M(t.authorizedVoter),new M(t.authorizedWithdrawer),t.commission)}}static decodeAuthorize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{newAuthorized:t,voteAuthorizationType:r}=re(yt.Authorize,e.data);return{votePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[2].pubkey,newAuthorizedPubkey:new M(t),voteAuthorizationType:{index:r}}}static decodeAuthorizeWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:t,currentAuthorityDerivedKeySeed:r,newAuthorized:n,voteAuthorizationType:i}}=re(yt.AuthorizeWithSeed,e.data);return{currentAuthorityDerivedKeyBasePubkey:e.keys[2].pubkey,currentAuthorityDerivedKeyOwnerPubkey:new M(t),currentAuthorityDerivedKeySeed:r,newAuthorizedPubkey:new M(n),voteAuthorizationType:{index:i},votePubkey:e.keys[0].pubkey}}static decodeWithdraw(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);let{lamports:t}=re(yt.Withdraw,e.data);return{votePubkey:e.keys[0].pubkey,authorizedWithdrawerPubkey:e.keys[2].pubkey,lamports:t,toPubkey:e.keys[1].pubkey}}static checkProgramId(e){if(!e.equals(Kt.programId))throw new Error("invalid instruction; programId is not VoteProgram")}static checkKeyLength(e,t){if(e.length<t)throw new Error(`invalid instruction; found ${e.length} keys, expected at least ${t}`)}},yt=Object.freeze({InitializeAccount:{index:0,layout:y.struct([y.u32("instruction"),ji()])},Authorize:{index:1,layout:y.struct([y.u32("instruction"),G("newAuthorized"),y.u32("voteAuthorizationType")])},Withdraw:{index:3,layout:y.struct([y.u32("instruction"),y.ns64("lamports")])},UpdateValidatorIdentity:{index:4,layout:y.struct([y.u32("instruction")])},AuthorizeWithSeed:{index:10,layout:y.struct([y.u32("instruction"),Ji()])}}),Bc=Object.freeze({Voter:{index:0},Withdrawer:{index:1}}),Kt=class{constructor(){}static initializeAccount(e){let{votePubkey:t,nodePubkey:r,voteInit:n}=e,i=yt.InitializeAccount,u=j(i,{voteInit:{nodePubkey:H(n.nodePubkey.toBuffer()),authorizedVoter:H(n.authorizedVoter.toBuffer()),authorizedWithdrawer:H(n.authorizedWithdrawer.toBuffer()),commission:n.commission}}),l={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:or,isSigner:!1,isWritable:!1},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:u};return new ne(l)}static createAccount(e){let t=new Z;return t.add(Je.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.votePubkey,lamports:e.lamports,space:this.space,programId:this.programId})),t.add(this.initializeAccount({votePubkey:e.votePubkey,nodePubkey:e.voteInit.nodePubkey,voteInit:e.voteInit}))}static authorize(e){let{votePubkey:t,authorizedPubkey:r,newAuthorizedPubkey:n,voteAuthorizationType:i}=e,u=yt.Authorize,l=j(u,{newAuthorized:H(n.toBuffer()),voteAuthorizationType:i.index}),m=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}];return new Z().add({keys:m,programId:this.programId,data:l})}static authorizeWithSeed(e){let{currentAuthorityDerivedKeyBasePubkey:t,currentAuthorityDerivedKeyOwnerPubkey:r,currentAuthorityDerivedKeySeed:n,newAuthorizedPubkey:i,voteAuthorizationType:u,votePubkey:l}=e,m=yt.AuthorizeWithSeed,I=j(m,{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:H(r.toBuffer()),currentAuthorityDerivedKeySeed:n,newAuthorized:H(i.toBuffer()),voteAuthorizationType:u.index}}),B=[{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:mt,isSigner:!1,isWritable:!1},{pubkey:t,isSigner:!0,isWritable:!1}];return new Z().add({keys:B,programId:this.programId,data:I})}static withdraw(e){let{votePubkey:t,authorizedWithdrawerPubkey:r,lamports:n,toPubkey:i}=e,u=yt.Withdraw,l=j(u,{lamports:n}),m=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}];return new Z().add({keys:m,programId:this.programId,data:l})}static safeWithdraw(e,t,r){if(e.lamports>t-r)throw new Error("Withdraw will leave vote account with insufficient funds.");return Kt.withdraw(e)}static updateValidatorIdentity(e){let{votePubkey:t,authorizedWithdrawerPubkey:r,nodePubkey:n}=e,i=yt.UpdateValidatorIdentity,u=j(i),l=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}];return new Z().add({keys:l,programId:this.programId,data:u})}};Kt.programId=new M("Vote111111111111111111111111111111111111111");Kt.space=3762;var Na=new M("Va1idator1nfo111111111111111111111111111111"),Oa=A({name:E(),website:$(E()),details:$(E()),iconUrl:$(E()),keybaseUsername:$(E())}),Zr=class{constructor(e,t){this.key=void 0,this.info=void 0,this.key=e,this.info=t}static fromConfigData(e){let t=[...e];if(it(t)!==2)return null;let n=[];for(let i=0;i<2;i++){let u=new M(ot(t,0,wt)),l=pt(t)===1;n.push({publicKey:u,isSigner:l})}if(n[0].publicKey.equals(Na)&&n[1].isSigner){let i=Ct().decode(D.from(t)),u=JSON.parse(i);return Pn(u,Oa),new Zr(n[1].publicKey,u)}return null}},Lc=new M("Vote111111111111111111111111111111111111111"),Ka=y.struct([G("nodePubkey"),G("authorizedWithdrawer"),y.u8("commission"),y.nu64(),y.seq(y.struct([y.nu64("slot"),y.u32("confirmationCount")]),y.offset(y.u32(),-8),"votes"),y.u8("rootSlotValid"),y.nu64("rootSlot"),y.nu64(),y.seq(y.struct([y.nu64("epoch"),G("authorizedVoter")]),y.offset(y.u32(),-8),"authorizedVoters"),y.struct([y.seq(y.struct([G("authorizedPubkey"),y.nu64("epochOfLastAuthorizedSwitch"),y.nu64("targetEpoch")]),32,"buf"),y.nu64("idx"),y.u8("isEmpty")],"priorVoters"),y.nu64(),y.seq(y.struct([y.nu64("epoch"),y.nu64("credits"),y.nu64("prevCredits")]),y.offset(y.u32(),-8),"epochCredits"),y.struct([y.nu64("slot"),y.nu64("timestamp")],"lastTimestamp")]),Xr=class{constructor(e){this.nodePubkey=void 0,this.authorizedWithdrawer=void 0,this.commission=void 0,this.rootSlot=void 0,this.votes=void 0,this.authorizedVoters=void 0,this.priorVoters=void 0,this.epochCredits=void 0,this.lastTimestamp=void 0,this.nodePubkey=e.nodePubkey,this.authorizedWithdrawer=e.authorizedWithdrawer,this.commission=e.commission,this.rootSlot=e.rootSlot,this.votes=e.votes,this.authorizedVoters=e.authorizedVoters,this.priorVoters=e.priorVoters,this.epochCredits=e.epochCredits,this.lastTimestamp=e.lastTimestamp}static fromAccountData(e){let r=Ka.decode(H(e),4),n=r.rootSlot;return r.rootSlotValid||(n=null),new Xr({nodePubkey:new M(r.nodePubkey),authorizedWithdrawer:new M(r.authorizedWithdrawer),commission:r.commission,votes:r.votes,rootSlot:n,authorizedVoters:r.authorizedVoters.map(Wa),priorVoters:qa(r.priorVoters),epochCredits:r.epochCredits,lastTimestamp:r.lastTimestamp})}};function Wa({authorizedVoter:a,epoch:e}){return{epoch:e,authorizedVoter:new M(a)}}function ii({authorizedPubkey:a,epochOfLastAuthorizedSwitch:e,targetEpoch:t}){return{authorizedPubkey:new M(a),epochOfLastAuthorizedSwitch:e,targetEpoch:t}}function qa({buf:a,idx:e,isEmpty:t}){return t?[]:[...a.slice(e+1).map(ii),...a.slice(0,e).map(ii)]}var oi={http:{devnet:"http://api.devnet.solana.com",testnet:"http://api.testnet.solana.com","mainnet-beta":"http://api.mainnet-beta.solana.com/"},https:{devnet:"https://api.devnet.solana.com",testnet:"https://api.testnet.solana.com","mainnet-beta":"https://api.mainnet-beta.solana.com/"}};function Rc(a,e){let t=e===!1?"http":"https";if(!a)return oi[t].devnet;let r=oi[t][a];if(!r)throw new Error(`Unknown ${t} cluster: ${a}`);return r}async function xc(a,e,t,r){let n,i;t&&Object.prototype.hasOwnProperty.call(t,"lastValidBlockHeight")||t&&Object.prototype.hasOwnProperty.call(t,"nonceValue")?(n=t,i=r):i=t;let u=i&&{skipPreflight:i.skipPreflight,preflightCommitment:i.preflightCommitment||i.commitment,minContextSlot:i.minContextSlot},l=await a.sendRawTransaction(e,u),m=i&&i.commitment,B=(await(n?a.confirmTransaction(n,m):a.confirmTransaction(l,m))).value;if(B.err)throw l!=null?new Gt({action:u?.skipPreflight?"send":"simulate",signature:l,transactionMessage:`Status: (${JSON.stringify(B)})`}):new Error(`Raw transaction ${l} failed (${JSON.stringify(B)})`);return l}var Ec=1e9;export{Ur as a,Cs as b,Wr as c,$i as d,wt as e,M as f,Ns as g,mc as h,zt as i,Zn as j,Dr as k,$r as l,Fr as m,Tt as n,Vt as o,lt as p,_t as q,fi as r,St as s,ne as t,Z as u,Vr as v,Hr as w,mt as x,bc as y,wc as z,Cn as A,or as B,kc as C,vc as D,Sc as E,zn as F,Gt as G,Ic as H,O as I,Os as J,eo as K,Ks as L,ar as M,Ws as N,ae as O,Je as P,At as Q,_c as R,qs as S,$n as T,Gr as U,po as V,js as W,Nt as X,It as Y,Js as Z,Jr as _,Ys as $,bt as aa,Yr as ba,ur as ca,Ot as da,za as ea,jn as fa,Jt as ga,ni as ha,Xe as ia,Ac as ja,hr as ka,Jn as la,si as ma,Bc as na,Kt as oa,Na as pa,Zr as qa,Lc as ra,Xr as sa,Rc as ta,xc as ua,Ec as va};
|
|
|
|
window.inOKXExtension = true;
|
|
window.inMiniApp = false;
|
|
window.ASSETS_BUILD_TYPE = "publish";
|
|
|
|
//# sourceMappingURL=chunk-57GDHD25.js.map
|