@stakekit/widget 0.0.290 → 0.0.291
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/{assets-DvEv_w-P.js → assets-H3qs-BfM.js} +1 -1
- package/dist/bundle/{cardano-connector-Cqj1z0wD.js → cardano-connector-C1YrKgp8.js} +2 -2
- package/dist/bundle/{configured-chains-Nn1qeOjm.js → configured-chains-CljV1eCV.js} +1 -1
- package/dist/bundle/{cosmos-connector-meta-BMa49Bqn.js → cosmos-connector-meta-CogU-5R3.js} +1 -1
- package/dist/bundle/index.bundle.js +17718 -17703
- package/dist/bundle/{ledger-connector-cdqjHR7O.js → ledger-connector-PwjsEMH_.js} +16 -16
- package/dist/bundle/{network-BvWfFLMi.js → network-rRxrzik9.js} +1 -1
- package/dist/bundle/{solana-connector-t7ro7CGZ.js → solana-connector-mwCnoTC6.js} +3 -3
- package/dist/bundle/{stellar-connector-CGTk18nF.js → stellar-connector-CIkU0qDy.js} +2 -2
- package/dist/bundle/{substrate-connector-Blu0Fmlx.js → substrate-connector-BtpGbum5.js} +1 -1
- package/dist/bundle/{ton-connector-D_6F9QzE.js → ton-connector-B9Rb8DpG.js} +3 -3
- package/dist/bundle/{transaction-nCW9pp-W.js → transaction-BU8gNx_-.js} +3 -3
- package/dist/bundle/{transaction-DFK_HUua.js → transaction-C5Rdik4M.js} +22 -22
- package/dist/bundle/transaction-C6SgGYH0.js +23 -0
- package/dist/bundle/{transaction-Dd1bxz-u.js → transaction-D8vYa3xG.js} +9 -9
- package/dist/bundle/{tron-connector-CNS7QrN7.js → tron-connector-feSoCE1Z.js} +13 -13
- package/dist/bundle/{utils-B2hhTK5t.js → utils-B5UkNjd3.js} +1 -1
- package/dist/bundle/{wallet-manager-xXCqWo2v.js → wallet-manager-iwdzlSwY.js} +34 -34
- package/dist/package/{assets-CCANldg9.js → assets-DLmJ26y-.js} +1 -1
- package/dist/package/{cardano-connector-DiiSoILv.js → cardano-connector-CIrXiVTi.js} +2 -2
- package/dist/package/{configured-chains-CqS9GQgO.js → configured-chains-Ddwhz0AO.js} +1 -1
- package/dist/package/{cosmos-connector-meta-D2OXd_8A.js → cosmos-connector-meta-gXG2LZJw.js} +1 -1
- package/dist/package/index.package.js +69 -34
- package/dist/package/{ledger-connector-CoflrvIY.js → ledger-connector-DA2MGFO1.js} +5 -5
- package/dist/package/{network-DzIq3Eb-.js → network-DRWqFyX1.js} +1 -1
- package/dist/package/{solana-connector-BGL_7RtS.js → solana-connector-zdXBpO69.js} +3 -3
- package/dist/package/{stellar-connector-KA4sbBsT.js → stellar-connector-Bwd8_6fg.js} +2 -2
- package/dist/package/{substrate-connector-C47hmu7O.js → substrate-connector-DWxNzj24.js} +1 -1
- package/dist/package/{ton-connector-Os8-LilP.js → ton-connector-Bwc9mQfl.js} +3 -3
- package/dist/package/{transaction-BUvzBUD1.js → transaction-C10sHjOp.js} +1 -1
- package/dist/package/{transaction-BhlMhMmN.js → transaction-CRtu-oMo.js} +1 -1
- package/dist/package/{transaction-GC-w6eas.js → transaction-CYsojERR.js} +1 -1
- package/dist/package/{transaction-9ZjMuyda.js → transaction-cowIxlQK.js} +1 -1
- package/dist/package/{tron-connector-73EkJLaC.js → tron-connector-DQ9QzTbX.js} +3 -3
- package/dist/package/{wallet-manager-fjTGOCl1.js → wallet-manager-CV7OgeRF.js} +2 -2
- package/dist/types/domain/network/contract.d.ts +1 -1
- package/dist/types/domain/network/network-name.d.ts +7 -0
- package/dist/types/domain/wallet/contract.d.ts +0 -1
- package/dist/types/domain/wallet/wallet-policy.d.ts +9 -0
- package/dist/types/generated/api/legacy-networks.d.ts +1 -0
- package/dist/types/generated/api/yield-networks.d.ts +1 -0
- package/dist/types/index.bundle.d.ts +1 -1
- package/dist/types/index.package.d.ts +1 -1
- package/dist/types/public-api/react-types.d.ts +8 -0
- package/dist/types/public-api/types.d.ts +73 -23
- package/dist/website/assets/{assets-Cv_Ib61e.js → assets-h8USQKgq.js} +1 -1
- package/dist/website/assets/{cardano-connector-BQ5eYUAn.js → cardano-connector-C0Sq11R4.js} +1 -1
- package/dist/website/assets/{configured-chains-BHW1HK8Y.js → configured-chains-CIWlanAA.js} +1 -1
- package/dist/website/assets/{cosmos-connector-meta-PXOxxoiN.js → cosmos-connector-meta-rno_UNzC.js} +1 -1
- package/dist/website/assets/index-5Aa-rcFh.js +540 -0
- package/dist/website/assets/{ledger-connector-CfdYVk_B.js → ledger-connector-Dd5qrF8_.js} +2 -2
- package/dist/website/assets/{network-CpiZy7GL.js → network-BGx8nCzY.js} +1 -1
- package/dist/website/assets/{solana-connector-Dko0nLRl.js → solana-connector-B7Md4VDG.js} +1 -1
- package/dist/website/assets/{stellar-connector-CzEQ-GiL.js → stellar-connector-BwE5re5j.js} +1 -1
- package/dist/website/assets/{substrate-connector-BySKIZSU.js → substrate-connector-Bc3A8Ngf.js} +1 -1
- package/dist/website/assets/{ton-connector-DfHih6IL.js → ton-connector-1XbtGnNe.js} +1 -1
- package/dist/website/assets/{transaction-BgxiRDr6.js → transaction-BN_PDuuD.js} +1 -1
- package/dist/website/assets/{transaction-Z0G1srG_.js → transaction-BTjp5Yv_.js} +2 -2
- package/dist/website/assets/{transaction-qQ73FnRV.js → transaction-CRGTe3Dx.js} +2 -2
- package/dist/website/assets/transaction-DhoVCNGK.js +1 -0
- package/dist/website/assets/{tron-connector-BkQWCtpI.js → tron-connector-BPQRviGm.js} +2 -2
- package/dist/website/assets/{utils-BnE0E9wY.js → utils-Bi0bPCX2.js} +1 -1
- package/dist/website/assets/{wallet-manager-Bnoaodi-.js → wallet-manager-Dysx00HR.js} +3 -3
- package/dist/website/index.html +9 -9
- package/package.json +2 -2
- package/dist/bundle/transaction-B_6wJk3a.js +0 -23
- package/dist/types/domain/network/intersection.d.ts +0 -2
- package/dist/types/domain/network/network.d.ts +0 -3
- package/dist/types/domain/wallet/network.d.ts +0 -575
- package/dist/types/generated/api/legacy-schema.d.ts +0 -1017
- package/dist/types/generated/api/yield-schema.d.ts +0 -4328
- package/dist/website/assets/index-DPaiXt13.js +0 -540
- package/dist/website/assets/transaction-XbbbllS0.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,s as r,t as i}from"./rolldown-runtime-BcKkbAw3.js";import{zt as a}from"./Result-Bvvef0v1.js";import{A as o,R as s,k as c,o as l}from"./assets-Cv_Ib61e.js";import{nn as u,wn as d}from"./wagmi-connect-result-B59F3NGW.js";import{n as f,t as p}from"./sha256-DmRqOOd6.js";import{n as m,t as h}from"./sha3-DRlIjSdj.js";import{n as g,r as _,t as v}from"./dist-CELdgNh9.js";import{n as ee,r as y,t as b}from"./eventemitter3-CTnouYki.js";import{n as te,t as x}from"./ed25519-DWgFEKI3.js";import{t as S}from"./dist-VPhQpe2v.js";import{t as ne}from"./bn-CqGbRtYY.js";import{t as C}from"./bs58-DoSnopGu.js";import{n as w,t as T}from"./secp256k1-BcfUQvi6.js";import{t as E}from"./esm-DhvlA6gG.js";y();var D=class extends Error{constructor(e,t){super(e),this.error=t}},re=class extends D{constructor(){super(...arguments),this.name=`WalletNotReadyError`}},O=class extends D{constructor(){super(...arguments),this.name=`WalletConfigError`}},k=class extends D{constructor(){super(...arguments),this.name=`WalletConnectionError`}},ie=class extends D{constructor(){super(...arguments),this.name=`WalletDisconnectedError`}},ae=class extends D{constructor(){super(...arguments),this.name=`WalletDisconnectionError`}},oe=class extends D{constructor(){super(...arguments),this.name=`WalletAccountError`}},se=class extends D{constructor(){super(...arguments),this.name=`WalletPublicKeyError`}},A=class extends D{constructor(){super(...arguments),this.name=`WalletNotConnectedError`}},j=class extends D{constructor(){super(...arguments),this.name=`WalletSendTransactionError`}},ce=class extends D{constructor(){super(...arguments),this.name=`WalletSignTransactionError`}},le=class extends D{constructor(){super(...arguments),this.name=`WalletSignMessageError`}},ue=class extends D{constructor(){super(...arguments),this.name=`WalletSignInError`}},de;(function(e){e.Installed=`Installed`,e.NotDetected=`NotDetected`,e.Loadable=`Loadable`,e.Unsupported=`Unsupported`})(de||={});var fe=class extends b{get connected(){return!!this.publicKey}async autoConnect(){await this.connect()}async prepareTransaction(e,t,n={}){let r=this.publicKey;if(!r)throw new A;return e.feePayer=e.feePayer||r,e.recentBlockhash=e.recentBlockhash||(await t.getLatestBlockhash({commitment:n.preflightCommitment,minContextSlot:n.minContextSlot})).blockhash,e}};function pe(e){if(typeof window>`u`||typeof document>`u`)return;let t=[];function n(){if(e())for(let e of t)e()}let r=setInterval(n,1e3);t.push(()=>clearInterval(r)),document.readyState===`loading`&&(document.addEventListener(`DOMContentLoaded`,n,{once:!0}),t.push(()=>document.removeEventListener(`DOMContentLoaded`,n))),document.readyState!==`complete`&&(window.addEventListener(`load`,n,{once:!0}),t.push(()=>window.removeEventListener(`load`,n))),n()}function me(){if(!navigator)return!1;let e=navigator.userAgent.toLowerCase(),t=e.includes(`iphone`)||e.includes(`ipad`),n=e.includes(`safari`);return t&&n}function M(e){return`version`in e}var he=class extends fe{async sendTransaction(e,t,n={}){let r=!0;try{if(M(e)){if(!this.supportedTransactionVersions)throw new j(`Sending versioned transactions isn't supported by this wallet`);if(!this.supportedTransactionVersions.has(e.version))throw new j(`Sending transaction version ${e.version} isn't supported by this wallet`);try{e=await this.signTransaction(e);let r=e.serialize();return await t.sendRawTransaction(r,n)}catch(e){throw e instanceof ce?(r=!1,e):new j(e?.message,e)}}try{let{signers:r,...i}=n;e=await this.prepareTransaction(e,t,i),r?.length&&e.partialSign(...r),e=await this.signTransaction(e);let a=e.serialize();return await t.sendRawTransaction(a,i)}catch(e){throw e instanceof ce?(r=!1,e):new j(e?.message,e)}}catch(e){throw r&&this.emit(`error`,e),e}}async signAllTransactions(e){for(let t of e)if(M(t)){if(!this.supportedTransactionVersions)throw new ce(`Signing versioned transactions isn't supported by this wallet`);if(!this.supportedTransactionVersions.has(t.version))throw new ce(`Signing transaction version ${t.version} isn't supported by this wallet`)}let t=[];for(let n of e)t.push(await this.signTransaction(n));return t}},ge=class extends he{},_e=class extends ge{},ve;(function(e){e.Mainnet=`mainnet-beta`,e.Testnet=`testnet`,e.Devnet=`devnet`})(ve||={});var ye=i(((e,t)=>{(function(e,t){function n(e,t){if(!e)throw Error(t||`Assertion failed`)}function r(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}function i(e,t,n){if(i.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,e!==null&&((t===`le`||t===`be`)&&(n=t,t=10),this._init(e||0,t||10,n||`be`))}typeof e==`object`?e.exports=i:t.BN=i,i.BN=i,i.wordSize=26;var a;try{a=typeof window<`u`&&window.Buffer!==void 0?window.Buffer:S().Buffer}catch{}i.isBN=function(e){return e instanceof i||typeof e==`object`&&!!e&&e.constructor.wordSize===i.wordSize&&Array.isArray(e.words)},i.max=function(e,t){return e.cmp(t)>0?e:t},i.min=function(e,t){return e.cmp(t)<0?e:t},i.prototype._init=function(e,t,r){if(typeof e==`number`)return this._initNumber(e,t,r);if(typeof e==`object`)return this._initArray(e,t,r);t===`hex`&&(t=16),n(t===(t|0)&&t>=2&&t<=36),e=e.toString().replace(/\s+/g,``);var i=0;e[0]===`-`&&(i++,this.negative=1),i<e.length&&(t===16?this._parseHex(e,i,r):(this._parseBase(e,t,i),r===`le`&&this._initArray(this.toArray(),t,r)))},i.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),r===`le`&&this._initArray(this.toArray(),t,r)},i.prototype._initArray=function(e,t,r){if(n(typeof e.length==`number`),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var a,o,s=0;if(r===`be`)for(i=e.length-1,a=0;i>=0;i-=3)o=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);else if(r===`le`)for(i=0,a=0;i<e.length;i+=3)o=e[i]|e[i+1]<<8|e[i+2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);return this._strip()};function o(e,t){var r=e.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;n(!1,`Invalid character in `+e)}function s(e,t,n){var r=o(e,n);return n-1>=t&&(r|=o(e,n-1)<<4),r}i.prototype._parseHex=function(e,t,n){this.length=Math.ceil((e.length-t)/6),this.words=Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var i=0,a=0,o;if(n===`be`)for(r=e.length-1;r>=t;r-=2)o=s(e,t,r)<<i,this.words[a]|=o&67108863,i>=18?(i-=18,a+=1,this.words[a]|=o>>>26):i+=8;else for(r=(e.length-t)%2==0?t+1:t;r<e.length;r+=2)o=s(e,t,r)<<i,this.words[a]|=o&67108863,i>=18?(i-=18,a+=1,this.words[a]|=o>>>26):i+=8;this._strip()};function c(e,t,r,i){for(var a=0,o=0,s=Math.min(e.length,r),c=t;c<s;c++){var l=e.charCodeAt(c)-48;a*=i,o=l>=49?l-49+10:l>=17?l-17+10:l,n(l>=0&&o<i,`Invalid character`),a+=o}return a}i.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var r=0,i=1;i<=67108863;i*=t)r++;r--,i=i/t|0;for(var a=e.length-n,o=a%r,s=Math.min(a,a-o)+n,l=0,u=n;u<s;u+=r)l=c(e,u,u+r,t),this.imuln(i),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(o!==0){var d=1;for(l=c(e,u,e.length,t),u=0;u<o;u++)d*=t;this.imuln(d),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this._strip()},i.prototype.copy=function(e){e.words=Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red};function l(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(i.prototype._move=function(e){l(e,this)},i.prototype.clone=function(){var e=new i(null);return this.copy(e),e},i.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<`u`&&typeof Symbol.for==`function`)try{i.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=u}catch{i.prototype.inspect=u}else i.prototype.inspect=u;function u(){return(this.red?`<BN-R: `:`<BN: `)+this.toString(16)+`>`}var d=`.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`.split(`.`),f=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(e,t){e||=10,t=t|0||1;var r;if(e===16||e===`hex`){r=``;for(var i=0,a=0,o=0;o<this.length;o++){var s=this.words[o],c=((s<<i|a)&16777215).toString(16);a=s>>>24-i&16777215,i+=2,i>=26&&(i-=26,o--),r=a!==0||o!==this.length-1?d[6-c.length]+c+r:c+r}for(a!==0&&(r=a.toString(16)+r);r.length%t!==0;)r=`0`+r;return this.negative!==0&&(r=`-`+r),r}if(e===(e|0)&&e>=2&&e<=36){var l=f[e],u=p[e];r=``;var m=this.clone();for(m.negative=0;!m.isZero();){var h=m.modrn(u).toString(e);m=m.idivn(u),r=m.isZero()?h+r:d[l-h.length]+h+r}for(this.isZero()&&(r=`0`+r);r.length%t!==0;)r=`0`+r;return this.negative!==0&&(r=`-`+r),r}n(!1,`Base should be between 2 and 36`)},i.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,`Number can only safely store up to 53 bits`),this.negative===0?e:-e},i.prototype.toJSON=function(){return this.toString(16,2)},a&&(i.prototype.toBuffer=function(e,t){return this.toArrayLike(a,e,t)}),i.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)};var m=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)};i.prototype.toArrayLike=function(e,t,r){this._strip();var i=this.byteLength(),a=r||Math.max(1,i);n(i<=a,`byte array longer than desired length`),n(a>0,`Requested array length <= 0`);var o=m(e,a),s=t===`le`?`LE`:`BE`;return this[`_toArrayLike`+s](o,i),o},i.prototype._toArrayLikeLE=function(e,t){for(var n=0,r=0,i=0,a=0;i<this.length;i++){var o=this.words[i]<<a|r;e[n++]=o&255,n<e.length&&(e[n++]=o>>8&255),n<e.length&&(e[n++]=o>>16&255),a===6?(n<e.length&&(e[n++]=o>>24&255),r=0,a=0):(r=o>>>24,a+=2)}if(n<e.length)for(e[n++]=r;n<e.length;)e[n++]=0},i.prototype._toArrayLikeBE=function(e,t){for(var n=e.length-1,r=0,i=0,a=0;i<this.length;i++){var o=this.words[i]<<a|r;e[n--]=o&255,n>=0&&(e[n--]=o>>8&255),n>=0&&(e[n--]=o>>16&255),a===6?(n>=0&&(e[n--]=o>>24&255),r=0,a=0):(r=o>>>24,a+=2)}if(n>=0)for(e[n--]=r;n>=0;)e[n--]=0},Math.clz32?i.prototype._countBits=function(e){return 32-Math.clz32(e)}:i.prototype._countBits=function(e){var t=e,n=0;return t>=4096&&(n+=13,t>>>=13),t>=64&&(n+=7,t>>>=7),t>=8&&(n+=4,t>>>=4),t>=2&&(n+=2,t>>>=2),n+t},i.prototype._zeroBits=function(e){if(e===0)return 26;var t=e,n=0;return t&8191||(n+=13,t>>>=13),t&127||(n+=7,t>>>=7),t&15||(n+=4,t>>>=4),t&3||(n+=2,t>>>=2),t&1||n++,n},i.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return(this.length-1)*26+t};function h(e){for(var t=Array(e.bitLength()),n=0;n<t.length;n++){var r=n/26|0,i=n%26;t[n]=e.words[r]>>>i&1}return t}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var n=this._zeroBits(this.words[t]);if(e+=n,n!==26)break}return e},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(e){return this.negative===0?this.clone():this.abs().inotn(e).iaddn(1)},i.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},i.prototype.ior=function(e){return n((this.negative|e.negative)===0),this.iuor(e)},i.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},i.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},i.prototype.iuand=function(e){for(var t=this.length>e.length?e:this,n=0;n<t.length;n++)this.words[n]=this.words[n]&e.words[n];return this.length=t.length,this._strip()},i.prototype.iand=function(e){return n((this.negative|e.negative)===0),this.iuand(e)},i.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},i.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},i.prototype.iuxor=function(e){var t,n;this.length>e.length?(t=this,n=e):(t=e,n=this);for(var r=0;r<n.length;r++)this.words[r]=t.words[r]^n.words[r];if(this!==t)for(;r<t.length;r++)this.words[r]=t.words[r];return this.length=t.length,this._strip()},i.prototype.ixor=function(e){return n((this.negative|e.negative)===0),this.iuxor(e)},i.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},i.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},i.prototype.inotn=function(e){n(typeof e==`number`&&e>=0);var t=Math.ceil(e/26)|0,r=e%26;this._expand(t),r>0&&t--;for(var i=0;i<t;i++)this.words[i]=~this.words[i]&67108863;for(r>0&&(this.words[i]=~this.words[i]&67108863>>26-r,i++);i<this.length;i++)this.words[i]=0;return this._strip()},i.prototype.notn=function(e){return this.clone().inotn(e)},i.prototype.setn=function(e,t){n(typeof e==`number`&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),t?this.words[r]=this.words[r]|1<<i:this.words[r]=this.words[r]&~(1<<i),this._strip()},i.prototype.iadd=function(e){var t;if(this.negative!==0&&e.negative===0)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();var n,r;this.length>e.length?(n=this,r=e):(n=e,r=this);for(var i=0,a=0;a<r.length;a++)t=(n.words[a]|0)+(r.words[a]|0)+i,this.words[a]=t&67108863,i=t>>>26;for(;i!==0&&a<n.length;a++)t=(n.words[a]|0)+i,this.words[a]=t&67108863,i=t>>>26;if(this.length=n.length,i!==0)this.words[this.length]=i,this.length++;else if(n!==this)for(;a<n.length;a++)this.words[a]=n.words[a];return this},i.prototype.add=function(e){var t;return e.negative!==0&&this.negative===0?(e.negative=0,t=this.sub(e),e.negative^=1,t):e.negative===0&&this.negative!==0?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},i.prototype.isub=function(e){if(e.negative!==0){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(this.negative!==0)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n=this.cmp(e);if(n===0)return this.negative=0,this.length=1,this.words[0]=0,this;var r,i;n>0?(r=this,i=e):(r=e,i=this);for(var a=0,o=0;o<i.length;o++)t=(r.words[o]|0)-(i.words[o]|0)+a,a=t>>26,this.words[o]=t&67108863;for(;a!==0&&o<r.length;o++)t=(r.words[o]|0)+a,a=t>>26,this.words[o]=t&67108863;if(a===0&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(e){return this.clone().isub(e)};function g(e,t,n){n.negative=t.negative^e.negative;var r=e.length+t.length|0;n.length=r,r=r-1|0;var i=e.words[0]|0,a=t.words[0]|0,o=i*a,s=o&67108863,c=o/67108864|0;n.words[0]=s;for(var l=1;l<r;l++){for(var u=c>>>26,d=c&67108863,f=Math.min(l,t.length-1),p=Math.max(0,l-e.length+1);p<=f;p++){var m=l-p|0;i=e.words[m]|0,a=t.words[p]|0,o=i*a+d,u+=o/67108864|0,d=o&67108863}n.words[l]=d|0,c=u|0}return c===0?n.length--:n.words[l]=c|0,n._strip()}var _=function(e,t,n){var r=e.words,i=t.words,a=n.words,o=0,s,c,l,u=r[0]|0,d=u&8191,f=u>>>13,p=r[1]|0,m=p&8191,h=p>>>13,g=r[2]|0,_=g&8191,v=g>>>13,ee=r[3]|0,y=ee&8191,b=ee>>>13,te=r[4]|0,x=te&8191,S=te>>>13,ne=r[5]|0,C=ne&8191,w=ne>>>13,T=r[6]|0,E=T&8191,D=T>>>13,re=r[7]|0,O=re&8191,k=re>>>13,ie=r[8]|0,ae=ie&8191,oe=ie>>>13,se=r[9]|0,A=se&8191,j=se>>>13,ce=i[0]|0,le=ce&8191,ue=ce>>>13,de=i[1]|0,fe=de&8191,pe=de>>>13,me=i[2]|0,M=me&8191,he=me>>>13,ge=i[3]|0,_e=ge&8191,ve=ge>>>13,ye=i[4]|0,be=ye&8191,N=ye>>>13,xe=i[5]|0,Se=xe&8191,Ce=xe>>>13,we=i[6]|0,Te=we&8191,Ee=we>>>13,De=i[7]|0,Oe=De&8191,ke=De>>>13,Ae=i[8]|0,P=Ae&8191,F=Ae>>>13,je=i[9]|0,Me=je&8191,Ne=je>>>13;n.negative=e.negative^t.negative,n.length=19,s=Math.imul(d,le),c=Math.imul(d,ue),c=c+Math.imul(f,le)|0,l=Math.imul(f,ue);var Pe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,s=Math.imul(m,le),c=Math.imul(m,ue),c=c+Math.imul(h,le)|0,l=Math.imul(h,ue),s=s+Math.imul(d,fe)|0,c=c+Math.imul(d,pe)|0,c=c+Math.imul(f,fe)|0,l=l+Math.imul(f,pe)|0;var Fe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,s=Math.imul(_,le),c=Math.imul(_,ue),c=c+Math.imul(v,le)|0,l=Math.imul(v,ue),s=s+Math.imul(m,fe)|0,c=c+Math.imul(m,pe)|0,c=c+Math.imul(h,fe)|0,l=l+Math.imul(h,pe)|0,s=s+Math.imul(d,M)|0,c=c+Math.imul(d,he)|0,c=c+Math.imul(f,M)|0,l=l+Math.imul(f,he)|0;var Ie=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,s=Math.imul(y,le),c=Math.imul(y,ue),c=c+Math.imul(b,le)|0,l=Math.imul(b,ue),s=s+Math.imul(_,fe)|0,c=c+Math.imul(_,pe)|0,c=c+Math.imul(v,fe)|0,l=l+Math.imul(v,pe)|0,s=s+Math.imul(m,M)|0,c=c+Math.imul(m,he)|0,c=c+Math.imul(h,M)|0,l=l+Math.imul(h,he)|0,s=s+Math.imul(d,_e)|0,c=c+Math.imul(d,ve)|0,c=c+Math.imul(f,_e)|0,l=l+Math.imul(f,ve)|0;var Le=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Le>>>26)|0,Le&=67108863,s=Math.imul(x,le),c=Math.imul(x,ue),c=c+Math.imul(S,le)|0,l=Math.imul(S,ue),s=s+Math.imul(y,fe)|0,c=c+Math.imul(y,pe)|0,c=c+Math.imul(b,fe)|0,l=l+Math.imul(b,pe)|0,s=s+Math.imul(_,M)|0,c=c+Math.imul(_,he)|0,c=c+Math.imul(v,M)|0,l=l+Math.imul(v,he)|0,s=s+Math.imul(m,_e)|0,c=c+Math.imul(m,ve)|0,c=c+Math.imul(h,_e)|0,l=l+Math.imul(h,ve)|0,s=s+Math.imul(d,be)|0,c=c+Math.imul(d,N)|0,c=c+Math.imul(f,be)|0,l=l+Math.imul(f,N)|0;var Re=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Re>>>26)|0,Re&=67108863,s=Math.imul(C,le),c=Math.imul(C,ue),c=c+Math.imul(w,le)|0,l=Math.imul(w,ue),s=s+Math.imul(x,fe)|0,c=c+Math.imul(x,pe)|0,c=c+Math.imul(S,fe)|0,l=l+Math.imul(S,pe)|0,s=s+Math.imul(y,M)|0,c=c+Math.imul(y,he)|0,c=c+Math.imul(b,M)|0,l=l+Math.imul(b,he)|0,s=s+Math.imul(_,_e)|0,c=c+Math.imul(_,ve)|0,c=c+Math.imul(v,_e)|0,l=l+Math.imul(v,ve)|0,s=s+Math.imul(m,be)|0,c=c+Math.imul(m,N)|0,c=c+Math.imul(h,be)|0,l=l+Math.imul(h,N)|0,s=s+Math.imul(d,Se)|0,c=c+Math.imul(d,Ce)|0,c=c+Math.imul(f,Se)|0,l=l+Math.imul(f,Ce)|0;var ze=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(ze>>>26)|0,ze&=67108863,s=Math.imul(E,le),c=Math.imul(E,ue),c=c+Math.imul(D,le)|0,l=Math.imul(D,ue),s=s+Math.imul(C,fe)|0,c=c+Math.imul(C,pe)|0,c=c+Math.imul(w,fe)|0,l=l+Math.imul(w,pe)|0,s=s+Math.imul(x,M)|0,c=c+Math.imul(x,he)|0,c=c+Math.imul(S,M)|0,l=l+Math.imul(S,he)|0,s=s+Math.imul(y,_e)|0,c=c+Math.imul(y,ve)|0,c=c+Math.imul(b,_e)|0,l=l+Math.imul(b,ve)|0,s=s+Math.imul(_,be)|0,c=c+Math.imul(_,N)|0,c=c+Math.imul(v,be)|0,l=l+Math.imul(v,N)|0,s=s+Math.imul(m,Se)|0,c=c+Math.imul(m,Ce)|0,c=c+Math.imul(h,Se)|0,l=l+Math.imul(h,Ce)|0,s=s+Math.imul(d,Te)|0,c=c+Math.imul(d,Ee)|0,c=c+Math.imul(f,Te)|0,l=l+Math.imul(f,Ee)|0;var Be=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Be>>>26)|0,Be&=67108863,s=Math.imul(O,le),c=Math.imul(O,ue),c=c+Math.imul(k,le)|0,l=Math.imul(k,ue),s=s+Math.imul(E,fe)|0,c=c+Math.imul(E,pe)|0,c=c+Math.imul(D,fe)|0,l=l+Math.imul(D,pe)|0,s=s+Math.imul(C,M)|0,c=c+Math.imul(C,he)|0,c=c+Math.imul(w,M)|0,l=l+Math.imul(w,he)|0,s=s+Math.imul(x,_e)|0,c=c+Math.imul(x,ve)|0,c=c+Math.imul(S,_e)|0,l=l+Math.imul(S,ve)|0,s=s+Math.imul(y,be)|0,c=c+Math.imul(y,N)|0,c=c+Math.imul(b,be)|0,l=l+Math.imul(b,N)|0,s=s+Math.imul(_,Se)|0,c=c+Math.imul(_,Ce)|0,c=c+Math.imul(v,Se)|0,l=l+Math.imul(v,Ce)|0,s=s+Math.imul(m,Te)|0,c=c+Math.imul(m,Ee)|0,c=c+Math.imul(h,Te)|0,l=l+Math.imul(h,Ee)|0,s=s+Math.imul(d,Oe)|0,c=c+Math.imul(d,ke)|0,c=c+Math.imul(f,Oe)|0,l=l+Math.imul(f,ke)|0;var Ve=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,s=Math.imul(ae,le),c=Math.imul(ae,ue),c=c+Math.imul(oe,le)|0,l=Math.imul(oe,ue),s=s+Math.imul(O,fe)|0,c=c+Math.imul(O,pe)|0,c=c+Math.imul(k,fe)|0,l=l+Math.imul(k,pe)|0,s=s+Math.imul(E,M)|0,c=c+Math.imul(E,he)|0,c=c+Math.imul(D,M)|0,l=l+Math.imul(D,he)|0,s=s+Math.imul(C,_e)|0,c=c+Math.imul(C,ve)|0,c=c+Math.imul(w,_e)|0,l=l+Math.imul(w,ve)|0,s=s+Math.imul(x,be)|0,c=c+Math.imul(x,N)|0,c=c+Math.imul(S,be)|0,l=l+Math.imul(S,N)|0,s=s+Math.imul(y,Se)|0,c=c+Math.imul(y,Ce)|0,c=c+Math.imul(b,Se)|0,l=l+Math.imul(b,Ce)|0,s=s+Math.imul(_,Te)|0,c=c+Math.imul(_,Ee)|0,c=c+Math.imul(v,Te)|0,l=l+Math.imul(v,Ee)|0,s=s+Math.imul(m,Oe)|0,c=c+Math.imul(m,ke)|0,c=c+Math.imul(h,Oe)|0,l=l+Math.imul(h,ke)|0,s=s+Math.imul(d,P)|0,c=c+Math.imul(d,F)|0,c=c+Math.imul(f,P)|0,l=l+Math.imul(f,F)|0;var He=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(He>>>26)|0,He&=67108863,s=Math.imul(A,le),c=Math.imul(A,ue),c=c+Math.imul(j,le)|0,l=Math.imul(j,ue),s=s+Math.imul(ae,fe)|0,c=c+Math.imul(ae,pe)|0,c=c+Math.imul(oe,fe)|0,l=l+Math.imul(oe,pe)|0,s=s+Math.imul(O,M)|0,c=c+Math.imul(O,he)|0,c=c+Math.imul(k,M)|0,l=l+Math.imul(k,he)|0,s=s+Math.imul(E,_e)|0,c=c+Math.imul(E,ve)|0,c=c+Math.imul(D,_e)|0,l=l+Math.imul(D,ve)|0,s=s+Math.imul(C,be)|0,c=c+Math.imul(C,N)|0,c=c+Math.imul(w,be)|0,l=l+Math.imul(w,N)|0,s=s+Math.imul(x,Se)|0,c=c+Math.imul(x,Ce)|0,c=c+Math.imul(S,Se)|0,l=l+Math.imul(S,Ce)|0,s=s+Math.imul(y,Te)|0,c=c+Math.imul(y,Ee)|0,c=c+Math.imul(b,Te)|0,l=l+Math.imul(b,Ee)|0,s=s+Math.imul(_,Oe)|0,c=c+Math.imul(_,ke)|0,c=c+Math.imul(v,Oe)|0,l=l+Math.imul(v,ke)|0,s=s+Math.imul(m,P)|0,c=c+Math.imul(m,F)|0,c=c+Math.imul(h,P)|0,l=l+Math.imul(h,F)|0,s=s+Math.imul(d,Me)|0,c=c+Math.imul(d,Ne)|0,c=c+Math.imul(f,Me)|0,l=l+Math.imul(f,Ne)|0;var Ue=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ue>>>26)|0,Ue&=67108863,s=Math.imul(A,fe),c=Math.imul(A,pe),c=c+Math.imul(j,fe)|0,l=Math.imul(j,pe),s=s+Math.imul(ae,M)|0,c=c+Math.imul(ae,he)|0,c=c+Math.imul(oe,M)|0,l=l+Math.imul(oe,he)|0,s=s+Math.imul(O,_e)|0,c=c+Math.imul(O,ve)|0,c=c+Math.imul(k,_e)|0,l=l+Math.imul(k,ve)|0,s=s+Math.imul(E,be)|0,c=c+Math.imul(E,N)|0,c=c+Math.imul(D,be)|0,l=l+Math.imul(D,N)|0,s=s+Math.imul(C,Se)|0,c=c+Math.imul(C,Ce)|0,c=c+Math.imul(w,Se)|0,l=l+Math.imul(w,Ce)|0,s=s+Math.imul(x,Te)|0,c=c+Math.imul(x,Ee)|0,c=c+Math.imul(S,Te)|0,l=l+Math.imul(S,Ee)|0,s=s+Math.imul(y,Oe)|0,c=c+Math.imul(y,ke)|0,c=c+Math.imul(b,Oe)|0,l=l+Math.imul(b,ke)|0,s=s+Math.imul(_,P)|0,c=c+Math.imul(_,F)|0,c=c+Math.imul(v,P)|0,l=l+Math.imul(v,F)|0,s=s+Math.imul(m,Me)|0,c=c+Math.imul(m,Ne)|0,c=c+Math.imul(h,Me)|0,l=l+Math.imul(h,Ne)|0;var We=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(We>>>26)|0,We&=67108863,s=Math.imul(A,M),c=Math.imul(A,he),c=c+Math.imul(j,M)|0,l=Math.imul(j,he),s=s+Math.imul(ae,_e)|0,c=c+Math.imul(ae,ve)|0,c=c+Math.imul(oe,_e)|0,l=l+Math.imul(oe,ve)|0,s=s+Math.imul(O,be)|0,c=c+Math.imul(O,N)|0,c=c+Math.imul(k,be)|0,l=l+Math.imul(k,N)|0,s=s+Math.imul(E,Se)|0,c=c+Math.imul(E,Ce)|0,c=c+Math.imul(D,Se)|0,l=l+Math.imul(D,Ce)|0,s=s+Math.imul(C,Te)|0,c=c+Math.imul(C,Ee)|0,c=c+Math.imul(w,Te)|0,l=l+Math.imul(w,Ee)|0,s=s+Math.imul(x,Oe)|0,c=c+Math.imul(x,ke)|0,c=c+Math.imul(S,Oe)|0,l=l+Math.imul(S,ke)|0,s=s+Math.imul(y,P)|0,c=c+Math.imul(y,F)|0,c=c+Math.imul(b,P)|0,l=l+Math.imul(b,F)|0,s=s+Math.imul(_,Me)|0,c=c+Math.imul(_,Ne)|0,c=c+Math.imul(v,Me)|0,l=l+Math.imul(v,Ne)|0;var Ge=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,s=Math.imul(A,_e),c=Math.imul(A,ve),c=c+Math.imul(j,_e)|0,l=Math.imul(j,ve),s=s+Math.imul(ae,be)|0,c=c+Math.imul(ae,N)|0,c=c+Math.imul(oe,be)|0,l=l+Math.imul(oe,N)|0,s=s+Math.imul(O,Se)|0,c=c+Math.imul(O,Ce)|0,c=c+Math.imul(k,Se)|0,l=l+Math.imul(k,Ce)|0,s=s+Math.imul(E,Te)|0,c=c+Math.imul(E,Ee)|0,c=c+Math.imul(D,Te)|0,l=l+Math.imul(D,Ee)|0,s=s+Math.imul(C,Oe)|0,c=c+Math.imul(C,ke)|0,c=c+Math.imul(w,Oe)|0,l=l+Math.imul(w,ke)|0,s=s+Math.imul(x,P)|0,c=c+Math.imul(x,F)|0,c=c+Math.imul(S,P)|0,l=l+Math.imul(S,F)|0,s=s+Math.imul(y,Me)|0,c=c+Math.imul(y,Ne)|0,c=c+Math.imul(b,Me)|0,l=l+Math.imul(b,Ne)|0;var Ke=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,s=Math.imul(A,be),c=Math.imul(A,N),c=c+Math.imul(j,be)|0,l=Math.imul(j,N),s=s+Math.imul(ae,Se)|0,c=c+Math.imul(ae,Ce)|0,c=c+Math.imul(oe,Se)|0,l=l+Math.imul(oe,Ce)|0,s=s+Math.imul(O,Te)|0,c=c+Math.imul(O,Ee)|0,c=c+Math.imul(k,Te)|0,l=l+Math.imul(k,Ee)|0,s=s+Math.imul(E,Oe)|0,c=c+Math.imul(E,ke)|0,c=c+Math.imul(D,Oe)|0,l=l+Math.imul(D,ke)|0,s=s+Math.imul(C,P)|0,c=c+Math.imul(C,F)|0,c=c+Math.imul(w,P)|0,l=l+Math.imul(w,F)|0,s=s+Math.imul(x,Me)|0,c=c+Math.imul(x,Ne)|0,c=c+Math.imul(S,Me)|0,l=l+Math.imul(S,Ne)|0;var qe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(qe>>>26)|0,qe&=67108863,s=Math.imul(A,Se),c=Math.imul(A,Ce),c=c+Math.imul(j,Se)|0,l=Math.imul(j,Ce),s=s+Math.imul(ae,Te)|0,c=c+Math.imul(ae,Ee)|0,c=c+Math.imul(oe,Te)|0,l=l+Math.imul(oe,Ee)|0,s=s+Math.imul(O,Oe)|0,c=c+Math.imul(O,ke)|0,c=c+Math.imul(k,Oe)|0,l=l+Math.imul(k,ke)|0,s=s+Math.imul(E,P)|0,c=c+Math.imul(E,F)|0,c=c+Math.imul(D,P)|0,l=l+Math.imul(D,F)|0,s=s+Math.imul(C,Me)|0,c=c+Math.imul(C,Ne)|0,c=c+Math.imul(w,Me)|0,l=l+Math.imul(w,Ne)|0;var Je=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Je>>>26)|0,Je&=67108863,s=Math.imul(A,Te),c=Math.imul(A,Ee),c=c+Math.imul(j,Te)|0,l=Math.imul(j,Ee),s=s+Math.imul(ae,Oe)|0,c=c+Math.imul(ae,ke)|0,c=c+Math.imul(oe,Oe)|0,l=l+Math.imul(oe,ke)|0,s=s+Math.imul(O,P)|0,c=c+Math.imul(O,F)|0,c=c+Math.imul(k,P)|0,l=l+Math.imul(k,F)|0,s=s+Math.imul(E,Me)|0,c=c+Math.imul(E,Ne)|0,c=c+Math.imul(D,Me)|0,l=l+Math.imul(D,Ne)|0;var Ye=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,s=Math.imul(A,Oe),c=Math.imul(A,ke),c=c+Math.imul(j,Oe)|0,l=Math.imul(j,ke),s=s+Math.imul(ae,P)|0,c=c+Math.imul(ae,F)|0,c=c+Math.imul(oe,P)|0,l=l+Math.imul(oe,F)|0,s=s+Math.imul(O,Me)|0,c=c+Math.imul(O,Ne)|0,c=c+Math.imul(k,Me)|0,l=l+Math.imul(k,Ne)|0;var Xe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,s=Math.imul(A,P),c=Math.imul(A,F),c=c+Math.imul(j,P)|0,l=Math.imul(j,F),s=s+Math.imul(ae,Me)|0,c=c+Math.imul(ae,Ne)|0,c=c+Math.imul(oe,Me)|0,l=l+Math.imul(oe,Ne)|0;var Ze=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ze>>>26)|0,Ze&=67108863,s=Math.imul(A,Me),c=Math.imul(A,Ne),c=c+Math.imul(j,Me)|0,l=Math.imul(j,Ne);var Qe=(o+s|0)+((c&8191)<<13)|0;return o=(l+(c>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,a[0]=Pe,a[1]=Fe,a[2]=Ie,a[3]=Le,a[4]=Re,a[5]=ze,a[6]=Be,a[7]=Ve,a[8]=He,a[9]=Ue,a[10]=We,a[11]=Ge,a[12]=Ke,a[13]=qe,a[14]=Je,a[15]=Ye,a[16]=Xe,a[17]=Ze,a[18]=Qe,o!==0&&(a[19]=o,n.length++),n};Math.imul||(_=g);function v(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var r=0,i=0,a=0;a<n.length-1;a++){var o=i;i=0;for(var s=r&67108863,c=Math.min(a,t.length-1),l=Math.max(0,a-e.length+1);l<=c;l++){var u=a-l,d=(e.words[u]|0)*(t.words[l]|0),f=d&67108863;o=o+(d/67108864|0)|0,f=f+s|0,s=f&67108863,o=o+(f>>>26)|0,i+=o>>>26,o&=67108863}n.words[a]=s,r=o,o=i}return r===0?n.length--:n.words[a]=r,n._strip()}function ee(e,t,n){return v(e,t,n)}i.prototype.mulTo=function(e,t){var n,r=this.length+e.length;return n=this.length===10&&e.length===10?_(this,e,t):r<63?g(this,e,t):r<1024?v(this,e,t):ee(this,e,t),n};function y(e,t){this.x=e,this.y=t}y.prototype.makeRBT=function(e){for(var t=Array(e),n=i.prototype._countBits(e)-1,r=0;r<e;r++)t[r]=this.revBin(r,n,e);return t},y.prototype.revBin=function(e,t,n){if(e===0||e===n-1)return e;for(var r=0,i=0;i<t;i++)r|=(e&1)<<t-i-1,e>>=1;return r},y.prototype.permute=function(e,t,n,r,i,a){for(var o=0;o<a;o++)r[o]=t[e[o]],i[o]=n[e[o]]},y.prototype.transform=function(e,t,n,r,i,a){this.permute(a,e,t,n,r,i);for(var o=1;o<i;o<<=1)for(var s=o<<1,c=Math.cos(2*Math.PI/s),l=Math.sin(2*Math.PI/s),u=0;u<i;u+=s)for(var d=c,f=l,p=0;p<o;p++){var m=n[u+p],h=r[u+p],g=n[u+p+o],_=r[u+p+o],v=d*g-f*_;_=d*_+f*g,g=v,n[u+p]=m+g,r[u+p]=h+_,n[u+p+o]=m-g,r[u+p+o]=h-_,p!==s&&(v=c*d-l*f,f=c*f+l*d,d=v)}},y.prototype.guessLen13b=function(e,t){var n=Math.max(t,e)|1,r=n&1,i=0;for(n=n/2|0;n;n>>>=1)i++;return 1<<i+1+r},y.prototype.conjugate=function(e,t,n){if(!(n<=1))for(var r=0;r<n/2;r++){var i=e[r];e[r]=e[n-r-1],e[n-r-1]=i,i=t[r],t[r]=-t[n-r-1],t[n-r-1]=-i}},y.prototype.normalize13b=function(e,t){for(var n=0,r=0;r<t/2;r++){var i=Math.round(e[2*r+1]/t)*8192+Math.round(e[2*r]/t)+n;e[r]=i&67108863,n=i<67108864?0:i/67108864|0}return e},y.prototype.convert13b=function(e,t,r,i){for(var a=0,o=0;o<t;o++)a+=e[o]|0,r[2*o]=a&8191,a>>>=13,r[2*o+1]=a&8191,a>>>=13;for(o=2*t;o<i;++o)r[o]=0;n(a===0),n(!(a&-8192))},y.prototype.stub=function(e){for(var t=Array(e),n=0;n<e;n++)t[n]=0;return t},y.prototype.mulp=function(e,t,n){var r=2*this.guessLen13b(e.length,t.length),i=this.makeRBT(r),a=this.stub(r),o=Array(r),s=Array(r),c=Array(r),l=Array(r),u=Array(r),d=Array(r),f=n.words;f.length=r,this.convert13b(e.words,e.length,o,r),this.convert13b(t.words,t.length,l,r),this.transform(o,a,s,c,r,i),this.transform(l,a,u,d,r,i);for(var p=0;p<r;p++){var m=s[p]*u[p]-c[p]*d[p];c[p]=s[p]*d[p]+c[p]*u[p],s[p]=m}return this.conjugate(s,c,r),this.transform(s,c,f,a,r,i),this.conjugate(f,a,r),this.normalize13b(f,r),n.negative=e.negative^t.negative,n.length=e.length+t.length,n._strip()},i.prototype.mul=function(e){var t=new i(null);return t.words=Array(this.length+e.length),this.mulTo(e,t)},i.prototype.mulf=function(e){var t=new i(null);return t.words=Array(this.length+e.length),ee(this,e,t)},i.prototype.imul=function(e){return this.clone().mulTo(e,this)},i.prototype.imuln=function(e){var t=e<0;t&&(e=-e),n(typeof e==`number`),n(e<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*e,o=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=o>>>26,this.words[i]=o&67108863}return r!==0&&(this.words[i]=r,this.length++),e===0&&(this.length=1,this._normSign()),t?this.ineg():this},i.prototype.muln=function(e){return this.clone().imuln(e)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(e){var t=h(e);if(t.length===0)return new i(1);for(var n=this,r=0;r<t.length&&t[r]===0;r++,n=n.sqr());if(++r<t.length)for(var a=n.sqr();r<t.length;r++,a=a.sqr())t[r]!==0&&(n=n.mul(a));return n},i.prototype.iushln=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26,i=67108863>>>26-t<<26-t,a;if(t!==0){var o=0;for(a=0;a<this.length;a++){var s=this.words[a]&i,c=(this.words[a]|0)-s<<t;this.words[a]=c|o,o=s>>>26-t}o&&(this.words[a]=o,this.length++)}if(r!==0){for(a=this.length-1;a>=0;a--)this.words[a+r]=this.words[a];for(a=0;a<r;a++)this.words[a]=0;this.length+=r}return this._strip()},i.prototype.ishln=function(e){return n(this.negative===0),this.iushln(e)},i.prototype.iushrn=function(e,t,r){n(typeof e==`number`&&e>=0);var i=t?(t-t%26)/26:0,a=e%26,o=Math.min((e-a)/26,this.length),s=67108863^67108863>>>a<<a,c=r;if(i-=o,i=Math.max(0,i),c){for(var l=0;l<o;l++)c.words[l]=this.words[l];c.length=o}if(o!==0){if(this.length>o)for(this.length-=o,l=0;l<this.length;l++)this.words[l]=this.words[l+o];else this.words[0]=0,this.length=1}var u=0;for(l=this.length-1;l>=0&&(u!==0||l>=i);l--){var d=this.words[l]|0;this.words[l]=u<<26-a|d>>>a,u=d&s}return c&&u!==0&&(c.words[c.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(e,t,r){return n(this.negative===0),this.iushrn(e,t,r)},i.prototype.shln=function(e){return this.clone().ishln(e)},i.prototype.ushln=function(e){return this.clone().iushln(e)},i.prototype.shrn=function(e){return this.clone().ishrn(e)},i.prototype.ushrn=function(e){return this.clone().iushrn(e)},i.prototype.testn=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26,i=1<<t;return this.length<=r?!1:!!(this.words[r]&i)},i.prototype.imaskn=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26;if(n(this.negative===0,`imaskn works only with positive numbers`),this.length<=r)return this;if(t!==0&&r++,this.length=Math.min(r,this.length),t!==0){var i=67108863^67108863>>>t<<t;this.words[this.length-1]&=i}return this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.maskn=function(e){return this.clone().imaskn(e)},i.prototype.iaddn=function(e){return n(typeof e==`number`),n(e<67108864),e<0?this.isubn(-e):this.negative===0?this._iaddn(e):this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this)},i.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},i.prototype.isubn=function(e){if(n(typeof e==`number`),n(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,--this.words[t+1];return this._strip()},i.prototype.addn=function(e){return this.clone().iaddn(e)},i.prototype.subn=function(e){return this.clone().isubn(e)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(e,t,r){var i=e.length+r,a;this._expand(i);var o,s=0;for(a=0;a<e.length;a++){o=(this.words[a+r]|0)+s;var c=(e.words[a]|0)*t;o-=c&67108863,s=(o>>26)-(c/67108864|0),this.words[a+r]=o&67108863}for(;a<this.length-r;a++)o=(this.words[a+r]|0)+s,s=o>>26,this.words[a+r]=o&67108863;if(s===0)return this._strip();for(n(s===-1),s=0,a=0;a<this.length;a++)o=-(this.words[a]|0)+s,s=o>>26,this.words[a]=o&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(e,t){var n=this.length-e.length,r=this.clone(),a=e,o=a.words[a.length-1]|0;n=26-this._countBits(o),n!==0&&(a=a.ushln(n),r.iushln(n),o=a.words[a.length-1]|0);var s=r.length-a.length,c;if(t!==`mod`){c=new i(null),c.length=s+1,c.words=Array(c.length);for(var l=0;l<c.length;l++)c.words[l]=0}var u=r.clone()._ishlnsubmul(a,1,s);u.negative===0&&(r=u,c&&(c.words[s]=1));for(var d=s-1;d>=0;d--){var f=(r.words[a.length+d]|0)*67108864+(r.words[a.length+d-1]|0);for(f=Math.min(f/o|0,67108863),r._ishlnsubmul(a,f,d);r.negative!==0;)f--,r.negative=0,r._ishlnsubmul(a,1,d),r.isZero()||(r.negative^=1);c&&(c.words[d]=f)}return c&&c._strip(),r._strip(),t!==`div`&&n!==0&&r.iushrn(n),{div:c||null,mod:r}},i.prototype.divmod=function(e,t,r){if(n(!e.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var a,o,s;return this.negative!==0&&e.negative===0?(s=this.neg().divmod(e,t),t!==`mod`&&(a=s.div.neg()),t!==`div`&&(o=s.mod.neg(),r&&o.negative!==0&&o.iadd(e)),{div:a,mod:o}):this.negative===0&&e.negative!==0?(s=this.divmod(e.neg(),t),t!==`mod`&&(a=s.div.neg()),{div:a,mod:s.mod}):(this.negative&e.negative)===0?e.length>this.length||this.cmp(e)<0?{div:new i(0),mod:this}:e.length===1?t===`div`?{div:this.divn(e.words[0]),mod:null}:t===`mod`?{div:null,mod:new i(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new i(this.modrn(e.words[0]))}:this._wordDiv(e,t):(s=this.neg().divmod(e.neg(),t),t!==`div`&&(o=s.mod.neg(),r&&o.negative!==0&&o.isub(e)),{div:s.div,mod:o})},i.prototype.div=function(e){return this.divmod(e,`div`,!1).div},i.prototype.mod=function(e){return this.divmod(e,`mod`,!1).mod},i.prototype.umod=function(e){return this.divmod(e,`mod`,!0).mod},i.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=t.mod.abs(),r=e.abs().iushrn(1),a=e.words[0]&1,o=n.cmp(r);if(o<0||a===1&&o===0)return t.div;var s=new i(1);return s.negative=this.negative^e.negative,t.div.iadd(s)},i.prototype.modrn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=(1<<26)%e,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%e;return t?-i:i},i.prototype.modn=function(e){return this.modrn(e)},i.prototype.idivn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/e|0,r=a%e}return this._strip(),t?this.ineg():this},i.prototype.divn=function(e){return this.clone().idivn(e)},i.prototype.egcd=function(e){n(e.negative===0),n(!e.isZero());var t=this,r=e.clone();t=t.negative===0?t.clone():t.umod(e);for(var a=new i(1),o=new i(0),s=new i(0),c=new i(1),l=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++l;for(var u=r.clone(),d=t.clone();!t.isZero();){for(var f=0,p=1;(t.words[0]&p)===0&&f<26;++f,p<<=1);if(f>0)for(t.iushrn(f);f-->0;)(a.isOdd()||o.isOdd())&&(a.iadd(u),o.isub(d)),a.iushrn(1),o.iushrn(1);for(var m=0,h=1;(r.words[0]&h)===0&&m<26;++m,h<<=1);if(m>0)for(r.iushrn(m);m-->0;)(s.isOdd()||c.isOdd())&&(s.iadd(u),c.isub(d)),s.iushrn(1),c.iushrn(1);t.cmp(r)>=0?(t.isub(r),a.isub(s),o.isub(c)):(r.isub(t),s.isub(a),c.isub(o))}return{a:s,b:c,gcd:r.iushln(l)}},i.prototype._invmp=function(e){n(e.negative===0),n(!e.isZero());var t=this,r=e.clone();t=t.negative===0?t.clone():t.umod(e);for(var a=new i(1),o=new i(0),s=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,l=1;(t.words[0]&l)===0&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-->0;)a.isOdd()&&a.iadd(s),a.iushrn(1);for(var u=0,d=1;(r.words[0]&d)===0&&u<26;++u,d<<=1);if(u>0)for(r.iushrn(u);u-->0;)o.isOdd()&&o.iadd(s),o.iushrn(1);t.cmp(r)>=0?(t.isub(r),a.isub(o)):(r.isub(t),o.isub(a))}var f=t.cmpn(1)===0?a:o;return f.cmpn(0)<0&&f.iadd(e),f},i.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),n=e.clone();t.negative=0,n.negative=0;for(var r=0;t.isEven()&&n.isEven();r++)t.iushrn(1),n.iushrn(1);do{for(;t.isEven();)t.iushrn(1);for(;n.isEven();)n.iushrn(1);var i=t.cmp(n);if(i<0){var a=t;t=n,n=a}else if(i===0||n.cmpn(1)===0)break;t.isub(n)}while(1);return n.iushln(r)},i.prototype.invm=function(e){return this.egcd(e).a.umod(e)},i.prototype.isEven=function(){return!(this.words[0]&1)},i.prototype.isOdd=function(){return(this.words[0]&1)==1},i.prototype.andln=function(e){return this.words[0]&e},i.prototype.bincn=function(e){n(typeof e==`number`);var t=e%26,r=(e-t)/26,i=1<<t;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var a=i,o=r;a!==0&&o<this.length;o++){var s=this.words[o]|0;s+=a,a=s>>>26,s&=67108863,this.words[o]=s}return a!==0&&(this.words[o]=a,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(e){var t=e<0;if(this.negative!==0&&!t)return-1;if(this.negative===0&&t)return 1;this._strip();var r;if(this.length>1)r=1;else{t&&(e=-e),n(e<=67108863,`Number is too big`);var i=this.words[0]|0;r=i===e?0:i<e?-1:1}return this.negative===0?r:-r|0},i.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var t=this.ucmp(e);return this.negative===0?t:-t|0},i.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,n=this.length-1;n>=0;n--){var r=this.words[n]|0,i=e.words[n]|0;if(r!==i){r<i?t=-1:r>i&&(t=1);break}}return t},i.prototype.gtn=function(e){return this.cmpn(e)===1},i.prototype.gt=function(e){return this.cmp(e)===1},i.prototype.gten=function(e){return this.cmpn(e)>=0},i.prototype.gte=function(e){return this.cmp(e)>=0},i.prototype.ltn=function(e){return this.cmpn(e)===-1},i.prototype.lt=function(e){return this.cmp(e)===-1},i.prototype.lten=function(e){return this.cmpn(e)<=0},i.prototype.lte=function(e){return this.cmp(e)<=0},i.prototype.eqn=function(e){return this.cmpn(e)===0},i.prototype.eq=function(e){return this.cmp(e)===0},i.red=function(e){return new T(e)},i.prototype.toRed=function(e){return n(!this.red,`Already a number in reduction context`),n(this.negative===0,`red works only with positives`),e.convertTo(this)._forceRed(e)},i.prototype.fromRed=function(){return n(this.red,`fromRed works only with numbers in reduction context`),this.red.convertFrom(this)},i.prototype._forceRed=function(e){return this.red=e,this},i.prototype.forceRed=function(e){return n(!this.red,`Already a number in reduction context`),this._forceRed(e)},i.prototype.redAdd=function(e){return n(this.red,`redAdd works only with red numbers`),this.red.add(this,e)},i.prototype.redIAdd=function(e){return n(this.red,`redIAdd works only with red numbers`),this.red.iadd(this,e)},i.prototype.redSub=function(e){return n(this.red,`redSub works only with red numbers`),this.red.sub(this,e)},i.prototype.redISub=function(e){return n(this.red,`redISub works only with red numbers`),this.red.isub(this,e)},i.prototype.redShl=function(e){return n(this.red,`redShl works only with red numbers`),this.red.shl(this,e)},i.prototype.redMul=function(e){return n(this.red,`redMul works only with red numbers`),this.red._verify2(this,e),this.red.mul(this,e)},i.prototype.redIMul=function(e){return n(this.red,`redMul works only with red numbers`),this.red._verify2(this,e),this.red.imul(this,e)},i.prototype.redSqr=function(){return n(this.red,`redSqr works only with red numbers`),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,`redISqr works only with red numbers`),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,`redSqrt works only with red numbers`),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,`redInvm works only with red numbers`),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,`redNeg works only with red numbers`),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(e){return n(this.red&&!e.red,`redPow(normalNum)`),this.red._verify1(this),this.red.pow(this,e)};var b={k256:null,p224:null,p192:null,p25519:null};function te(e,t){this.name=e,this.p=new i(t,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}te.prototype._tmp=function(){var e=new i(null);return e.words=Array(Math.ceil(this.n/13)),e},te.prototype.ireduce=function(e){var t=e,n;do this.split(t,this.tmp),t=this.imulK(t),t=t.iadd(this.tmp),n=t.bitLength();while(n>this.n);var r=n<this.n?-1:t.ucmp(this.p);return r===0?(t.words[0]=0,t.length=1):r>0?t.isub(this.p):t.strip===void 0?t._strip():t.strip(),t},te.prototype.split=function(e,t){e.iushrn(this.n,0,t)},te.prototype.imulK=function(e){return e.imul(this.k)};function x(){te.call(this,`k256`,`ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f`)}r(x,te),x.prototype.split=function(e,t){for(var n=4194303,r=Math.min(e.length,9),i=0;i<r;i++)t.words[i]=e.words[i];if(t.length=r,e.length<=9){e.words[0]=0,e.length=1;return}var a=e.words[9];for(t.words[t.length++]=a&n,i=10;i<e.length;i++){var o=e.words[i]|0;e.words[i-10]=(o&n)<<4|a>>>22,a=o}a>>>=22,e.words[i-10]=a,a===0&&e.length>10?e.length-=10:e.length-=9},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0;n<e.length;n++){var r=e.words[n]|0;t+=r*977,e.words[n]=t&67108863,t=r*64+(t/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function ne(){te.call(this,`p224`,`ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001`)}r(ne,te);function C(){te.call(this,`p192`,`ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff`)}r(C,te);function w(){te.call(this,`25519`,`7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed`)}r(w,te),w.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var r=(e.words[n]|0)*19+t,i=r&67108863;r>>>=26,e.words[n]=i,t=r}return t!==0&&(e.words[e.length++]=t),e},i._prime=function(e){if(b[e])return b[e];var t;if(e===`k256`)t=new x;else if(e===`p224`)t=new ne;else if(e===`p192`)t=new C;else if(e===`p25519`)t=new w;else throw Error(`Unknown prime `+e);return b[e]=t,t};function T(e){if(typeof e==`string`){var t=i._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),`modulus must be greater than 1`),this.m=e,this.prime=null}T.prototype._verify1=function(e){n(e.negative===0,`red works only with positives`),n(e.red,`red works only with red numbers`)},T.prototype._verify2=function(e,t){n((e.negative|t.negative)===0,`red works only with positives`),n(e.red&&e.red===t.red,`red works only with red numbers`)},T.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(l(e,e.umod(this.m)._forceRed(this)),e)},T.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},T.prototype.add=function(e,t){this._verify2(e,t);var n=e.add(t);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},T.prototype.iadd=function(e,t){this._verify2(e,t);var n=e.iadd(t);return n.cmp(this.m)>=0&&n.isub(this.m),n},T.prototype.sub=function(e,t){this._verify2(e,t);var n=e.sub(t);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},T.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return n.cmpn(0)<0&&n.iadd(this.m),n},T.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},T.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},T.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},T.prototype.isqr=function(e){return this.imul(e,e.clone())},T.prototype.sqr=function(e){return this.mul(e,e)},T.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),t===3){var r=this.m.add(new i(1)).iushrn(2);return this.pow(e,r)}for(var a=this.m.subn(1),o=0;!a.isZero()&&a.andln(1)===0;)o++,a.iushrn(1);n(!a.isZero());var s=new i(1).toRed(this),c=s.redNeg(),l=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new i(2*u*u).toRed(this);this.pow(u,l).cmp(c)!==0;)u.redIAdd(c);for(var d=this.pow(u,a),f=this.pow(e,a.addn(1).iushrn(1)),p=this.pow(e,a),m=o;p.cmp(s)!==0;){for(var h=p,g=0;h.cmp(s)!==0;g++)h=h.redSqr();n(g<m);var _=this.pow(d,new i(1).iushln(m-g-1));f=f.redMul(_),d=_.redSqr(),p=p.redMul(d),m=g}return f},T.prototype.invm=function(e){var t=e._invmp(this.m);return t.negative===0?this.imod(t):(t.negative=0,this.imod(t).redNeg())},T.prototype.pow=function(e,t){if(t.isZero())return new i(1).toRed(this);if(t.cmpn(1)===0)return e.clone();var n=4,r=Array(1<<n);r[0]=new i(1).toRed(this),r[1]=e;for(var a=2;a<r.length;a++)r[a]=this.mul(r[a-1],e);var o=r[0],s=0,c=0,l=t.bitLength()%26;for(l===0&&(l=26),a=t.length-1;a>=0;a--){for(var u=t.words[a],d=l-1;d>=0;d--){var f=u>>d&1;if(o!==r[0]&&(o=this.sqr(o)),f===0&&s===0){c=0;continue}s<<=1,s|=f,c++,(c===n||a===0&&d===0)&&(o=this.mul(o,r[s]),c=0,s=0)}l=26}return o},T.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},T.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},i.mont=function(e){return new E(e)};function E(e){T.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(E,T),E.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},E.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},E.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var n=e.imul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),a=i;return i.cmp(this.m)>=0?a=i.isub(this.m):i.cmpn(0)<0&&(a=i.iadd(this.m)),a._forceRed(this)},E.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new i(0)._forceRed(this);var n=e.mul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),a=n.isub(r).iushrn(this.shift),o=a;return a.cmp(this.m)>=0?o=a.isub(this.m):a.cmpn(0)<0&&(o=a.iadd(this.m)),o._forceRed(this)},E.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}})(t===void 0||t,e)})),be=n({TextDecoder:()=>Ee,TextEncoder:()=>De});function N(e,t,n){return t<=e&&e<=n}function xe(e){if(e===void 0)return{};if(e===Object(e))return e;throw TypeError(`Could not convert argument to dictionary`)}function Se(e){for(var t=String(e),n=t.length,r=0,i=[];r<n;){var a=t.charCodeAt(r);if(a<55296||a>57343)i.push(a);else if(56320<=a&&a<=57343)i.push(65533);else if(55296<=a&&a<=56319){if(r===n-1)i.push(65533);else{var o=e.charCodeAt(r+1);if(56320<=o&&o<=57343){var s=a&1023,c=o&1023;i.push(65536+(s<<10)+c),r+=1}else i.push(65533)}}r+=1}return i}function Ce(e){for(var t=``,n=0;n<e.length;++n){var r=e[n];r<=65535?t+=String.fromCharCode(r):(r-=65536,t+=String.fromCharCode((r>>10)+55296,(r&1023)+56320))}return t}function we(e){this.tokens=[].slice.call(e)}function Te(e,t){if(e)throw TypeError(`Decoder error`);return t||65533}function Ee(e,t){if(!(this instanceof Ee))return new Ee(e,t);if(e=e===void 0?F:String(e).toLowerCase(),e!==F)throw Error(`Encoding not supported. Only utf-8 is supported`);t=xe(t),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=!!t.fatal,this._ignoreBOM=!!t.ignoreBOM,Object.defineProperty(this,"encoding",{value:`utf-8`}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function De(e,t){if(!(this instanceof De))return new De(e,t);if(e=e===void 0?F:String(e).toLowerCase(),e!==F)throw Error(`Encoding not supported. Only utf-8 is supported`);t=xe(t),this._streaming=!1,this._encoder=null,this._options={fatal:!!t.fatal},Object.defineProperty(this,"encoding",{value:`utf-8`})}function Oe(e){var t=e.fatal,n=0,r=0,i=0,a=128,o=191;this.handler=function(e,s){if(s===Ae&&i!==0)return i=0,Te(t);if(s===Ae)return P;if(i===0){if(N(s,0,127))return s;if(N(s,194,223))i=1,n=s-192;else if(N(s,224,239))s===224&&(a=160),s===237&&(o=159),i=2,n=s-224;else if(N(s,240,244))s===240&&(a=144),s===244&&(o=143),i=3,n=s-240;else return Te(t);return n<<=6*i,null}if(!N(s,a,o))return n=i=r=0,a=128,o=191,e.prepend(s),Te(t);if(a=128,o=191,r+=1,n+=s-128<<6*(i-r),r!==i)return null;var c=n;return n=i=r=0,c}}function ke(e){e.fatal,this.handler=function(e,t){if(t===Ae)return P;if(N(t,0,127))return t;var n,r;N(t,128,2047)?(n=1,r=192):N(t,2048,65535)?(n=2,r=224):N(t,65536,1114111)&&(n=3,r=240);for(var i=[(t>>6*n)+r];n>0;){var a=t>>6*(n-1);i.push(128|a&63),--n}return i}}var Ae,P,F,je=e((()=>{Ae=-1,we.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Ae},prepend:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.unshift(t.pop());else this.tokens.unshift(e)},push:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.push(t.shift());else this.tokens.push(e)}},P=-1,F=`utf-8`,Ee.prototype={decode:function(e,t){var n=typeof e==`object`&&e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`object`&&`buffer`in e&&e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array;t=xe(t),this._streaming||(this._decoder=new Oe({fatal:this._fatal}),this._BOMseen=!1),this._streaming=!!t.stream;for(var r=new we(n),i=[],a;!r.endOfStream()&&(a=this._decoder.handler(r,r.read()),a!==P);)a!==null&&(Array.isArray(a)?i.push.apply(i,a):i.push(a));if(!this._streaming){do{if(a=this._decoder.handler(r,r.read()),a===P)break;a!==null&&(Array.isArray(a)?i.push.apply(i,a):i.push(a))}while(!r.endOfStream());this._decoder=null}return i.length&&[`utf-8`].indexOf(this.encoding)!==-1&&!this._ignoreBOM&&!this._BOMseen&&(i[0]===65279?(this._BOMseen=!0,i.shift()):this._BOMseen=!0),Ce(i)}},De.prototype={encode:function(e,t){e=e?String(e):``,t=xe(t),this._streaming||(this._encoder=new ke(this._options)),this._streaming=!!t.stream;for(var n=[],r=new we(Se(e)),i;!r.endOfStream()&&(i=this._encoder.handler(r,r.read()),i!==P);)Array.isArray(i)?n.push.apply(n,i):n.push(i);if(!this._streaming){for(;i=this._encoder.handler(r,r.read()),i!==P;)Array.isArray(i)?n.push.apply(n,i):n.push(i);this._encoder=null}return new Uint8Array(n)}}})),Me=i((e=>{_();var n=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),r=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),i=e&&e.__decorate||function(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a},a=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var i in e)i!=="default"&&Object.hasOwnProperty.call(e,i)&&n(t,e,i);return r(t,e),t},o=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.deserializeUnchecked=e.deserialize=e.serialize=e.BinaryReader=e.BinaryWriter=e.BorshError=e.baseDecode=e.baseEncode=void 0;var s=o(ne()),c=o(C()),l=a((je(),t(be))),u=new(typeof TextDecoder==`function`?TextDecoder:l.TextDecoder)(`utf-8`,{fatal:!0});function d(e){return typeof e==`string`&&(e=v.from(e,`utf8`)),c.default.encode(v.from(e))}e.baseEncode=d;function f(e){return v.from(c.default.decode(e))}e.baseDecode=f;var p=1024,m=class extends Error{constructor(e){super(e),this.fieldPath=[],this.originalMessage=e}addToFieldPath(e){this.fieldPath.splice(0,0,e),this.message=this.originalMessage+`: `+this.fieldPath.join(`.`)}};e.BorshError=m;var h=class{constructor(){this.buf=v.alloc(p),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=v.concat([this.buf,v.alloc(p)]))}writeU8(e){this.maybeResize(),this.buf.writeUInt8(e,this.length),this.length+=1}writeU16(e){this.maybeResize(),this.buf.writeUInt16LE(e,this.length),this.length+=2}writeU32(e){this.maybeResize(),this.buf.writeUInt32LE(e,this.length),this.length+=4}writeU64(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,8)))}writeU128(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,16)))}writeU256(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,32)))}writeU512(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,64)))}writeBuffer(e){this.buf=v.concat([v.from(this.buf.subarray(0,this.length)),e,v.alloc(p)]),this.length+=e.length}writeString(e){this.maybeResize();let t=v.from(e,`utf8`);this.writeU32(t.length),this.writeBuffer(t)}writeFixedArray(e){this.writeBuffer(v.from(e))}writeArray(e,t){this.maybeResize(),this.writeU32(e.length);for(let n of e)this.maybeResize(),t(n)}toArray(){return this.buf.subarray(0,this.length)}};e.BinaryWriter=h;function g(e,t,n){let r=n.value;n.value=function(...e){try{return r.apply(this,e)}catch(e){if(e instanceof RangeError){let t=e.code;if([`ERR_BUFFER_OUT_OF_BOUNDS`,`ERR_OUT_OF_RANGE`].indexOf(t)>=0)throw new m(`Reached the end of buffer when deserializing`)}throw e}}}var ee=class{constructor(e){this.buf=e,this.offset=0}readU8(){let e=this.buf.readUInt8(this.offset);return this.offset+=1,e}readU16(){let e=this.buf.readUInt16LE(this.offset);return this.offset+=2,e}readU32(){let e=this.buf.readUInt32LE(this.offset);return this.offset+=4,e}readU64(){let e=this.readBuffer(8);return new s.default(e,`le`)}readU128(){let e=this.readBuffer(16);return new s.default(e,`le`)}readU256(){let e=this.readBuffer(32);return new s.default(e,`le`)}readU512(){let e=this.readBuffer(64);return new s.default(e,`le`)}readBuffer(e){if(this.offset+e>this.buf.length)throw new m(`Expected buffer length ${e} isn't within bounds`);let t=this.buf.slice(this.offset,this.offset+e);return this.offset+=e,t}readString(){let e=this.readU32(),t=this.readBuffer(e);try{return u.decode(t)}catch(e){throw new m(`Error decoding UTF-8 string: ${e}`)}}readFixedArray(e){return new Uint8Array(this.readBuffer(e))}readArray(e){let t=this.readU32(),n=[];for(let r=0;r<t;++r)n.push(e());return n}};i([g],ee.prototype,`readU8`,null),i([g],ee.prototype,`readU16`,null),i([g],ee.prototype,`readU32`,null),i([g],ee.prototype,`readU64`,null),i([g],ee.prototype,`readU128`,null),i([g],ee.prototype,`readU256`,null),i([g],ee.prototype,`readU512`,null),i([g],ee.prototype,`readString`,null),i([g],ee.prototype,`readFixedArray`,null),i([g],ee.prototype,`readArray`,null),e.BinaryReader=ee;function y(e){return e.charAt(0).toUpperCase()+e.slice(1)}function b(e,t,n,r,i){try{if(typeof r==`string`)i[`write${y(r)}`](n);else if(r instanceof Array){if(typeof r[0]==`number`){if(n.length!==r[0])throw new m(`Expecting byte array of length ${r[0]}, but got ${n.length} bytes`);i.writeFixedArray(n)}else if(r.length===2&&typeof r[1]==`number`){if(n.length!==r[1])throw new m(`Expecting byte array of length ${r[1]}, but got ${n.length} bytes`);for(let t=0;t<r[1];t++)b(e,null,n[t],r[0],i)}else i.writeArray(n,n=>{b(e,t,n,r[0],i)})}else if(r.kind!==void 0)switch(r.kind){case`option`:n==null?i.writeU8(0):(i.writeU8(1),b(e,t,n,r.type,i));break;case`map`:i.writeU32(n.size),n.forEach((n,a)=>{b(e,t,a,r.key,i),b(e,t,n,r.value,i)});break;default:throw new m(`FieldType ${r} unrecognized`)}else te(e,n,i)}catch(e){throw e instanceof m&&e.addToFieldPath(t),e}}function te(e,t,n){if(typeof t.borshSerialize==`function`){t.borshSerialize(n);return}let r=e.get(t.constructor);if(!r)throw new m(`Class ${t.constructor.name} is missing in schema`);if(r.kind===`struct`)r.fields.map(([r,i])=>{b(e,r,t[r],i,n)});else if(r.kind===`enum`){let i=t[r.field];for(let a=0;a<r.values.length;++a){let[o,s]=r.values[a];if(o===i){n.writeU8(a),b(e,o,t[o],s,n);break}}}else throw new m(`Unexpected schema kind: ${r.kind} for ${t.constructor.name}`)}function x(e,t,n=h){let r=new n;return te(e,t,r),r.toArray()}e.serialize=x;function S(e,t,n,r){try{if(typeof n==`string`)return r[`read${y(n)}`]();if(n instanceof Array){if(typeof n[0]==`number`)return r.readFixedArray(n[0]);if(typeof n[1]==`number`){let t=[];for(let i=0;i<n[1];i++)t.push(S(e,null,n[0],r));return t}return r.readArray(()=>S(e,t,n[0],r))}if(n.kind===`option`)return r.readU8()?S(e,t,n.type,r):void 0;if(n.kind===`map`){let i=new Map,a=r.readU32();for(let o=0;o<a;o++){let a=S(e,t,n.key,r),o=S(e,t,n.value,r);i.set(a,o)}return i}return w(e,n,r)}catch(e){throw e instanceof m&&e.addToFieldPath(t),e}}function w(e,t,n){if(typeof t.borshDeserialize==`function`)return t.borshDeserialize(n);let r=e.get(t);if(!r)throw new m(`Class ${t.name} is missing in schema`);if(r.kind===`struct`){let r={};for(let[i,a]of e.get(t).fields)r[i]=S(e,i,a,n);return new t(r)}if(r.kind===`enum`){let i=n.readU8();if(i>=r.values.length)throw new m(`Enum index: ${i} is out of range`);let[a,o]=r.values[i],s=S(e,a,o,n);return new t({[a]:s})}throw new m(`Unexpected schema kind: ${r.kind} for ${t.constructor.name}`)}function T(e,t,n,r=ee){let i=new r(n),a=w(e,t,i);if(i.offset<n.length)throw new m(`Unexpected ${n.length-i.offset} bytes after deserialized data`);return a}e.deserialize=T;function E(e,t,n,r=ee){return w(e,t,new r(n))}e.deserializeUnchecked=E})),Ne=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.s16=e.s8=e.nu64be=e.u48be=e.u40be=e.u32be=e.u24be=e.u16be=e.nu64=e.u48=e.u40=e.u32=e.u24=e.u16=e.u8=e.offset=e.greedy=e.Constant=e.UTF8=e.CString=e.Blob=e.Boolean=e.BitField=e.BitStructure=e.VariantLayout=e.Union=e.UnionLayoutDiscriminator=e.UnionDiscriminator=e.Structure=e.Sequence=e.DoubleBE=e.Double=e.FloatBE=e.Float=e.NearInt64BE=e.NearInt64=e.NearUInt64BE=e.NearUInt64=e.IntBE=e.Int=e.UIntBE=e.UInt=e.OffsetLayout=e.GreedyCount=e.ExternalLayout=e.bindConstructorLayout=e.nameWithProperty=e.Layout=e.uint8ArrayToBuffer=e.checkUint8Array=void 0,e.constant=e.utf8=e.cstr=e.blob=e.unionLayoutDiscriminator=e.union=e.seq=e.bits=e.struct=e.f64be=e.f64=e.f32be=e.f32=e.ns64be=e.s48be=e.s40be=e.s32be=e.s24be=e.s16be=e.ns64=e.s48=e.s40=e.s32=e.s24=void 0;var t=S();function n(e){if(!(e instanceof Uint8Array))throw TypeError(`b must be a Uint8Array`)}e.checkUint8Array=n;function r(e){return n(e),t.Buffer.from(e.buffer,e.byteOffset,e.length)}e.uint8ArrayToBuffer=r;var i=class{constructor(e,t){if(!Number.isInteger(e))throw TypeError(`span must be an integer`);this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw 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){}};e.Layout=i;function a(e,t){return t.property?e+`[`+t.property+`]`:e}e.nameWithProperty=a;function o(e,t){if(typeof e!=`function`)throw TypeError(`Class must be constructor`);if(Object.prototype.hasOwnProperty.call(e,`layout_`))throw Error(`Class is already bound to a layout`);if(!(t&&t instanceof i))throw TypeError(`layout must be a Layout`);if(Object.prototype.hasOwnProperty.call(t,`boundConstructor_`))throw Error(`layout is already bound to a constructor`);e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=(()=>new e),Object.defineProperty(e.prototype,"encode",{value(e,n){return t.encode(this,e,n)},writable:!0}),Object.defineProperty(e,"decode",{value(e,n){return t.decode(e,n)},writable:!0})}e.bindConstructorLayout=o;var s=class extends i{isCount(){throw Error(`ExternalLayout is abstract`)}};e.ExternalLayout=s;var c=class extends s{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw TypeError(`elementSpan must be a (positive) integer`);super(-1,t),this.elementSpan=e}isCount(){return!0}decode(e,t=0){n(e);let r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,n){return 0}};e.GreedyCount=c;var l=class extends s{constructor(e,t=0,n){if(!(e instanceof i))throw TypeError(`layout must be a Layout`);if(!Number.isInteger(t))throw TypeError(`offset must be integer or undefined`);super(e.span,n||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof u||this.layout instanceof d}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,n=0){return this.layout.encode(e,t,n+this.offset)}};e.OffsetLayout=l;var u=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readUIntLE(t,this.span)}encode(e,t,n=0){return r(t).writeUIntLE(e,n,this.span),this.span}};e.UInt=u;var d=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readUIntBE(t,this.span)}encode(e,t,n=0){return r(t).writeUIntBE(e,n,this.span),this.span}};e.UIntBE=d;var f=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readIntLE(t,this.span)}encode(e,t,n=0){return r(t).writeIntLE(e,n,this.span),this.span}};e.Int=f;var p=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readIntBE(t,this.span)}encode(e,t,n=0){return r(t).writeIntBE(e,n,this.span),this.span}};e.IntBE=p;var m=2**32;function h(e){let t=Math.floor(e/m);return{hi32:t,lo32:e-t*m}}function g(e,t){return e*m+t}var _=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e),i=n.readUInt32LE(t);return g(n.readUInt32LE(t+4),i)}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32LE(i.lo32,n),a.writeUInt32LE(i.hi32,n+4),8}};e.NearUInt64=_;var v=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e);return g(n.readUInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32BE(i.hi32,n),a.writeUInt32BE(i.lo32,n+4),8}};e.NearUInt64BE=v;var ee=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e),i=n.readUInt32LE(t);return g(n.readInt32LE(t+4),i)}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32LE(i.lo32,n),a.writeInt32LE(i.hi32,n+4),8}};e.NearInt64=ee;var y=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e);return g(n.readInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeInt32BE(i.hi32,n),a.writeUInt32BE(i.lo32,n+4),8}};e.NearInt64BE=y;var b=class extends i{constructor(e){super(4,e)}decode(e,t=0){return r(e).readFloatLE(t)}encode(e,t,n=0){return r(t).writeFloatLE(e,n),4}};e.Float=b;var te=class extends i{constructor(e){super(4,e)}decode(e,t=0){return r(e).readFloatBE(t)}encode(e,t,n=0){return r(t).writeFloatBE(e,n),4}};e.FloatBE=te;var x=class extends i{constructor(e){super(8,e)}decode(e,t=0){return r(e).readDoubleLE(t)}encode(e,t,n=0){return r(t).writeDoubleLE(e,n),8}};e.Double=x;var ne=class extends i{constructor(e){super(8,e)}decode(e,t=0){return r(e).readDoubleBE(t)}encode(e,t,n=0){return r(t).writeDoubleBE(e,n),8}};e.DoubleBE=ne;var C=class extends i{constructor(e,t,n){if(!(e instanceof i))throw TypeError(`elementLayout must be a Layout`);if(!(t instanceof s&&t.isCount()||Number.isInteger(t)&&0<=t))throw TypeError(`count must be non-negative integer or an unsigned integer ExternalLayout`);let r=-1;!(t instanceof s)&&0<e.span&&(r=t*e.span),super(r,n),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0,r=this.count;if(r instanceof s&&(r=r.decode(e,t)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let i=0;for(;i<r;)n+=this.elementLayout.getSpan(e,t+n),++i}return n}decode(e,t=0){let n=[],r=0,i=this.count;for(i instanceof s&&(i=i.decode(e,t));r<i;)n.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),r+=1;return n}encode(e,t,n=0){let r=this.elementLayout,i=e.reduce((e,i)=>e+r.encode(i,t,n+e),0);return this.count instanceof s&&this.count.encode(e.length,t,n),i}};e.Sequence=C;var w=class extends i{constructor(e,t,n){if(!(Array.isArray(e)&&e.reduce((e,t)=>e&&t instanceof i,!0)))throw TypeError(`fields must be array of Layout instances`);typeof t==`boolean`&&n===void 0&&(n=t,t=void 0);for(let t of e)if(0>t.span&&t.property===void 0)throw Error(`fields cannot contain unnamed variable-length layout`);let r=-1;try{r=e.reduce((e,t)=>e+t.getSpan(),0)}catch{}super(r,t),this.fields=e,this.decodePrefixes=!!n}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;try{n=this.fields.reduce((n,r)=>{let i=r.getSpan(e,t);return t+=i,n+i},0)}catch{throw RangeError(`indeterminate span`)}return n}decode(e,t=0){n(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,n=0){let r=n,i=0,a=0;for(let r of this.fields){let o=r.span;if(a=0<o?o:0,r.property!==void 0){let i=e[r.property];i!==void 0&&(a=r.encode(i,t,n),0>o&&(o=r.getSpan(t,n)))}i=n,n+=o}return i+a-r}fromArray(e){let t=this.makeDestinationObject();for(let n of this.fields)n.property!==void 0&&0<e.length&&(t[n.property]=e.shift());return t}layoutFor(e){if(typeof e!=`string`)throw TypeError(`property must be string`);for(let t of this.fields)if(t.property===e)return t}offsetOf(e){if(typeof e!=`string`)throw TypeError(`property must be string`);let t=0;for(let n of this.fields){if(n.property===e)return t;0>n.span?t=-1:0<=t&&(t+=n.span)}}};e.Structure=w;var T=class{constructor(e){this.property=e}decode(e,t){throw Error(`UnionDiscriminator is abstract`)}encode(e,t,n){throw Error(`UnionDiscriminator is abstract`)}};e.UnionDiscriminator=T;var E=class extends T{constructor(e,t){if(!(e instanceof s&&e.isCount()))throw 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,n){return this.layout.encode(e,t,n)}};e.UnionLayoutDiscriminator=E;var D=class extends i{constructor(e,t,n){let r;if(e instanceof u||e instanceof d)r=new E(new l(e));else if(e instanceof s&&e.isCount())r=new E(e);else if(e instanceof T)r=e;else throw TypeError(`discr must be a UnionDiscriminator or an unsigned integer layout`);if(t===void 0&&(t=null),!(t===null||t instanceof i))throw TypeError(`defaultLayout must be null or a Layout`);if(t!==null){if(0>t.span)throw Error(`defaultLayout must have constant span`);t.property===void 0&&(t=t.replicate(`content`))}let a=-1;t&&(a=t.span,0<=a&&(e instanceof u||e instanceof d)&&(a+=r.layout.span)),super(a,n),this.discriminator=r,this.usesPrefixDiscriminator=e instanceof u||e instanceof d,this.defaultLayout=t,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return o(e)},this.configGetSourceVariant=function(e){o=e.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;let n=this.getVariant(e,t);if(!n)throw Error(`unable to determine span for unrecognized variant`);return n.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 n=this.registry[t];if(n.property&&Object.prototype.hasOwnProperty.call(e,n.property))return n}throw Error(`unable to infer src variant`)}decode(e,t=0){let n,r=this.discriminator,i=r.decode(e,t),a=this.registry[i];if(a===void 0){let a=this.defaultLayout,o=0;this.usesPrefixDiscriminator&&(o=r.layout.span),n=this.makeDestinationObject(),n[r.property]=i,n[a.property]=a.decode(e,t+o)}else n=a.decode(e,t);return n}encode(e,t,n=0){let r=this.getSourceVariant(e);if(r===void 0){let r=this.discriminator,i=this.defaultLayout,a=0;return this.usesPrefixDiscriminator&&(a=r.layout.span),r.encode(e[r.property],t,n),a+i.encode(e[i.property],t,n+a)}return r.encode(e,t,n)}addVariant(e,t,n){let r=new re(this,e,t,n);return this.registry[e]=r,r}getVariant(e,t=0){let n;return n=e instanceof Uint8Array?this.discriminator.decode(e,t):e,this.registry[n]}};e.Union=D;var re=class extends i{constructor(e,t,n,r){if(!(e instanceof D))throw TypeError(`union must be a Union`);if(!Number.isInteger(t)||0>t)throw TypeError(`variant must be a (non-negative) integer`);if(typeof n==`string`&&r===void 0&&(r=n,n=null),n){if(!(n instanceof i))throw TypeError(`layout must be a Layout`);if(e.defaultLayout!==null&&0<=n.span&&n.span>e.defaultLayout.span)throw Error(`variant span exceeds span of containing union`);if(typeof r!=`string`)throw TypeError(`variant must have a String property`)}let a=e.span;0>e.span&&(a=n?n.span:0,0<=a&&e.usesPrefixDiscriminator&&(a+=e.discriminator.layout.span)),super(a,r),this.union=e,this.variant=t,this.layout=n||null}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span);let r=0;return this.layout&&(r=this.layout.getSpan(e,t+n)),n+r}decode(e,t=0){let n=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw Error(`variant mismatch`);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout?n[this.property]=this.layout.decode(e,t+r):this.property?n[this.property]=!0:this.union.usesPrefixDiscriminator&&(n[this.union.discriminator.property]=this.variant),n}encode(e,t,n=0){let r=0;if(this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw TypeError(`variant lacks property `+this.property);this.union.discriminator.encode(this.variant,t,n);let i=r;if(this.layout&&(this.layout.encode(e[this.property],t,n+r),i+=this.layout.getSpan(t,n+r),0<=this.union.span&&i>this.union.span))throw Error(`encoded variant overruns containing union`);return i}fromArray(e){if(this.layout)return this.layout.fromArray(e)}};e.VariantLayout=re;function O(e){return 0>e&&(e+=4294967296),e}var k=class extends i{constructor(e,t,n){if(!(e instanceof u||e instanceof d))throw TypeError(`word must be a UInt or UIntBE layout`);if(typeof t==`string`&&n===void 0&&(n=t,t=!1),4<e.span)throw RangeError(`word cannot exceed 32 bits`);super(e.span,n),this.word=e,this.msb=!!t,this.fields=[];let r=0;this._packedSetValue=function(e){return r=O(e),this},this._packedGetValue=function(){return r}}decode(e,t=0){let n=this.makeDestinationObject(),r=this.word.decode(e,t);this._packedSetValue(r);for(let t of this.fields)t.property!==void 0&&(n[t.property]=t.decode(e));return n}encode(e,t,n=0){let r=this.word.decode(t,n);this._packedSetValue(r);for(let t of this.fields)if(t.property!==void 0){let n=e[t.property];n!==void 0&&t.encode(n)}return this.word.encode(this._packedGetValue(),t,n)}addField(e,t){let n=new ie(this,e,t);return this.fields.push(n),n}addBoolean(e){let t=new ae(this,e);return this.fields.push(t),t}fieldFor(e){if(typeof e!=`string`)throw TypeError(`property must be string`);for(let t of this.fields)if(t.property===e)return t}};e.BitStructure=k;var ie=class{constructor(e,t,n){if(!(e instanceof k))throw TypeError(`container must be a BitStructure`);if(!Number.isInteger(t)||0>=t)throw TypeError(`bits must be positive integer`);let r=8*e.span,i=e.fields.reduce((e,t)=>e+t.bits,0);if(t+i>r)throw Error(`bits too long for span remainder (`+(r-i)+` of `+r+` 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=r-i-t),this.wordMask=O(this.valueMask<<this.start),this.property=n}decode(e,t){return O(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(typeof e!=`number`||!Number.isInteger(e)||e!==O(e&this.valueMask))throw TypeError(a(`BitField.encode`,this)+` value must be integer not exceeding `+this.valueMask);let t=this.container._packedGetValue(),n=O(e<<this.start);this.container._packedSetValue(O(t&~this.wordMask)|n)}};e.BitField=ie;var ae=class extends ie{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)}};e.Boolean=ae;var oe=class extends i{constructor(e,t){if(!(e instanceof s&&e.isCount()||Number.isInteger(e)&&0<=e))throw TypeError(`length must be positive integer or an unsigned integer ExternalLayout`);let n=-1;e instanceof s||(n=e),super(n,t),this.length=e}getSpan(e,t){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),n}decode(e,t=0){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),r(e).slice(t,t+n)}encode(e,t,n){let i=this.length;if(this.length instanceof s&&(i=e.length),!(e instanceof Uint8Array&&i===e.length))throw TypeError(a(`Blob.encode`,this)+` requires (length `+i+`) Uint8Array as src`);if(n+i>t.length)throw RangeError(`encoding overruns Uint8Array`);let o=r(e);return r(t).write(o.toString(`hex`),n,i,`hex`),this.length instanceof s&&this.length.encode(i,t,n),i}};e.Blob=oe;var se=class extends i{constructor(e){super(-1,e)}getSpan(e,t=0){n(e);let r=t;for(;r<e.length&&e[r]!==0;)r+=1;return 1+r-t}decode(e,t=0){let n=this.getSpan(e,t);return r(e).slice(t,t+n-1).toString(`utf-8`)}encode(e,n,i=0){typeof e!=`string`&&(e=String(e));let a=t.Buffer.from(e,`utf8`),o=a.length;if(i+o>n.length)throw RangeError(`encoding overruns Buffer`);let s=r(n);return a.copy(s,i),s[i+o]=0,o+1}};e.CString=se;var A=class extends i{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 TypeError(`maxSpan must be an integer`);super(-1,t),this.maxSpan=e}getSpan(e,t=0){return n(e),e.length-t}decode(e,t=0){let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw RangeError(`text length exceeds maxSpan`);return r(e).slice(t,t+n).toString(`utf-8`)}encode(e,n,i=0){typeof e!=`string`&&(e=String(e));let a=t.Buffer.from(e,`utf8`),o=a.length;if(0<=this.maxSpan&&this.maxSpan<o)throw RangeError(`text length exceeds maxSpan`);if(i+o>n.length)throw RangeError(`encoding overruns Buffer`);return a.copy(r(n),i),o}};e.UTF8=A;var j=class extends i{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,n){return 0}};e.Constant=j,e.greedy=((e,t)=>new c(e,t)),e.offset=((e,t,n)=>new l(e,t,n)),e.u8=(e=>new u(1,e)),e.u16=(e=>new u(2,e)),e.u24=(e=>new u(3,e)),e.u32=(e=>new u(4,e)),e.u40=(e=>new u(5,e)),e.u48=(e=>new u(6,e)),e.nu64=(e=>new _(e)),e.u16be=(e=>new d(2,e)),e.u24be=(e=>new d(3,e)),e.u32be=(e=>new d(4,e)),e.u40be=(e=>new d(5,e)),e.u48be=(e=>new d(6,e)),e.nu64be=(e=>new v(e)),e.s8=(e=>new f(1,e)),e.s16=(e=>new f(2,e)),e.s24=(e=>new f(3,e)),e.s32=(e=>new f(4,e)),e.s40=(e=>new f(5,e)),e.s48=(e=>new f(6,e)),e.ns64=(e=>new ee(e)),e.s16be=(e=>new p(2,e)),e.s24be=(e=>new p(3,e)),e.s32be=(e=>new p(4,e)),e.s40be=(e=>new p(5,e)),e.s48be=(e=>new p(6,e)),e.ns64be=(e=>new y(e)),e.f32=(e=>new b(e)),e.f32be=(e=>new te(e)),e.f64=(e=>new x(e)),e.f64be=(e=>new ne(e)),e.struct=((e,t,n)=>new w(e,t,n)),e.bits=((e,t,n)=>new k(e,t,n)),e.seq=((e,t,n)=>new C(e,t,n)),e.union=((e,t,n)=>new D(e,t,n)),e.unionLayoutDiscriminator=((e,t)=>new E(e,t)),e.blob=((e,t)=>new oe(e,t)),e.cstr=(e=>new se(e)),e.utf8=((e,t)=>new A(e,t)),e.constant=((e,t)=>new j(e,t))}));function Pe(e){return Array.isArray(e)?`%5B`+e.map(Pe).join(`%2C%20`)+`%5D`:typeof e==`bigint`?`${e}n`:encodeURIComponent(String(e!=null&&Object.getPrototypeOf(e)===null?{...e}:e))}function Fe([e,t]){return`${e}=${Pe(t)}`}function Ie(e){let t=Object.entries(e).map(Fe).join(`&`);return btoa(t)}function Le(e,t={}){{let n=`Solana error #${e}; Decode this error by running \`npx @solana/errors decode -- ${e}`;return Object.keys(t).length&&(n+=` '${Ie(t)}'`),`${n}\``}}var Re,ze,Be,Ve,He,Ue,We,Ge=e((()=>{Re=8078e3,ze=8078001,Be=8078004,Ve=8078005,He=8078006,Ue=8078011,We=class extends Error{cause=this.cause;context;constructor(...[e,t]){let n,r;t&&Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([t,i])=>{t===`cause`?r={cause:i.value}:(n===void 0&&(n={__code:e}),Object.defineProperty(n,t,i))});let i=Le(e,n);super(i,r),this.context=Object.freeze(n===void 0?{__code:e}:n),this.name=`SolanaError`}}}));function Ke(e,t){return`fixedSize`in t?t.fixedSize:t.getSizeFromValue(e)}function qe(e){return Object.freeze({...e,encode:t=>{let n=new Uint8Array(Ke(t,e));return e.write(t,n,0),n}})}function Je(e){return Object.freeze({...e,decode:(t,n=0)=>e.read(t,n)[0]})}function Ye(e){return`fixedSize`in e&&typeof e.fixedSize==`number`}function Xe(e,t){if(Ye(e)!==Ye(t))throw new We(Be);if(Ye(e)&&Ye(t)&&e.fixedSize!==t.fixedSize)throw new We(Ve,{decoderFixedSize:t.fixedSize,encoderFixedSize:e.fixedSize});if(!Ye(e)&&!Ye(t)&&e.maxSize!==t.maxSize)throw new We(He,{decoderMaxSize:t.maxSize,encoderMaxSize:e.maxSize});return{...t,...e,decode:t.decode,encode:e.encode,read:t.read,write:e.write}}function Ze(e,t,n=0){if(t.length-n<=0)throw new We(Re,{codecDescription:e})}function Qe(e,t,n,r=0){let i=n.length-r;if(i<t)throw new We(ze,{bytesLength:i,codecDescription:e,expected:t})}function $e(e,t,n){let r=e.byteOffset+(t??0),i=n??e.byteLength,a;return typeof SharedArrayBuffer>`u`?a=e.buffer:e.buffer instanceof SharedArrayBuffer?(a=new ArrayBuffer(e.length),new Uint8Array(a).set(new Uint8Array(e))):a=e.buffer,(r===0||r===-e.byteLength)&&i===e.byteLength?a:a.slice(r,r+i)}var et=e((()=>{Ge()}));function tt(e,t,n,r){if(r<t||r>n)throw new We(Ue,{codecDescription:e,max:n,min:t,value:r})}function nt(e){return e?.endian!==1}function rt(e){return qe({fixedSize:e.size,write(t,n,r){e.range&&tt(e.name,e.range[0],e.range[1],t);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),t,nt(e.config)),n.set(new Uint8Array(i),r),r+e.size}})}function it(e){return Je({fixedSize:e.size,read(t,n=0){Ze(e.name,t,n),Qe(e.name,e.size,t,n);let r=new DataView($e(t,n,e.size));return[e.get(r,nt(e.config)),n+e.size]}})}var at,ot,st,ct=e((()=>{Ge(),et(),at=(e={})=>rt({config:e,name:`u64`,range:[0n,BigInt(`0xffffffffffffffff`)],set:(e,t,n)=>e.setBigUint64(0,BigInt(t),n),size:8}),ot=(e={})=>it({config:e,get:(e,t)=>e.getBigUint64(0,t),name:`u64`,size:8}),st=(e={})=>Xe(at(e),ot(e))}));function lt(e){return ut(e)&&typeof e[Symbol.iterator]==`function`}function ut(e){return typeof e==`object`&&!!e}function dt(e){return ut(e)&&!Array.isArray(e)}function ft(e){return typeof e==`symbol`?e.toString():typeof e==`string`?JSON.stringify(e):`${e}`}function pt(e){let{done:t,value:n}=e.next();return t?void 0:n}function mt(e,t,n,r){if(e===!0)return;e===!1?e={}:typeof e==`string`&&(e={message:e});let{path:i,branch:a}=t,{type:o}=n,{refinement:s,message:c=`Expected a value of type \`${o}\`${s?` with refinement \`${s}\``:``}, but received: \`${ft(r)}\``}=e;return{value:r,type:o,refinement:s,key:i[i.length-1],path:i,branch:a,...e,message:c}}function*ht(e,t,n,r){lt(e)||(e=[e]);for(let i of e){let e=mt(i,t,n,r);e&&(yield e)}}function*gt(e,t,n={}){let{path:r=[],branch:i=[e],coerce:a=!1,mask:o=!1}=n,s={path:r,branch:i,mask:o};a&&(e=t.coercer(e,s));let c=`valid`;for(let r of t.validator(e,s))r.explanation=n.message,c=`not_valid`,yield[r,void 0];for(let[l,u,d]of t.entries(e,s)){let t=gt(u,d,{path:l===void 0?r:[...r,l],branch:l===void 0?i:[...i,u],coerce:a,mask:o,message:n.message});for(let n of t)n[0]?(c=n[0].refinement==null?`not_valid`:`not_refined`,yield[n[0],void 0]):a&&(u=n[1],l===void 0?e=u:e instanceof Map?e.set(l,u):e instanceof Set?e.add(u):ut(e)&&(u!==void 0||l in e)&&(e[l]=u))}if(c!==`not_valid`)for(let r of t.refiner(e,s))r.explanation=n.message,c=`not_refined`,yield[r,void 0];c===`valid`&&(yield[void 0,e])}function _t(e,t,n){let r=bt(e,t,{message:n});if(r[0])throw r[0]}function I(e,t,n){let r=bt(e,t,{coerce:!0,message:n});if(r[0])throw r[0];return r[1]}function vt(e,t,n){let r=bt(e,t,{coerce:!0,mask:!0,message:n});if(r[0])throw r[0];return r[1]}function yt(e,t){return!bt(e,t)[0]}function bt(e,t,n={}){let r=gt(e,t,n),i=pt(r);return i[0]?[new Mt(i[0],function*(){for(let e of r)e[0]&&(yield e[0])}),void 0]:[void 0,i[1]]}function xt(e,t){return new Nt({type:e,schema:null,validator:t})}function St(){return xt(`any`,()=>!0)}function L(e){return new Nt({type:`array`,schema:e,*entries(t){if(e&&Array.isArray(t))for(let[n,r]of t.entries())yield[n,r,e]},coercer(e){return Array.isArray(e)?e.slice():e},validator(e){return Array.isArray(e)||`Expected an array value, but received: ${ft(e)}`}})}function Ct(){return xt(`boolean`,e=>typeof e==`boolean`)}function wt(e){return xt(`instance`,t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${ft(t)}`)}function Tt(e){let t=ft(e),n=typeof e;return new Nt({type:`literal`,schema:n===`string`||n===`number`||n===`boolean`?e:null,validator(n){return n===e||`Expected the literal \`${t}\`, but received: ${ft(n)}`}})}function Et(){return xt(`never`,()=>!1)}function R(e){return new Nt({...e,validator:(t,n)=>t===null||e.validator(t,n),refiner:(t,n)=>t===null||e.refiner(t,n)})}function z(){return xt(`number`,e=>typeof e==`number`&&!isNaN(e)||`Expected a number, but received: ${ft(e)}`)}function B(e){return new Nt({...e,validator:(t,n)=>t===void 0||e.validator(t,n),refiner:(t,n)=>t===void 0||e.refiner(t,n)})}function Dt(e,t){return new Nt({type:`record`,schema:null,*entries(n){if(ut(n))for(let r in n){let i=n[r];yield[r,r,e],yield[r,i,t]}},validator(e){return dt(e)||`Expected an object, but received: ${ft(e)}`},coercer(e){return dt(e)?{...e}:e}})}function V(){return xt(`string`,e=>typeof e==`string`||`Expected a string, but received: ${ft(e)}`)}function Ot(e){let t=Et();return new Nt({type:`tuple`,schema:null,*entries(n){if(Array.isArray(n)){let r=Math.max(e.length,n.length);for(let i=0;i<r;i++)yield[i,n[i],e[i]||t]}},validator(e){return Array.isArray(e)||`Expected an array, but received: ${ft(e)}`},coercer(e){return Array.isArray(e)?e.slice():e}})}function H(e){let t=Object.keys(e);return new Nt({type:`type`,schema:e,*entries(n){if(ut(n))for(let r of t)yield[r,n[r],e[r]]},validator(e){return dt(e)||`Expected an object, but received: ${ft(e)}`},coercer(e){return dt(e)?{...e}:e}})}function kt(e){let t=e.map(e=>e.type).join(` | `);return new Nt({type:`union`,schema:null,coercer(t,n){for(let r of e){let[e,i]=r.validate(t,{coerce:!0,mask:n.mask});if(!e)return i}return t},validator(n,r){let i=[];for(let t of e){let[...e]=gt(n,t,r),[a]=e;if(a[0])for(let[t]of e)t&&i.push(t);else return[]}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${ft(n)}`,...i]}})}function At(){return xt(`unknown`,()=>!0)}function jt(e,t,n){return new Nt({...e,coercer:(r,i)=>yt(r,t)?e.coercer(n(r,i),i):e.coercer(r,i)})}var Mt,Nt,Pt=e((()=>{Mt=class extends TypeError{constructor(e,t){let n,{message:r,explanation:i,...a}=e,{path:o}=e,s=o.length===0?r:`At path: ${o.join(`.`)} -- ${r}`;super(i??s),i!=null&&(this.cause=s),Object.assign(this,a),this.name=this.constructor.name,this.failures=()=>n??=[e,...t()]}},Nt=class{constructor(e){let{type:t,schema:n,validator:r,refiner:i,coercer:a=e=>e,entries:o=function*(){}}=e;this.type=t,this.schema=n,this.entries=o,this.coercer=a,this.validator=r?(e,t)=>ht(r(e,t),t,this,e):()=>[],this.refiner=i?(e,t)=>ht(i(e,t),t,this,e):()=>[]}assert(e,t){return _t(e,this,t)}create(e,t){return I(e,this,t)}is(e){return yt(e,this)}mask(e,t){return vt(e,this,t)}validate(e,t={}){return bt(e,this,t)}}}));function Ft(){if(!It&&(It=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<`u`&&typeof msCrypto.getRandomValues==`function`&&msCrypto.getRandomValues.bind(msCrypto),!It))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return It(Lt)}var It,Lt,Rt=e((()=>{Lt=new Uint8Array(16)})),zt,Bt=e((()=>{zt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i}));function Vt(e){return typeof e==`string`&&zt.test(e)}var Ht=e((()=>{Bt()}));function Ut(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(Wt[e[t+0]]+Wt[e[t+1]]+Wt[e[t+2]]+Wt[e[t+3]]+`-`+Wt[e[t+4]]+Wt[e[t+5]]+`-`+Wt[e[t+6]]+Wt[e[t+7]]+`-`+Wt[e[t+8]]+Wt[e[t+9]]+`-`+Wt[e[t+10]]+Wt[e[t+11]]+Wt[e[t+12]]+Wt[e[t+13]]+Wt[e[t+14]]+Wt[e[t+15]]).toLowerCase();if(!Vt(n))throw TypeError(`Stringified UUID is invalid`);return n}var Wt,Gt,Kt=e((()=>{for(Ht(),Wt=[],Gt=0;Gt<256;++Gt)Wt.push((Gt+256).toString(16).substr(1))}));function qt(e,t,n){var r=t&&n||0,i=t||Array(16);e||={};var a=e.node||Jt,o=e.clockseq===void 0?Yt:e.clockseq;if(a==null||o==null){var s=e.random||(e.rng||Ft)();a??=Jt=[s[0]|1,s[1],s[2],s[3],s[4],s[5]],o??=Yt=(s[6]<<8|s[7])&16383}var c=e.msecs===void 0?Date.now():e.msecs,l=e.nsecs===void 0?Zt+1:e.nsecs,u=c-Xt+(l-Zt)/1e4;if(u<0&&e.clockseq===void 0&&(o=o+1&16383),(u<0||c>Xt)&&e.nsecs===void 0&&(l=0),l>=1e4)throw Error(`uuid.v1(): Can't create more than 10M uuids/sec`);Xt=c,Zt=l,Yt=o,c+=0xb1d069b5400;var d=((c&268435455)*1e4+l)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=d&255;var f=c/4294967296*1e4&268435455;i[r++]=f>>>8&255,i[r++]=f&255,i[r++]=f>>>24&15|16,i[r++]=f>>>16&255,i[r++]=o>>>8|128,i[r++]=o&255;for(var p=0;p<6;++p)i[r+p]=a[p];return t||Ut(i)}var Jt,Yt,Xt,Zt,Qt=e((()=>{Rt(),Kt(),Xt=0,Zt=0}));function $t(e){if(!Vt(e))throw TypeError(`Invalid UUID`);var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=t&255,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=t&255,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=t&255,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=t&255,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=t&255,n}var en=e((()=>{Ht()}));function tn(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}function nn(e,t,n){function r(e,r,i,a){if(typeof e==`string`&&(e=tn(e)),typeof r==`string`&&(r=$t(r)),r.length!==16)throw TypeError(`Namespace must be array-like (16 iterable integer values, 0-255)`);var o=new Uint8Array(16+e.length);if(o.set(r),o.set(e,r.length),o=n(o),o[6]=o[6]&15|t,o[8]=o[8]&63|128,i){a||=0;for(var s=0;s<16;++s)i[a+s]=o[s];return i}return Ut(o)}try{r.name=e}catch{}return r.DNS=rn,r.URL=an,r}var rn,an,on=e((()=>{Kt(),en(),rn=`6ba7b810-9dad-11d1-80b4-00c04fd430c8`,an=`6ba7b811-9dad-11d1-80b4-00c04fd430c8`}));function sn(e){if(typeof e==`string`){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return cn(un(dn(e),e.length*8))}function cn(e){for(var t=[],n=e.length*32,r=`0123456789abcdef`,i=0;i<n;i+=8){var a=e[i>>5]>>>i%32&255,o=parseInt(r.charAt(a>>>4&15)+r.charAt(a&15),16);t.push(o)}return t}function ln(e){return(e+64>>>9<<4)+14+1}function un(e,t){e[t>>5]|=128<<t%32,e[ln(t)-1]=t;for(var n=1732584193,r=-271733879,i=-1732584194,a=271733878,o=0;o<e.length;o+=16){var s=n,c=r,l=i,u=a;n=hn(n,r,i,a,e[o],7,-680876936),a=hn(a,n,r,i,e[o+1],12,-389564586),i=hn(i,a,n,r,e[o+2],17,606105819),r=hn(r,i,a,n,e[o+3],22,-1044525330),n=hn(n,r,i,a,e[o+4],7,-176418897),a=hn(a,n,r,i,e[o+5],12,1200080426),i=hn(i,a,n,r,e[o+6],17,-1473231341),r=hn(r,i,a,n,e[o+7],22,-45705983),n=hn(n,r,i,a,e[o+8],7,1770035416),a=hn(a,n,r,i,e[o+9],12,-1958414417),i=hn(i,a,n,r,e[o+10],17,-42063),r=hn(r,i,a,n,e[o+11],22,-1990404162),n=hn(n,r,i,a,e[o+12],7,1804603682),a=hn(a,n,r,i,e[o+13],12,-40341101),i=hn(i,a,n,r,e[o+14],17,-1502002290),r=hn(r,i,a,n,e[o+15],22,1236535329),n=gn(n,r,i,a,e[o+1],5,-165796510),a=gn(a,n,r,i,e[o+6],9,-1069501632),i=gn(i,a,n,r,e[o+11],14,643717713),r=gn(r,i,a,n,e[o],20,-373897302),n=gn(n,r,i,a,e[o+5],5,-701558691),a=gn(a,n,r,i,e[o+10],9,38016083),i=gn(i,a,n,r,e[o+15],14,-660478335),r=gn(r,i,a,n,e[o+4],20,-405537848),n=gn(n,r,i,a,e[o+9],5,568446438),a=gn(a,n,r,i,e[o+14],9,-1019803690),i=gn(i,a,n,r,e[o+3],14,-187363961),r=gn(r,i,a,n,e[o+8],20,1163531501),n=gn(n,r,i,a,e[o+13],5,-1444681467),a=gn(a,n,r,i,e[o+2],9,-51403784),i=gn(i,a,n,r,e[o+7],14,1735328473),r=gn(r,i,a,n,e[o+12],20,-1926607734),n=_n(n,r,i,a,e[o+5],4,-378558),a=_n(a,n,r,i,e[o+8],11,-2022574463),i=_n(i,a,n,r,e[o+11],16,1839030562),r=_n(r,i,a,n,e[o+14],23,-35309556),n=_n(n,r,i,a,e[o+1],4,-1530992060),a=_n(a,n,r,i,e[o+4],11,1272893353),i=_n(i,a,n,r,e[o+7],16,-155497632),r=_n(r,i,a,n,e[o+10],23,-1094730640),n=_n(n,r,i,a,e[o+13],4,681279174),a=_n(a,n,r,i,e[o],11,-358537222),i=_n(i,a,n,r,e[o+3],16,-722521979),r=_n(r,i,a,n,e[o+6],23,76029189),n=_n(n,r,i,a,e[o+9],4,-640364487),a=_n(a,n,r,i,e[o+12],11,-421815835),i=_n(i,a,n,r,e[o+15],16,530742520),r=_n(r,i,a,n,e[o+2],23,-995338651),n=vn(n,r,i,a,e[o],6,-198630844),a=vn(a,n,r,i,e[o+7],10,1126891415),i=vn(i,a,n,r,e[o+14],15,-1416354905),r=vn(r,i,a,n,e[o+5],21,-57434055),n=vn(n,r,i,a,e[o+12],6,1700485571),a=vn(a,n,r,i,e[o+3],10,-1894986606),i=vn(i,a,n,r,e[o+10],15,-1051523),r=vn(r,i,a,n,e[o+1],21,-2054922799),n=vn(n,r,i,a,e[o+8],6,1873313359),a=vn(a,n,r,i,e[o+15],10,-30611744),i=vn(i,a,n,r,e[o+6],15,-1560198380),r=vn(r,i,a,n,e[o+13],21,1309151649),n=vn(n,r,i,a,e[o+4],6,-145523070),a=vn(a,n,r,i,e[o+11],10,-1120210379),i=vn(i,a,n,r,e[o+2],15,718787259),r=vn(r,i,a,n,e[o+9],21,-343485551),n=fn(n,s),r=fn(r,c),i=fn(i,l),a=fn(a,u)}return[n,r,i,a]}function dn(e){if(e.length===0)return[];for(var t=e.length*8,n=new Uint32Array(ln(t)),r=0;r<t;r+=8)n[r>>5]|=(e[r/8]&255)<<r%32;return n}function fn(e,t){var n=(e&65535)+(t&65535);return(e>>16)+(t>>16)+(n>>16)<<16|n&65535}function pn(e,t){return e<<t|e>>>32-t}function mn(e,t,n,r,i,a){return fn(pn(fn(fn(t,e),fn(r,a)),i),n)}function hn(e,t,n,r,i,a,o){return mn(t&n|~t&r,e,t,i,a,o)}function gn(e,t,n,r,i,a,o){return mn(t&r|n&~r,e,t,i,a,o)}function _n(e,t,n,r,i,a,o){return mn(t^n^r,e,t,i,a,o)}function vn(e,t,n,r,i,a,o){return mn(n^(t|~r),e,t,i,a,o)}var yn=e((()=>{})),bn,xn=e((()=>{on(),yn(),bn=nn(`v3`,48,sn)}));function Sn(e,t,n){e||={};var r=e.random||(e.rng||Ft)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return Ut(r)}var Cn=e((()=>{Rt(),Kt()}));function wn(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function Tn(e,t){return e<<t|e>>>32-t}function En(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e==`string`){var r=unescape(encodeURIComponent(e));e=[];for(var i=0;i<r.length;++i)e.push(r.charCodeAt(i))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var a=e.length/4+2,o=Math.ceil(a/16),s=Array(o),c=0;c<o;++c){for(var l=new Uint32Array(16),u=0;u<16;++u)l[u]=e[c*64+u*4]<<24|e[c*64+u*4+1]<<16|e[c*64+u*4+2]<<8|e[c*64+u*4+3];s[c]=l}s[o-1][14]=(e.length-1)*8/2**32,s[o-1][14]=Math.floor(s[o-1][14]),s[o-1][15]=(e.length-1)*8&4294967295;for(var d=0;d<o;++d){for(var f=new Uint32Array(80),p=0;p<16;++p)f[p]=s[d][p];for(var m=16;m<80;++m)f[m]=Tn(f[m-3]^f[m-8]^f[m-14]^f[m-16],1);for(var h=n[0],g=n[1],_=n[2],v=n[3],ee=n[4],y=0;y<80;++y){var b=Math.floor(y/20),te=Tn(h,5)+wn(b,g,_,v)+ee+t[b]+f[y]>>>0;ee=v,v=_,_=Tn(g,30)>>>0,g=h,h=te}n[0]=n[0]+h>>>0,n[1]=n[1]+g>>>0,n[2]=n[2]+_>>>0,n[3]=n[3]+v>>>0,n[4]=n[4]+ee>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,n[0]&255,n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,n[1]&255,n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,n[2]&255,n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,n[3]&255,n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,n[4]&255]}var Dn=e((()=>{})),On,kn=e((()=>{on(),Dn(),On=nn(`v5`,80,En)})),An,jn=e((()=>{An=`00000000-0000-0000-0000-000000000000`}));function Mn(e){if(!Vt(e))throw TypeError(`Invalid UUID`);return parseInt(e.substr(14,1),16)}var Nn=e((()=>{Ht()})),Pn=n({NIL:()=>An,parse:()=>$t,stringify:()=>Ut,v1:()=>qt,v3:()=>bn,v4:()=>Sn,v5:()=>On,validate:()=>Vt,version:()=>Mn}),Fn=e((()=>{Qt(),xn(),Cn(),kn(),jn(),Nn(),Ht(),Kt(),en()})),In=i(((e,n)=>{var r=(Fn(),t(Pn)).v4;n.exports=function(e,t,n,i){if(typeof e!=`string`)throw TypeError(e+` must be a string`);i||={};let a=typeof i.version==`number`?i.version:2;if(a!==1&&a!==2)throw TypeError(a+` must be 1 or 2`);let o={method:e};if(a===2&&(o.jsonrpc=`2.0`),t){if(typeof t!=`object`&&!Array.isArray(t))throw TypeError(t+` must be an object, array or omitted`);o.params=t}return n===void 0?o.id=(typeof i.generator==`function`?i.generator:function(){return r()})(o,i):a===2&&n===null?i.notificationIdNull&&(o.id=null):o.id=n,o}})),Ln=i(((e,n)=>{var r=(Fn(),t(Pn)).v4,i=In(),a=function(e,t){if(!(this instanceof a))return new a(e,t);t||={},this.options={reviver:t.reviver===void 0?null:t.reviver,replacer:t.replacer===void 0?null:t.replacer,generator:t.generator===void 0?function(){return r()}:t.generator,version:t.version===void 0?2:t.version,notificationIdNull:typeof t.notificationIdNull==`boolean`&&t.notificationIdNull},this.callServer=e};n.exports=a,a.prototype.request=function(e,t,n,r){let a=this,o=null,s=Array.isArray(e)&&typeof t==`function`;if(this.options.version===1&&s)throw TypeError(`JSON-RPC 1.0 does not support batching`);if(s||!s&&e&&typeof e==`object`&&typeof t==`function`)r=t,o=e;else{typeof n==`function`&&(r=n,n=void 0);let a=typeof r==`function`;try{o=i(e,t,n,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(e){if(a){r(e);return}throw e}if(!a)return o}let c;try{c=JSON.stringify(o,this.options.replacer)}catch(e){r(e);return}return this.callServer(c,function(e,t){a._parseResponse(e,t,r)}),o},a.prototype._parseResponse=function(e,t,n){if(e){n(e);return}if(!t){n();return}let r;try{r=JSON.parse(t,this.options.reviver)}catch(e){n(e);return}if(n.length===3){if(Array.isArray(r)){let e=function(e){return e.error!==void 0};n(null,r.filter(e),r.filter(function(t){return!e(t)}));return}n(null,r.error,r.result);return}n(null,r)}}));function Rn(e,t){return new zn(e,t)}var zn,Bn,Vn,Hn=e((()=>{_(),y(),zn=class extends ee.default{socket;constructor(e,t,n){super(),this.socket=new window.WebSocket(e,n),this.socket.onopen=()=>this.emit(`open`),this.socket.onmessage=e=>this.emit(`message`,e.data),this.socket.onerror=e=>this.emit(`error`,e),this.socket.onclose=e=>{this.emit(`close`,e.code,e.reason)}}send(e,t,n){let r=n||t;try{this.socket.send(e),r()}catch(e){r(e)}}close(e,t){this.socket.close(e,t)}addEventListener(e,t,n){this.socket.addEventListener(e,t,n)}},Bn=class{encode(e){return JSON.stringify(e)}decode(e){return JSON.parse(e)}},Vn=class extends ee.default{address;rpc_id;queue;options;autoconnect;ready;reconnect;reconnect_timer_id;reconnect_interval;max_reconnects;rest_options;current_reconnects;generate_request_id;socket;webSocketFactory;dataPack;constructor(e,t=`ws://localhost:8080`,{autoconnect:n=!0,reconnect:r=!0,reconnect_interval:i=1e3,max_reconnects:a=5,...o}={},s,c){super(),this.webSocketFactory=e,this.queue={},this.rpc_id=0,this.address=t,this.autoconnect=n,this.ready=!1,this.reconnect=r,this.reconnect_timer_id=void 0,this.reconnect_interval=i,this.max_reconnects=a,this.rest_options=o,this.current_reconnects=0,this.generate_request_id=s||(()=>typeof this.rpc_id==`number`?++this.rpc_id:Number(this.rpc_id)+1),this.dataPack=c||new Bn,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,n,r){return!r&&typeof n==`object`&&(r=n,n=null),new Promise((i,a)=>{if(!this.ready)return a(Error(`socket not ready`));let o=this.generate_request_id(e,t),s={jsonrpc:`2.0`,method:e,params:t||void 0,id:o};this.socket.send(this.dataPack.encode(s),r,e=>{if(e)return a(e);this.queue[o]={promise:[i,a]},n&&(this.queue[o].timeout=setTimeout(()=>{delete this.queue[o],a(Error(`reply timeout`))},n))})})}async login(e){let t=await this.call(`rpc.login`,e);if(!t)throw Error(`authentication failed`);return t}async listMethods(){return await this.call(`__listMethods`)}notify(e,t){return new Promise((n,r)=>{if(!this.ready)return r(Error(`socket not ready`));let i={jsonrpc:`2.0`,method:e,params:t};this.socket.send(this.dataPack.encode(i),e=>{if(e)return r(e);n()})})}async subscribe(e){typeof e==`string`&&(e=[e]);let t=await this.call(`rpc.on`,e);if(typeof e==`string`&&t[e]!==`ok`)throw 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 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:e})=>{e instanceof ArrayBuffer&&(e=g.from(e).toString());try{e=this.dataPack.decode(e)}catch{return}if(e.notification&&this.listeners(e.notification).length){if(!Object.keys(e.params).length)return this.emit(e.notification);let t=[e.notification];if(e.params.constructor===Object)t.push(e.params);else for(let n=0;n<e.params.length;n++)t.push(e.params[n]);return Promise.resolve().then(()=>{this.emit.apply(this,t)})}if(!this.queue[e.id])return e.method?Promise.resolve().then(()=>{this.emit(e.method,e?.params)}):void 0;`error`in e==`result`in e&&this.queue[e.id].promise[1](Error(`Server response malformed. Response must include either "result" or "error", but not both.`)),this.queue[e.id].timeout&&clearTimeout(this.queue[e.id].timeout),e.error?this.queue[e.id].promise[1](e.error):this.queue[e.id].promise[0](e.result),delete this.queue[e.id]}),this.socket.addEventListener(`error`,e=>this.emit(`error`,e)),this.socket.addEventListener(`close`,({code:n,reason:r})=>{this.ready&&setTimeout(()=>this.emit(`close`,n,r),0),this.ready=!1,this.socket=void 0,n!==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)))})}}}));function Un(e){try{return x.ExtendedPoint.fromHex(e),!0}catch{return!1}}function Wn(e){return e._bn!==void 0}function Gn(e,t){let n=e=>{if(e.span>=0)return e.span;if(typeof e.alloc==`function`)return e.alloc(t[e.property]);if(`count`in e&&`elementLayout`in e){let r=t[e.property];if(Array.isArray(r))return r.length*n(e.elementLayout)}else if(`fields`in e)return Gn({layout:e},t[e.property]);return 0},r=0;return e.layout.fields.forEach(e=>{r+=n(e)}),r}function Kn(e){let t=0,n=0;for(;;){let r=e.shift();if(t|=(r&127)<<n*7,n+=1,!(r&128))break}return t}function qn(e,t){let n=t;for(;;){let t=n&127;if(n>>=7,n==0){e.push(t);break}t|=128,e.push(t)}}function U(e,t){if(!e)throw Error(t||`Assertion failed`)}function Jn(e){if(e.length===0)throw Error(Hr);return e.shift()}function Yn(e,...t){let[n]=t;if(t.length===2?n+(t[1]??0)>e.length:n>=e.length)throw Error(Hr);return e.splice(...t)}function Xn(e){let t=Yn(e,0,4);return t[0]+t[1]*256+t[2]*2**16+t[3]*2**24}function Zn(e){let t=Yn(e,0,8),n=BigInt(0);for(let e=t.length-1;e>=0;e--)n=n<<BigInt(8)|BigInt(t[e]);return U(n<=BigInt(2**53-1),`Expected u64 value to be within the safe integer range`),Number(n)}async function Qn(e,t,n,r){let i=r&&{skipPreflight:r.skipPreflight,preflightCommitment:r.preflightCommitment||r.commitment,maxRetries:r.maxRetries,minContextSlot:r.minContextSlot},a=await e.sendTransaction(t,n,i),o;if(t.recentBlockhash!=null&&t.lastValidBlockHeight!=null)o=(await e.confirmTransaction({abortSignal:r?.abortSignal,signature:a,blockhash:t.recentBlockhash,lastValidBlockHeight:t.lastValidBlockHeight},r&&r.commitment)).value;else if(t.minNonceContextSlot!=null&&t.nonceInfo!=null){let{nonceInstruction:n}=t.nonceInfo,i=n.keys[0].pubkey;o=(await e.confirmTransaction({abortSignal:r?.abortSignal,minContextSlot:t.minNonceContextSlot,nonceAccountPubkey:i,nonceValue:t.nonceInfo.nonce,signature:a},r&&r.commitment)).value}else r?.abortSignal,o=(await e.confirmTransaction(a,r&&r.commitment)).value;if(o.err)throw a==null?Error(`Transaction ${a} failed (${JSON.stringify(o)})`):new ai({action:`send`,signature:a,transactionMessage:`Status: (${JSON.stringify(o)})`});return a}function $n(e){return new Promise(t=>setTimeout(t,e))}function W(e,t){let n=e.layout.span>=0?e.layout.span:Gn(e,t),r=g.alloc(n),i=Object.assign({instruction:e.index},t);return e.layout.encode(i,r),r}function er(e){let t=(0,br.blob)(8,e),n=t.decode.bind(t),r=t.encode.bind(t),i=t,a=st();return i.decode=(e,t)=>{let r=n(e,t);return a.decode(r)},i.encode=(e,t,n)=>{let i=a.encode(e);return r(i,t,n)},i}function tr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function nr(){if(hi)return mi;hi=1;var e=Object.prototype.toString,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};function n(r,i){var a,o,s,c,l,u,d;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 n(r.toJSON(),i);if(d=e.call(r),d===`[object Array]`){for(s=`[`,o=r.length-1,a=0;a<o;a++)s+=n(r[a],!0)+`,`;return o>-1&&(s+=n(r[a],!0)),s+`]`}if(d===`[object Object]`){for(c=t(r).sort(),o=c.length,s=``,a=0;a<o;)l=c[a],u=n(r[l],!1),u!==void 0&&(s&&(s+=`,`),s+=JSON.stringify(l)+`:`+u),a++;return`{`+s+`}`}return JSON.stringify(r);case`function`:case`undefined`:return i?null:void 0;case`string`:return JSON.stringify(r);default:return isFinite(r)?r:null}}return mi=function(e){var t=n(e,!1);if(t!==void 0)return``+t},mi}function rr(e){let t=0;for(;e>1;)e/=2,t++;return t}function ir(e){return e===0?1:(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e|=e>>32,e+1)}function ar(e,t){let n;try{n=e.layout.decode(t)}catch(e){throw Error(`invalid instruction; `+e)}if(n.typeIndex!==e.index)throw Error(`invalid account data; account type mismatch ${n.typeIndex} != ${e.index}`);return n}function or(e){let t=e.match(wi);if(t==null)throw TypeError(`Failed to validate endpoint URL \`${e}\``);let[n,r,i,a]=t,o=e.startsWith(`https:`)?`wss:`:`ws:`,s=i==null?null:parseInt(i.slice(1),10);return`${o}//${r}${s==null?``:`:${s+1}`}${a}`}function sr(e){if(/^https?:/.test(e)===!1)throw TypeError("Endpoint URL must start with `http:` or `https:`.");return e}function G(e){let t,n;if(typeof e==`string`)t=e;else if(e){let{commitment:r,...i}=e;t=r,n=i}return{commitment:t,config:n}}function cr(e){return e.map(e=>`memcmp`in e?{...e,memcmp:{...e.memcmp,encoding:e.memcmp.encoding??`base58`}}:e)}function lr(e){return kt([H({jsonrpc:Tt(`2.0`),id:V(),result:e}),H({jsonrpc:Tt(`2.0`),id:V(),error:H({code:At(),message:V(),data:B(St())})})])}function K(e){return jt(lr(e),ki,t=>`error`in t?t:{...t,result:I(t.result,e)})}function ur(e){return K(H({context:H({slot:z()}),value:e}))}function dr(e){return H({context:H({slot:z()}),value:e})}function fr(e,t){if(e===0)return new Wr({header:t.header,staticAccountKeys:t.accountKeys.map(e=>new Y(e)),recentBlockhash:t.recentBlockhash,compiledInstructions:t.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)})),addressTableLookups:t.addressTableLookups});if(e===1){let e=t.transactionConfig;if(e==null)throw Error("Expected a version 1 transaction message response to have a `transactionConfig`");return new Yr({header:t.header,staticAccountKeys:t.accountKeys.map(e=>new Y(e)),recentBlockhash:t.recentBlockhash,compiledInstructions:t.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)})),transactionConfig:e})}return new Ur(t)}function pr(e,t,n,r,i,a){let o=n||yi,s,c;return r&&(c=async(e,t)=>{let n=await new Promise((n,i)=>{try{r(e,t,(e,t)=>n([e,t]))}catch(e){i(e)}});return await o(...n)}),new xr.default(async(n,r)=>{let a={method:`POST`,body:n,agent:s,headers:Object.assign({"Content-Type":`application/json`},t||{},fo)};try{let t=5,n,s=500;for(;n=c?await c(e,a):await o(e,a),!(n.status!==429||i===!0||(--t,t===0));)await $n(s),s*=2;let l=await n.text();n.ok?r(null,l):r(Error(`${n.status} ${n.statusText}: ${l}`))}catch(e){e instanceof Error&&r(e)}},{})}function mr(e){return(t,n)=>new Promise((r,i)=>{e.request(t,n,(e,t)=>{if(e){i(e);return}r(t)})})}function hr(e){return t=>new Promise((n,r)=>{t.length===0&&n([]);let i=t.map(t=>e.request(t.methodName,t.args));e.request(i,(e,t)=>{if(e){r(e);return}n(t)})})}function gr(e,t){let n=t===!1?`http`:`https`;if(!e)return Ro[n].devnet;let r=Ro[n][e];if(!r)throw Error(`Unknown ${n} cluster: ${e}`);return r}var _r,vr,yr,q,br,xr,Sr,Cr,wr,Tr,J,Er,Dr,Or,kr,Y,Ar,jr,Mr,Nr,Pr,X,Fr,Ir,Lr,Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,Z,Q,$r,ei,ti,ni,ri,ii,ai,$,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo=e((()=>{_(),te(),_r=r(ye()),vr=r(C()),p(),yr=Me(),q=r(Ne()),br=r(Ne()),ct(),Pt(),xr=r(Ln()),Hn(),h(),T(),x.utils.randomPrivateKey,Sr=()=>{let e=x.utils.randomPrivateKey(),t=Cr(e),n=new Uint8Array(64);return n.set(e),n.set(t,32),{publicKey:t,secretKey:n}},Cr=x.getPublicKey,wr=(e,t)=>x.sign(e,t.slice(0,32)),Tr=x.verify,J=e=>g.isBuffer(e)?e:e instanceof Uint8Array?g.from(e.buffer,e.byteOffset,e.byteLength):g.from(e),Er=class{constructor(e){Object.assign(this,e)}encode(){return g.from((0,yr.serialize)(Dr,this))}static decode(e){return(0,yr.deserialize)(Dr,this,e)}static decodeUnchecked(e){return(0,yr.deserializeUnchecked)(Dr,this,e)}},Dr=new Map,kr=1,Y=class e extends Er{constructor(e){if(super({}),this._bn=void 0,Wn(e))this._bn=e._bn;else{if(typeof e==`string`){let t=vr.default.decode(e);if(t.length!=32)throw Error(`Invalid public key input`);this._bn=new _r.default(t)}else this._bn=new _r.default(e);if(this._bn.byteLength()>32)throw Error(`Invalid public key input`)}}static unique(){let t=new e(kr);return kr+=1,new e(t.toBuffer())}equals(e){return this._bn.eq(e._bn)}toBase58(){return vr.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(g);if(e.length===32)return e;let t=g.alloc(32);return e.copy(t,32-e.length),t}get[Symbol.toStringTag](){return`PublicKey(${this.toString()})`}toString(){return this.toBase58()}static async createWithSeed(t,n,r){let i=g.concat([t.toBuffer(),g.from(n),r.toBuffer()]),a=f(i);return new e(a)}static createProgramAddressSync(t,n){let r=g.alloc(0);t.forEach(function(e){if(e.length>32)throw TypeError(`Max seed length exceeded`);r=g.concat([r,J(e)])}),r=g.concat([r,n.toBuffer(),g.from(`ProgramDerivedAddress`)]);let i=f(r);if(Un(i))throw Error(`Invalid seeds, address must fall off the curve`);return new e(i)}static async createProgramAddress(e,t){return this.createProgramAddressSync(e,t)}static findProgramAddressSync(e,t){let n=255,r;for(;n!=0;){try{let i=e.concat(g.from([n]));r=this.createProgramAddressSync(i,t)}catch(e){if(e instanceof TypeError)throw e;n--;continue}return[r,n]}throw Error(`Unable to find a viable program address nonce`)}static async findProgramAddress(e,t){return this.findProgramAddressSync(e,t)}static isOnCurve(t){return Un(new e(t).toBytes())}},Or=Y,Y.default=new Or(`11111111111111111111111111111111`),Dr.set(Y,{kind:`struct`,fields:[[`_bn`,`u256`]]}),new Y(`BPFLoader1111111111111111111111111111111111`),Ar=1232,jr=class extends Error{constructor(e){super(`Signature ${e} has expired: block height exceeded.`),this.signature=void 0,this.signature=e}},Object.defineProperty(jr.prototype,"name",{value:`TransactionExpiredBlockheightExceededError`}),Mr=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(Mr.prototype,"name",{value:`TransactionExpiredTimeoutError`}),Nr=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(Nr.prototype,"name",{value:`TransactionExpiredNonceInvalidError`}),Pr=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];else e-=t.length}get length(){return this.keySegments().flat().length}compileInstructions(e){if(this.length>256)throw Error(`Account index overflow encountered during compilation`);let t=new Map;this.keySegments().flat().forEach((e,n)=>{t.set(e.toBase58(),n)});let n=e=>{let n=t.get(e.toBase58());if(n===void 0)throw Error(`Encountered an unknown instruction account key during compilation`);return n};return e.map(e=>({programIdIndex:n(e.programId),accountKeyIndexes:e.keys.map(e=>n(e.pubkey)),data:e.data}))}},X=(e=`publicKey`)=>q.blob(32,e),Fr=(e=`signature`)=>q.blob(64,e),Ir=(e=`string`)=>{let t=q.struct([q.u32(`length`),q.u32(`lengthPadding`),q.blob(q.offset(q.u32(),-8),`chars`)],e),n=t.decode.bind(t),r=t.encode.bind(t),i=t;return i.decode=(e,t)=>n(e,t).chars.toString(),i.encode=(e,t,n)=>{let i={chars:g.from(e,`utf8`)};return r(i,t,n)},i.alloc=e=>q.u32().span+q.u32().span+g.from(e,`utf8`).length,i},Lr=(e=`authorized`)=>q.struct([X(`staker`),X(`withdrawer`)],e),Rr=(e=`lockup`)=>q.struct([q.ns64(`unixTimestamp`),q.ns64(`epoch`),X(`custodian`)],e),zr=(e=`voteInit`)=>q.struct([X(`nodePubkey`),X(`authorizedVoter`),X(`authorizedWithdrawer`),q.u8(`commission`)],e),Br=(e=`voteAuthorizeWithSeedArgs`)=>q.struct([q.u32(`voteAuthorizationType`),X(`currentAuthorityDerivedKeyOwnerPubkey`),Ir(`currentAuthorityDerivedKeySeed`),X(`newAuthorized`)],e),Vr=class e{constructor(e,t){this.payer=void 0,this.keyMetaMap=void 0,this.payer=e,this.keyMetaMap=t}static compile(t,n){let r=new Map,i=e=>{let t=e.toBase58(),n=r.get(t);return n===void 0&&(n={isSigner:!1,isWritable:!1,isInvoked:!1},r.set(t,n)),n},a=i(n);a.isSigner=!0,a.isWritable=!0;for(let e of t){i(e.programId).isInvoked=!0;for(let t of e.keys){let e=i(t.pubkey);e.isSigner||=t.isSigner,e.isWritable||=t.isWritable}}return new e(n,r)}getMessageComponents(){let e=[...this.keyMetaMap.entries()];U(e.length<=256,`Max static account keys length exceeded`);let t=e.filter(([,e])=>e.isSigner&&e.isWritable),n=e.filter(([,e])=>e.isSigner&&!e.isWritable),r=e.filter(([,e])=>!e.isSigner&&e.isWritable),i=e.filter(([,e])=>!e.isSigner&&!e.isWritable),a={numRequiredSignatures:t.length+n.length,numReadonlySignedAccounts:n.length,numReadonlyUnsignedAccounts:i.length};{U(t.length>0,`Expected at least one writable signer key`);let[e]=t[0];U(e===this.payer.toBase58(),`Expected first writable signer key to be the fee payer`)}return[a,[...t.map(([e])=>new Y(e)),...n.map(([e])=>new Y(e)),...r.map(([e])=>new Y(e)),...i.map(([e])=>new Y(e))]]}extractTableLookup(e){let[t,n]=this.drainKeysFoundInLookupTable(e.state.addresses,e=>!e.isSigner&&!e.isInvoked&&e.isWritable),[r,i]=this.drainKeysFoundInLookupTable(e.state.addresses,e=>!e.isSigner&&!e.isInvoked&&!e.isWritable);if(t.length!==0||r.length!==0)return[{accountKey:e.key,writableIndexes:t,readonlyIndexes:r},{writable:n,readonly:i}]}drainKeysFoundInLookupTable(e,t){let n=[],r=[];for(let[i,a]of this.keyMetaMap.entries())if(t(a)){let t=new Y(i),a=e.findIndex(e=>e.equals(t));a>=0&&(U(a<256,`Max lookup table index exceeded`),n.push(a),r.push(t),this.keyMetaMap.delete(i))}return[n,r]}},Hr=`Reached end of buffer unexpectedly`,Ur=class e{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(e=>new Y(e)),this.recentBlockhash=e.recentBlockhash,this.instructions=e.instructions,this.instructions.forEach(e=>this.indexToProgramIds.set(e.programIdIndex,this.accountKeys[e.programIdIndex]))}get version(){return`legacy`}get staticAccountKeys(){return this.accountKeys}get compiledInstructions(){return this.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)}))}get addressTableLookups(){return[]}getAccountKeys(){return new Pr(this.staticAccountKeys)}static compile(t){let[n,r]=Vr.compile(t.instructions,t.payerKey).getMessageComponents(),i=new Pr(r).compileInstructions(t.instructions).map(e=>({programIdIndex:e.programIdIndex,accounts:e.accountKeyIndexes,data:vr.default.encode(e.data)}));return new e({header:n,accountKeys:r,recentBlockhash:t.recentBlockhash,instructions:i})}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures;return e>=this.header.numRequiredSignatures?e-t<this.accountKeys.length-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}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=[];qn(t,e);let n=this.instructions.map(e=>{let{accounts:t,programIdIndex:n}=e,r=Array.from(vr.default.decode(e.data)),i=[];qn(i,t.length);let a=[];return qn(a,r.length),{programIdIndex:n,keyIndicesCount:g.from(i),keyIndices:t,dataLength:g.from(a),data:r}}),r=[];qn(r,n.length);let i=g.alloc(Ar);g.from(r).copy(i);let a=r.length;n.forEach(e=>{let t=q.struct([q.u8(`programIdIndex`),q.blob(e.keyIndicesCount.length,`keyIndicesCount`),q.seq(q.u8(`keyIndex`),e.keyIndices.length,`keyIndices`),q.blob(e.dataLength.length,`dataLength`),q.seq(q.u8(`userdatum`),e.data.length,`data`)]).encode(e,i,a);a+=t}),i=i.slice(0,a);let o=q.struct([q.blob(1,`numRequiredSignatures`),q.blob(1,`numReadonlySignedAccounts`),q.blob(1,`numReadonlyUnsignedAccounts`),q.blob(t.length,`keyCount`),q.seq(X(`key`),e,`keys`),X(`recentBlockhash`)]),s={numRequiredSignatures:g.from([this.header.numRequiredSignatures]),numReadonlySignedAccounts:g.from([this.header.numReadonlySignedAccounts]),numReadonlyUnsignedAccounts:g.from([this.header.numReadonlyUnsignedAccounts]),keyCount:g.from(t),keys:this.accountKeys.map(e=>J(e.toBytes())),recentBlockhash:vr.default.decode(this.recentBlockhash)},c=g.alloc(2048),l=o.encode(s,c);return i.copy(c,l),c.slice(0,l+i.length)}static from(t){let n=[...t],r=Jn(n);if(r!==(r&127))throw Error(`Versioned messages must be deserialized with VersionedMessage.deserialize()`);let i=Jn(n),a=Jn(n),o=Kn(n),s=[];for(let e=0;e<o;e++){let e=Yn(n,0,32);s.push(new Y(g.from(e)))}let c=Yn(n,0,32),l=Kn(n),u=[];for(let e=0;e<l;e++){let e=Jn(n),t=Yn(n,0,Kn(n)),r=Yn(n,0,Kn(n)),i=vr.default.encode(g.from(r));u.push({programIdIndex:e,accounts:t,data:i})}let d={header:{numRequiredSignatures:r,numReadonlySignedAccounts:i,numReadonlyUnsignedAccounts:a},recentBlockhash:vr.default.encode(g.from(c)),accountKeys:s,instructions:u};return new e(d)}},Wr=class e{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 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 Error(`Failed to get account keys because address table lookups were not resolved`);return new Pr(this.staticAccountKeys,t)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures,n=this.staticAccountKeys.length;return e>=n?e-n<this.addressTableLookups.reduce((e,t)=>e+t.writableIndexes.length,0):e>=this.header.numRequiredSignatures?e-t<n-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}resolveAddressTableLookups(e){let t={writable:[],readonly:[]};for(let n of this.addressTableLookups){let r=e.find(e=>e.key.equals(n.accountKey));if(!r)throw Error(`Failed to find address lookup table account for table key ${n.accountKey.toBase58()}`);for(let e of n.writableIndexes)if(e<r.state.addresses.length)t.writable.push(r.state.addresses[e]);else throw Error(`Failed to find address for index ${e} in address lookup table ${n.accountKey.toBase58()}`);for(let e of n.readonlyIndexes)if(e<r.state.addresses.length)t.readonly.push(r.state.addresses[e]);else throw Error(`Failed to find address for index ${e} in address lookup table ${n.accountKey.toBase58()}`)}return t}static compile(t){let n=Vr.compile(t.instructions,t.payerKey),r=[],i={writable:[],readonly:[]},a=t.addressLookupTableAccounts||[];for(let e of a){let t=n.extractTableLookup(e);if(t!==void 0){let[e,{writable:n,readonly:a}]=t;r.push(e),i.writable.push(...n),i.readonly.push(...a)}}let[o,s]=n.getMessageComponents(),c=new Pr(s,i).compileInstructions(t.instructions);return new e({header:o,staticAccountKeys:s,recentBlockhash:t.recentBlockhash,compiledInstructions:c,addressTableLookups:r})}serialize(){let e=[];qn(e,this.staticAccountKeys.length);let t=this.serializeInstructions(),n=[];qn(n,this.compiledInstructions.length);let r=this.serializeAddressTableLookups(),i=[];qn(i,this.addressTableLookups.length);let a=q.struct([q.u8(`prefix`),q.struct([q.u8(`numRequiredSignatures`),q.u8(`numReadonlySignedAccounts`),q.u8(`numReadonlyUnsignedAccounts`)],`header`),q.blob(e.length,`staticAccountKeysLength`),q.seq(X(),this.staticAccountKeys.length,`staticAccountKeys`),X(`recentBlockhash`),q.blob(n.length,`instructionsLength`),q.blob(t.length,`serializedInstructions`),q.blob(i.length,`addressTableLookupsLength`),q.blob(r.length,`serializedAddressTableLookups`)]),o=new Uint8Array(Ar),s=a.encode({prefix:128,header:this.header,staticAccountKeysLength:new Uint8Array(e),staticAccountKeys:this.staticAccountKeys.map(e=>e.toBytes()),recentBlockhash:vr.default.decode(this.recentBlockhash),instructionsLength:new Uint8Array(n),serializedInstructions:t,addressTableLookupsLength:new Uint8Array(i),serializedAddressTableLookups:r},o);return o.slice(0,s)}serializeInstructions(){let e=0,t=new Uint8Array(Ar);for(let n of this.compiledInstructions){let r=[];qn(r,n.accountKeyIndexes.length);let i=[];qn(i,n.data.length);let a=q.struct([q.u8(`programIdIndex`),q.blob(r.length,`encodedAccountKeyIndexesLength`),q.seq(q.u8(),n.accountKeyIndexes.length,`accountKeyIndexes`),q.blob(i.length,`encodedDataLength`),q.blob(n.data.length,`data`)]);e+=a.encode({programIdIndex:n.programIdIndex,encodedAccountKeyIndexesLength:new Uint8Array(r),accountKeyIndexes:n.accountKeyIndexes,encodedDataLength:new Uint8Array(i),data:n.data},t,e)}return t.slice(0,e)}serializeAddressTableLookups(){let e=0,t=new Uint8Array(Ar);for(let n of this.addressTableLookups){let r=[];qn(r,n.writableIndexes.length);let i=[];qn(i,n.readonlyIndexes.length);let a=q.struct([X(`accountKey`),q.blob(r.length,`encodedWritableIndexesLength`),q.seq(q.u8(),n.writableIndexes.length,`writableIndexes`),q.blob(i.length,`encodedReadonlyIndexesLength`),q.seq(q.u8(),n.readonlyIndexes.length,`readonlyIndexes`)]);e+=a.encode({accountKey:n.accountKey.toBytes(),encodedWritableIndexesLength:new Uint8Array(r),writableIndexes:n.writableIndexes,encodedReadonlyIndexesLength:new Uint8Array(i),readonlyIndexes:n.readonlyIndexes},t,e)}return t.slice(0,e)}static deserialize(t){let n=[...t],r=Jn(n),i=r&127;U(r!==i,`Expected versioned message but received legacy message`);let a=i;U(a===0,`Expected versioned message with version 0 but found version ${a}`);let o={numRequiredSignatures:Jn(n),numReadonlySignedAccounts:Jn(n),numReadonlyUnsignedAccounts:Jn(n)},s=[],c=Kn(n);for(let e=0;e<c;e++)s.push(new Y(Yn(n,0,32)));let l=vr.default.encode(Yn(n,0,32)),u=Kn(n),d=[];for(let e=0;e<u;e++){let e=Jn(n),t=Yn(n,0,Kn(n)),r=Kn(n),i=new Uint8Array(Yn(n,0,r));d.push({programIdIndex:e,accountKeyIndexes:t,data:i})}let f=Kn(n),p=[];for(let e=0;e<f;e++){let e=new Y(Yn(n,0,32)),t=Yn(n,0,Kn(n)),r=Yn(n,0,Kn(n));p.push({accountKey:e,writableIndexes:t,readonlyIndexes:r})}return new e({header:o,staticAccountKeys:s,recentBlockhash:l,compiledInstructions:d,addressTableLookups:p})}},Gr=3,Kr=4,qr=8,Jr=16,Yr=class e{constructor(e){this.header=void 0,this.staticAccountKeys=void 0,this.recentBlockhash=void 0,this.compiledInstructions=void 0,this.transactionConfig=void 0,this.header=e.header,this.staticAccountKeys=e.staticAccountKeys,this.recentBlockhash=e.recentBlockhash,this.compiledInstructions=e.compiledInstructions,this.transactionConfig=e.transactionConfig??{computeUnitLimit:null,heapSize:null,loadedAccountsDataSizeLimit:null,priorityFee:null}}get version(){return 1}get addressTableLookups(){return[]}getAccountKeys(){return new Pr(this.staticAccountKeys)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures,n=this.staticAccountKeys.length;return e>=n?!1:e>=this.header.numRequiredSignatures?e-t<n-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}serialize(){throw Error(`Serialization of version 1 transaction messages is not supported`)}static deserialize(t){let n=[...t],r=Jn(n),i=r&127;U(r!==i,`Expected versioned message but received legacy message`);let a=i;U(a===1,`Expected versioned message with version 1 but found version ${a}`);let o={numRequiredSignatures:Jn(n),numReadonlySignedAccounts:Jn(n),numReadonlyUnsignedAccounts:Jn(n)},s=Xn(n);U(!(s&-32),`Unexpected bits set in the transaction config mask`);let c=s&Gr;U(c===0||c===Gr,`Expected both or neither of the priority fee bits to be set in the transaction config mask`);let l=vr.default.encode(Yn(n,0,32)),u=Jn(n),d=Jn(n),f=[];for(let e=0;e<d;e++)f.push(new Y(Yn(n,0,32)));let p={computeUnitLimit:null,heapSize:null,loadedAccountsDataSizeLimit:null,priorityFee:null};c!==0&&(p.priorityFee=Zn(n)),s&Kr&&(p.computeUnitLimit=Xn(n)),s&qr&&(p.loadedAccountsDataSizeLimit=Xn(n)),s&Jr&&(p.heapSize=Xn(n));let m=[];for(let e=0;e<u;e++){let e=Jn(n),t=Jn(n),r=Jn(n)+Jn(n)*256;m.push({accountKeyIndexesLength:t,dataLength:r,programIdIndex:e})}let h=[];for(let e of m)h.push({programIdIndex:e.programIdIndex,accountKeyIndexes:Yn(n,0,e.accountKeyIndexesLength),data:new Uint8Array(Yn(n,0,e.dataLength))});return U(n.length===0,`Expected no bytes to remain after deserializing a version 1 message`),new e({header:o,staticAccountKeys:f,recentBlockhash:l,compiledInstructions:h,transactionConfig:p})}},Xr={deserializeMessageVersion(e){let t=e[0],n=t&127;return n===t?`legacy`:n},deserialize:e=>{let t=Xr.deserializeMessageVersion(e);if(t===`legacy`)return Ur.from(e);if(t===0)return Wr.deserialize(e);if(t===1)return Yr.deserialize(e);throw Error(`Transaction message version ${t} deserialization is not supported`)}},Zr=function(e){return e[e.BLOCKHEIGHT_EXCEEDED=0]=`BLOCKHEIGHT_EXCEEDED`,e[e.PROCESSED=1]=`PROCESSED`,e[e.TIMED_OUT=2]=`TIMED_OUT`,e[e.NONCE_INVALID=3]=`NONCE_INVALID`,e}({}),Qr=g.alloc(64).fill(0),Z=class{constructor(e){this.keys=void 0,this.programId=void 0,this.data=g.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:n})=>({pubkey:e.toJSON(),isSigner:t,isWritable:n})),programId:this.programId.toJSON(),data:[...this.data]}}},Q=class e{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:n}=e;this.minNonceContextSlot=t,this.nonceInfo=n}else if(Object.prototype.hasOwnProperty.call(e,`lastValidBlockHeight`)){let{blockhash:t,lastValidBlockHeight:n}=e;this.recentBlockhash=t,this.lastValidBlockHeight=n}else{let{recentBlockhash:t,nonceInfo:n}=e;n&&(this.nonceInfo=n),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 Error(`No instructions`);return e.forEach(e=>{`instructions`in e?this.instructions=this.instructions.concat(e.instructions):`data`in e&&`programId`in e&&`keys`in e?this.instructions.push(e):this.instructions.push(new Z(e))}),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,t=this.instructions[0]==this.nonceInfo.nonceInstruction?this.instructions:[this.nonceInfo.nonceInstruction,...this.instructions]):(e=this.recentBlockhash,t=this.instructions),!e)throw Error(`Transaction recentBlockhash required`);t.length;let n;if(this.feePayer)n=this.feePayer;else if(this.signatures.length>0&&this.signatures[0].publicKey)n=this.signatures[0].publicKey;else throw Error(`Transaction fee payer required`);for(let e=0;e<t.length;e++)if(t[e].programId===void 0)throw Error(`Transaction instruction index ${e} has undefined program id`);let r=[],i=[];t.forEach(e=>{e.keys.forEach(e=>{i.push({...e})});let t=e.programId.toString();r.includes(t)||r.push(t)}),r.forEach(e=>{i.push({pubkey:new Y(e),isSigner:!1,isWritable:!1})});let a=[];i.forEach(e=>{let t=e.pubkey.toString(),n=a.findIndex(e=>e.pubkey.toString()===t);n>-1?(a[n].isWritable=a[n].isWritable||e.isWritable,a[n].isSigner=a[n].isSigner||e.isSigner):a.push(e)}),a.sort(function(e,t){return e.isSigner===t.isSigner?e.isWritable===t.isWritable?e.pubkey.toBase58().localeCompare(t.pubkey.toBase58(),`en`,{localeMatcher:`best fit`,usage:`sort`,sensitivity:`variant`,ignorePunctuation:!1,numeric:!1,caseFirst:`lower`}):e.isWritable?-1:1:e.isSigner?-1:1});let o=a.findIndex(e=>e.pubkey.equals(n));if(o>-1){let[e]=a.splice(o,1);e.isSigner=!0,e.isWritable=!0,a.unshift(e)}else a.unshift({pubkey:n,isSigner:!0,isWritable:!0});for(let e of this.signatures){let t=a.findIndex(t=>t.pubkey.equals(e.publicKey));if(t>-1)a[t].isSigner||(a[t].isSigner=!0);else throw Error(`unknown signer: ${e.publicKey.toString()}`)}let s=0,c=0,l=0,u=[],d=[];a.forEach(({pubkey:e,isSigner:t,isWritable:n})=>{t?(u.push(e.toString()),s+=1,n||(c+=1)):(d.push(e.toString()),n||(l+=1))});let f=u.concat(d),p=t.map(e=>{let{data:t,programId:n}=e;return{programIdIndex:f.indexOf(n.toString()),accounts:e.keys.map(e=>f.indexOf(e.pubkey.toString())),data:vr.default.encode(t)}});return p.forEach(e=>{U(e.programIdIndex>=0),e.accounts.forEach(e=>U(e>=0))}),new Ur({header:{numRequiredSignatures:s,numReadonlySignedAccounts:c,numReadonlyUnsignedAccounts:l},accountKeys:f,recentBlockhash:e,instructions:p})}_compile(){let e=this.compileMessage(),t=e.accountKeys.slice(0,e.header.numRequiredSignatures);return this.signatures.length===t.length&&this.signatures.every((e,n)=>t[n].equals(e.publicKey))||(this.signatures=t.map(e=>({signature:null,publicKey:e}))),e}serializeMessage(){return this._compile().serialize()}async getEstimatedFee(e){return(await e.getFeeForMessage(this.compileMessage())).value}setSigners(...e){if(e.length===0)throw Error(`No signers`);let t=new Set;this.signatures=e.filter(e=>{let n=e.toString();return!t.has(n)&&(t.add(n),!0)}).map(e=>({signature:null,publicKey:e}))}sign(...e){if(e.length===0)throw Error(`No signers`);let t=new Set,n=[];for(let r of e){let e=r.publicKey.toString();t.has(e)||(t.add(e),n.push(r))}this.signatures=n.map(e=>({signature:null,publicKey:e.publicKey}));let r=this._compile();this._partialSign(r,...n)}partialSign(...e){if(e.length===0)throw Error(`No signers`);let t=new Set,n=[];for(let r of e){let e=r.publicKey.toString();t.has(e)||(t.add(e),n.push(r))}let r=this._compile();this._partialSign(r,...n)}_partialSign(e,...t){let n=e.serialize();t.forEach(e=>{let t=wr(n,e.secretKey);this._addSignature(e.publicKey,J(t))})}addSignature(e,t){this._compile(),this._addSignature(e,t)}_addSignature(e,t){U(t.length===64);let n=this.signatures.findIndex(t=>e.equals(t.publicKey));if(n<0)throw Error(`unknown signer: ${e.toString()}`);this.signatures[n].signature=g.from(t)}verifySignatures(e=!0){return!this._getMessageSignednessErrors(this.serializeMessage(),e)}_getMessageSignednessErrors(e,t){let n={};for(let{signature:r,publicKey:i}of this.signatures)r===null?t&&(n.missing||=[]).push(i):Tr(r,e,i.toBytes())||(n.invalid||=[]).push(i);return n.invalid||n.missing?n:void 0}serialize(e){let{requireAllSignatures:t,verifySignatures:n}=Object.assign({requireAllSignatures:!0,verifySignatures:!0},e),r=this.serializeMessage();if(n){let e=this._getMessageSignednessErrors(r,t);if(e){let t=`Signature verification failed.`;throw e.invalid&&(t+=`\nInvalid signature for public key${e.invalid.length===1?``:`(s)`} [\`${e.invalid.map(e=>e.toBase58()).join("`, `")}\`].`),e.missing&&(t+=`\nMissing signature for public key${e.missing.length===1?``:`(s)`} [\`${e.missing.map(e=>e.toBase58()).join("`, `")}\`].`),Error(t)}}return this._serialize(r)}_serialize(e){let{signatures:t}=this,n=[];qn(n,t.length);let r=n.length+t.length*64+e.length,i=g.alloc(r);return U(t.length<256),g.from(n).copy(i,0),t.forEach(({signature:e},t)=>{e!==null&&(U(e.length===64,`signature has invalid length`),g.from(e).copy(i,n.length+t*64))}),e.copy(i,n.length+t.length*64),U(i.length<=Ar,`Transaction too large: ${i.length} > ${Ar}`),i}get keys(){return U(this.instructions.length===1),this.instructions[0].keys.map(e=>e.pubkey)}get programId(){return U(this.instructions.length===1),this.instructions[0].programId}get data(){return U(this.instructions.length===1),this.instructions[0].data}static from(t){let n=[...t],r=Kn(n),i=[];for(let e=0;e<r;e++){let e=Yn(n,0,64);i.push(vr.default.encode(g.from(e)))}return e.populate(Ur.from(n),i)}static populate(t,n=[]){let r=new e;return r.recentBlockhash=t.recentBlockhash,t.header.numRequiredSignatures>0&&(r.feePayer=t.accountKeys[0]),n.forEach((e,n)=>{let i={signature:e==vr.default.encode(Qr)?null:vr.default.decode(e),publicKey:t.accountKeys[n]};r.signatures.push(i)}),t.instructions.forEach(e=>{let n=e.accounts.map(e=>{let n=t.accountKeys[e];return{pubkey:n,isSigner:r.signatures.some(e=>e.publicKey.toString()===n.toString())||t.isAccountSigner(e),isWritable:t.isAccountWritable(e)}});r.instructions.push(new Z({keys:n,programId:t.accountKeys[e.programIdIndex],data:vr.default.decode(e.data)}))}),r._message=t,r._json=r.toJSON(),r}},$r=class e{get version(){return this.message.version}constructor(e,t){if(this.signatures=void 0,this.message=void 0,t!==void 0)U(t.length===e.header.numRequiredSignatures,`Expected signatures length to be equal to the number of required signatures`),this.signatures=t;else{let t=[];for(let n=0;n<e.header.numRequiredSignatures;n++)t.push(new Uint8Array(64));this.signatures=t}this.message=e}serialize(){let e=this.message.serialize(),t=[];qn(t,this.signatures.length);let n=q.struct([q.blob(t.length,`encodedSignaturesLength`),q.seq(Fr(),this.signatures.length,`signatures`),q.blob(e.length,`serializedMessage`)]),r=new Uint8Array(2048),i=n.encode({encodedSignaturesLength:new Uint8Array(t),signatures:this.signatures,serializedMessage:e},r);return r.slice(0,i)}static deserialize(t){if(t[0]===129)return this.deserializeV1(t);let n=[...t],r=[],i=Kn(n);for(let e=0;e<i;e++)r.push(new Uint8Array(Yn(n,0,64)));let a=Xr.deserialize(new Uint8Array(n));return new e(a,r)}static deserializeV1(t){let n=t[1],r=n*64,i=t.length-r;U(i>0,`Expected transaction to have enough bytes for its signatures`);let a=Xr.deserialize(t.slice(0,i)),o=[];for(let e=0;e<n;e++){let n=i+e*64;o.push(t.slice(n,n+64))}return new e(a,o)}sign(e){let t=this.message.serialize(),n=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures);for(let r of e){let e=n.findIndex(e=>e.equals(r.publicKey));U(e>=0,`Cannot sign with non signer key ${r.publicKey.toBase58()}`),this.signatures[e]=wr(t,r.secretKey)}}addSignature(e,t){U(t.byteLength===64,`Signature must be 64 bytes long`);let n=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures).findIndex(t=>t.equals(e));U(n>=0,`Can not add signature; \`${e.toBase58()}\` is not required to sign this transaction`),this.signatures[n]=t}},ei=1e3/(160/64),ti=new Y(`SysvarC1ock11111111111111111111111111111111`),new Y(`SysvarEpochSchedu1e111111111111111111111111`),new Y(`Sysvar1nstructions1111111111111111111111111`),ni=new Y(`SysvarRecentB1ockHashes11111111111111111111`),ri=new Y(`SysvarRent111111111111111111111111111111111`),new Y(`SysvarRewards111111111111111111111111111111`),new Y(`SysvarS1otHashes111111111111111111111111111`),new Y(`SysvarS1otHistory11111111111111111111111111`),ii=new Y(`SysvarStakeHistory1111111111111111111111111`),ai=class extends Error{constructor({action:e,signature:t,transactionMessage:n,logs:r}){let i=r?`Logs: \n${JSON.stringify(r.slice(-10),null,2)}. `:``,a="\nCatch the `SendTransactionError` and call `getLogs()` on it for full details.",o;switch(e){case`send`:o=`Transaction ${t} resulted in an error. \n${n}. `+i+a;break;case`simulate`:o=`Simulation failed. \nMessage: ${n}. \n`+i+a;break;default:o=`Unknown action '${(e=>e)(e)}'`}super(o),this.signature=void 0,this.transactionMessage=void 0,this.transactionLogs=void 0,this.signature=t,this.transactionMessage=n,this.transactionLogs=r||void 0}get transactionError(){return{message:this.transactionMessage,logs:Array.isArray(this.transactionLogs)?this.transactionLogs:void 0}}get logs(){let e=this.transactionLogs;if(!(typeof e==`object`&&e&&`then`in e))return e}async getLogs(e){return Array.isArray(this.transactionLogs)||(this.transactionLogs=new Promise((t,n)=>{e.getTransaction(this.signature).then(e=>{if(e&&e.meta&&e.meta.logMessages){let n=e.meta.logMessages;this.transactionLogs=n,t(n)}else n(Error(`Log messages not found`))}).catch(n)})),await this.transactionLogs}},$=class extends Error{constructor({code:e,message:t,data:n},r){super(r==null?t:`${r}: ${t}`),this.code=void 0,this.data=void 0,this.code=e,this.data=n,this.name=`SolanaJSONRPCError`}},oi=q.nu64(`lamportsPerSignature`),si=q.struct([q.u32(`version`),q.u32(`state`),X(`authorizedPubkey`),X(`nonce`),q.struct([oi],`feeCalculator`)]),ci=si.span,li=class e{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(t){let n=si.decode(J(t),0);return new e({authorizedPubkey:new Y(n.authorizedPubkey),nonce:new Y(n.nonce).toString(),feeCalculator:n.feeCalculator})}},ui=Object.freeze({Create:{index:0,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`),q.ns64(`space`),X(`programId`)])},Assign:{index:1,layout:q.struct([q.u32(`instruction`),X(`programId`)])},Transfer:{index:2,layout:q.struct([q.u32(`instruction`),er(`lamports`)])},CreateWithSeed:{index:3,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),q.ns64(`lamports`),q.ns64(`space`),X(`programId`)])},AdvanceNonceAccount:{index:4,layout:q.struct([q.u32(`instruction`)])},WithdrawNonceAccount:{index:5,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},InitializeNonceAccount:{index:6,layout:q.struct([q.u32(`instruction`),X(`authorized`)])},AuthorizeNonceAccount:{index:7,layout:q.struct([q.u32(`instruction`),X(`authorized`)])},Allocate:{index:8,layout:q.struct([q.u32(`instruction`),q.ns64(`space`)])},AllocateWithSeed:{index:9,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),q.ns64(`space`),X(`programId`)])},AssignWithSeed:{index:10,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),X(`programId`)])},TransferWithSeed:{index:11,layout:q.struct([q.u32(`instruction`),er(`lamports`),Ir(`seed`),X(`programId`)])},UpgradeNonceAccount:{index:12,layout:q.struct([q.u32(`instruction`)])}}),di=class e{constructor(){}static createAccount(e){let t=ui.Create,n=W(t,{lamports:e.lamports,space:e.space,programId:J(e.programId.toBuffer())});return new Z({keys:[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!0,isWritable:!0}],programId:this.programId,data:n})}static transfer(e){let t,n;if(`basePubkey`in e){let r=ui.TransferWithSeed;t=W(r,{lamports:BigInt(e.lamports),seed:e.seed,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.fromPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}else{let r=ui.Transfer;t=W(r,{lamports:BigInt(e.lamports)}),n=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}static assign(e){let t,n;if(`basePubkey`in e){let r=ui.AssignWithSeed;t=W(r,{base:J(e.basePubkey.toBuffer()),seed:e.seed,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let r=ui.Assign;t=W(r,{programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}static createAccountWithSeed(e){let t=ui.CreateWithSeed,n=W(t,{base:J(e.basePubkey.toBuffer()),seed:e.seed,lamports:e.lamports,space:e.space,programId:J(e.programId.toBuffer())}),r=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!1,isWritable:!0}];return e.basePubkey.equals(e.fromPubkey)||r.push({pubkey:e.basePubkey,isSigner:!0,isWritable:!1}),new Z({keys:r,programId:this.programId,data:n})}static createNonceAccount(t){let n=new Q;`basePubkey`in t&&`seed`in t?n.add(e.createAccountWithSeed({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,basePubkey:t.basePubkey,seed:t.seed,lamports:t.lamports,space:ci,programId:this.programId})):n.add(e.createAccount({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,lamports:t.lamports,space:ci,programId:this.programId}));let r={noncePubkey:t.noncePubkey,authorizedPubkey:t.authorizedPubkey};return n.add(this.nonceInitialize(r)),n}static nonceInitialize(e){let t=ui.InitializeNonceAccount,n=W(t,{authorized:J(e.authorizedPubkey.toBuffer())}),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:this.programId,data:n};return new Z(r)}static nonceAdvance(e){let t=ui.AdvanceNonceAccount,n=W(t),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n};return new Z(r)}static nonceWithdraw(e){let t=ui.WithdrawNonceAccount,n=W(t,{lamports:e.lamports});return new Z({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:ri,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n})}static nonceAuthorize(e){let t=ui.AuthorizeNonceAccount,n=W(t,{authorized:J(e.newAuthorizedPubkey.toBuffer())});return new Z({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n})}static allocate(e){let t,n;if(`basePubkey`in e){let r=ui.AllocateWithSeed;t=W(r,{base:J(e.basePubkey.toBuffer()),seed:e.seed,space:e.space,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let r=ui.Allocate;t=W(r,{space:e.space}),n=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}},di.programId=new Y(`11111111111111111111111111111111`),fi=932,pi=class e{constructor(){}static getMinNumSignatures(t){return 2*(Math.ceil(t/e.chunkSize)+1+1)}static async load(t,n,r,i,a){{let e=await t.getMinimumBalanceForRentExemption(a.length),o=await t.getAccountInfo(r.publicKey,`confirmed`),s=null;if(o!==null){if(o.executable)return!1;o.data.length!==a.length&&(s||=new Q,s.add(di.allocate({accountPubkey:r.publicKey,space:a.length}))),o.owner.equals(i)||(s||=new Q,s.add(di.assign({accountPubkey:r.publicKey,programId:i}))),o.lamports<e&&(s||=new Q,s.add(di.transfer({fromPubkey:n.publicKey,toPubkey:r.publicKey,lamports:e-o.lamports})))}else s=new Q().add(di.createAccount({fromPubkey:n.publicKey,newAccountPubkey:r.publicKey,lamports:e>0?e:1,space:a.length,programId:i}));s!==null&&await Qn(t,s,[n,r],{commitment:`confirmed`})}let o=q.struct([q.u32(`instruction`),q.u32(`offset`),q.u32(`bytesLength`),q.u32(`bytesLengthPadding`),q.seq(q.u8(`byte`),q.offset(q.u32(),-8),`bytes`)]),s=e.chunkSize,c=0,l=a,u=[];for(;l.length>0;){let e=l.slice(0,s),a=g.alloc(s+16);o.encode({instruction:0,offset:c,bytes:e,bytesLength:0,bytesLengthPadding:0},a);let d=new Q().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0}],programId:i,data:a});u.push(Qn(t,d,[n,r],{commitment:`confirmed`})),t._rpcEndpoint.includes(`solana.com`)&&await $n(250),c+=s,l=l.slice(s)}await Promise.all(u);{let e=q.struct([q.u32(`instruction`)]),a=g.alloc(e.span);e.encode({instruction:1},a);let o=new Q().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:i,data:a}),s=`processed`,c=await t.sendTransaction(o,[n,r],{preflightCommitment:s}),{context:l,value:u}=await t.confirmTransaction({signature:c,lastValidBlockHeight:o.lastValidBlockHeight,blockhash:o.recentBlockhash},s);if(u.err)throw Error(`Transaction ${c} failed (${JSON.stringify(u)})`);for(;;){try{if(await t.getSlot({commitment:s})>l.slot)break}catch{}await new Promise(e=>setTimeout(e,Math.round(ei/2)))}}return!0}},pi.chunkSize=fi,new Y(`BPFLoader2111111111111111111111111111111111`),gi=tr(nr()),_i=32,vi=class{constructor(e,t,n,r,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=n,this.firstNormalEpoch=r,this.firstNormalSlot=i}getEpoch(e){return this.getEpochAndSlotIndex(e)[0]}getEpochAndSlotIndex(e){if(e<this.firstNormalSlot){let t=rr(ir(e+_i+1))-rr(_i)-1;return[t,e-(this.getSlotsInEpoch(t)-_i)]}{let t=e-this.firstNormalSlot,n=Math.floor(t/this.slotsPerEpoch);return[this.firstNormalEpoch+n,t%this.slotsPerEpoch]}}getFirstSlotInEpoch(e){return e<=this.firstNormalEpoch?(2**e-1)*_i:(e-this.firstNormalEpoch)*this.slotsPerEpoch+this.firstNormalSlot}getLastSlotInEpoch(e){return this.getFirstSlotInEpoch(e)+this.getSlotsInEpoch(e)-1}getSlotsInEpoch(e){return e<this.firstNormalEpoch?2**(e+rr(_i)):this.slotsPerEpoch}},yi=globalThis.fetch,bi=class extends Vn{constructor(e,t,n){super(e=>{let n=Rn(e,{autoconnect:!0,max_reconnects:5,reconnect:!0,reconnect_interval:1e3,...t});return`socket`in n?this.underlyingSocket=n.socket:this.underlyingSocket=n,n},e,t,n),this.underlyingSocket=void 0}call(...e){let t=this.underlyingSocket?.readyState;return t===1?super.call(...e):Promise.reject(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(Error("Tried to send a JSON-RPC notification `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+`)`))}},xi=56,Si=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=ar(Ci,e),n=e.length-xi;U(n>=0,`lookup table is invalid`),U(n%32==0,`lookup table is invalid`);let r=n/32,{addresses:i}=q.struct([q.seq(X(),r,`addresses`)]).decode(e.slice(xi));return{deactivationSlot:t.deactivationSlot,lastExtendedSlot:t.lastExtendedSlot,lastExtendedSlotStartIndex:t.lastExtendedStartIndex,authority:t.authority.length===0?void 0:new Y(t.authority[0]),addresses:i.map(e=>new Y(e))}}},Ci={index:1,layout:q.struct([q.u32(`typeIndex`),er(`deactivationSlot`),q.nu64(`lastExtendedSlot`),q.u8(`lastExtendedStartIndex`),q.u8(),q.seq(X(),q.offset(q.u8(),-1),`authority`)])},wi=/^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i,Ti=jt(wt(Y),V(),e=>new Y(e)),Ei=Ot([V(),Tt(`base64`)]),Di=jt(wt(g),Ei,e=>g.from(e[0],`base64`)),Oi=3e4,ki=lr(At()),Ai=H({foundation:z(),foundationTerm:z(),initial:z(),taper:z(),terminal:z()}),ji=K(L(R(H({epoch:z(),effectiveSlot:z(),amount:z(),postBalance:z(),commission:B(R(z()))})))),Mi=L(H({slot:z(),prioritizationFee:z()})),Ni=H({total:z(),validator:z(),foundation:z(),epoch:z()}),Pi=H({epoch:z(),slotIndex:z(),slotsInEpoch:z(),absoluteSlot:z(),blockHeight:B(z()),transactionCount:B(z())}),Fi=H({slotsPerEpoch:z(),leaderScheduleSlotOffset:z(),warmup:Ct(),firstNormalEpoch:z(),firstNormalSlot:z()}),Ii=Dt(V(),L(z())),Li=R(kt([H({}),V()])),Ri=H({err:Li}),zi=Tt(`receivedSignature`),Bi=H({"solana-core":V(),"feature-set":B(z())}),Vi=H({program:V(),programId:Ti,parsed:At()}),Hi=H({programId:Ti,accounts:L(Ti),data:V()}),Ui=ur(H({err:R(kt([H({}),V()])),logs:R(L(V())),accounts:B(R(L(R(H({executable:Ct(),owner:V(),lamports:z(),data:L(V()),rentEpoch:B(z())}))))),unitsConsumed:B(z()),returnData:B(R(H({programId:V(),data:Ot([V(),Tt(`base64`)])}))),innerInstructions:B(R(L(H({index:z(),instructions:L(kt([Vi,Hi]))}))))})),Wi=ur(H({byIdentity:Dt(V(),L(z())),range:H({firstSlot:z(),lastSlot:z()})})),Gi=K(Ai),Ki=K(Ni),qi=K(Mi),Ji=K(Pi),Yi=K(Fi),Xi=K(Ii),Zi=K(z()),Qi=ur(H({total:z(),circulating:z(),nonCirculating:z(),nonCirculatingAccounts:L(Ti)})),$i=H({amount:V(),uiAmount:R(z()),decimals:z(),uiAmountString:B(V())}),ea=ur(L(H({address:Ti,amount:V(),uiAmount:R(z()),decimals:z(),uiAmountString:B(V())}))),ta=ur(L(H({pubkey:Ti,account:H({executable:Ct(),owner:Ti,lamports:z(),data:Di,rentEpoch:z()})}))),na=H({program:V(),parsed:At(),space:z()}),ra=ur(L(H({pubkey:Ti,account:H({executable:Ct(),owner:Ti,lamports:z(),data:na,rentEpoch:z()})}))),ia=ur(L(H({lamports:z(),address:Ti}))),aa=H({executable:Ct(),owner:Ti,lamports:z(),data:Di,rentEpoch:z()}),oa=H({pubkey:Ti,account:aa}),sa=jt(kt([wt(g),na]),kt([Ei,na]),e=>Array.isArray(e)?I(e,Di):e),ca=H({executable:Ct(),owner:Ti,lamports:z(),data:sa,rentEpoch:z()}),la=H({pubkey:Ti,account:ca}),ua=H({state:kt([Tt(`active`),Tt(`inactive`),Tt(`activating`),Tt(`deactivating`)]),active:z(),inactive:z()}),da=K(L(H({signature:V(),slot:z(),err:Li,memo:R(V()),blockTime:B(R(z()))}))),fa=K(L(H({signature:V(),slot:z(),err:Li,memo:R(V()),blockTime:B(R(z()))}))),pa=H({subscription:z(),result:dr(aa)}),ma=H({pubkey:Ti,account:aa}),ha=H({subscription:z(),result:dr(ma)}),ga=H({parent:z(),slot:z(),root:z()}),_a=H({subscription:z(),result:ga}),va=kt([H({type:kt([Tt(`firstShredReceived`),Tt(`completed`),Tt(`optimisticConfirmation`),Tt(`root`)]),slot:z(),timestamp:z()}),H({type:Tt(`createdBank`),parent:z(),slot:z(),timestamp:z()}),H({type:Tt(`frozen`),slot:z(),timestamp:z(),stats:H({numTransactionEntries:z(),numSuccessfulTransactions:z(),numFailedTransactions:z(),maxTransactionsPerEntry:z()})}),H({type:Tt(`dead`),slot:z(),timestamp:z(),err:V()})]),ya=H({subscription:z(),result:va}),ba=H({subscription:z(),result:dr(kt([Ri,zi]))}),xa=H({subscription:z(),result:z()}),Sa=H({pubkey:V(),gossip:R(V()),tpu:R(V()),rpc:R(V()),version:R(V())}),Ca=H({votePubkey:V(),nodePubkey:V(),activatedStake:z(),epochVoteAccount:Ct(),epochCredits:L(Ot([z(),z(),z()])),commission:z(),lastVote:z(),rootSlot:R(z())}),wa=K(H({current:L(Ca),delinquent:L(Ca)})),Ta=kt([Tt(`processed`),Tt(`confirmed`),Tt(`finalized`)]),Ea=H({slot:z(),confirmations:R(z()),err:Li,confirmationStatus:B(Ta)}),Da=ur(L(R(Ea))),Oa=K(z()),ka=H({accountKey:Ti,writableIndexes:L(z()),readonlyIndexes:L(z())}),Aa=H({computeUnitLimit:R(z()),heapSize:R(z()),loadedAccountsDataSizeLimit:R(z()),priorityFee:R(z())}),ja=H({signatures:L(V()),message:H({accountKeys:L(V()),header:H({numRequiredSignatures:z(),numReadonlySignedAccounts:z(),numReadonlyUnsignedAccounts:z()}),instructions:L(H({accounts:L(z()),data:V(),programIdIndex:z()})),recentBlockhash:V(),addressTableLookups:B(L(ka)),transactionConfig:B(R(Aa))})}),Ma=H({pubkey:Ti,signer:Ct(),writable:Ct(),source:B(kt([Tt(`transaction`),Tt(`lookupTable`)]))}),Na=H({accountKeys:L(Ma),signatures:L(V())}),Pa=H({parsed:At(),program:V(),programId:Ti}),Fa=H({accounts:L(Ti),data:V(),programId:Ti}),Ia=kt([Fa,Pa]),La=kt([H({parsed:At(),program:V(),programId:V()}),H({accounts:L(V()),data:V(),programId:V()})]),Ra=jt(Ia,La,e=>`accounts`in e?I(e,Fa):I(e,Pa)),za=H({signatures:L(V()),message:H({accountKeys:L(Ma),instructions:L(Ra),recentBlockhash:V(),addressTableLookups:B(R(L(ka))),transactionConfig:B(R(Aa))})}),Ba=H({accountIndex:z(),mint:V(),owner:B(V()),programId:B(V()),uiTokenAmount:$i}),Va=H({writable:L(Ti),readonly:L(Ti)}),Ha=H({err:Li,fee:z(),innerInstructions:B(R(L(H({index:z(),instructions:L(H({accounts:L(z()),data:V(),programIdIndex:z()}))})))),preBalances:L(z()),postBalances:L(z()),logMessages:B(R(L(V()))),preTokenBalances:B(R(L(Ba))),postTokenBalances:B(R(L(Ba))),loadedAddresses:B(Va),computeUnitsConsumed:B(z()),costUnits:B(z())}),Ua=H({err:Li,fee:z(),innerInstructions:B(R(L(H({index:z(),instructions:L(Ra)})))),preBalances:L(z()),postBalances:L(z()),logMessages:B(R(L(V()))),preTokenBalances:B(R(L(Ba))),postTokenBalances:B(R(L(Ba))),loadedAddresses:B(Va),computeUnitsConsumed:B(z()),costUnits:B(z())}),Wa=kt([Tt(0),Tt(1),Tt(`legacy`)]),Ga=H({pubkey:V(),lamports:z(),postBalance:R(z()),rewardType:R(V()),commission:B(R(z()))}),Ka=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:ja,meta:R(Ha),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),qa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Ja=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:Na,meta:R(Ha),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Ya=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:za,meta:R(Ua),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Xa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:Na,meta:R(Ua),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Za=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Qa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:ja,meta:R(Ha)})),rewards:B(L(Ga)),blockTime:R(z())}))),$a=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),signatures:L(V()),blockTime:R(z())}))),eo=K(R(H({slot:z(),meta:R(Ha),blockTime:B(R(z())),transaction:ja,version:B(Wa)}))),to=K(R(H({slot:z(),transaction:za,meta:R(Ua),blockTime:B(R(z())),version:B(Wa)}))),no=ur(H({blockhash:V(),lastValidBlockHeight:z()})),ro=ur(Ct()),io=H({slot:z(),numTransactions:z(),numSlots:z(),samplePeriodSecs:z()}),ao=K(L(io)),oo=ur(R(H({feeCalculator:H({lamportsPerSignature:z()})}))),so=K(V()),co=K(V()),lo=H({err:Li,logs:L(V()),signature:V()}),uo=H({result:dr(lo),subscription:z()}),fo={"solana-client":`js/1.99.0`},po=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 e={};return async t=>{let{commitment:n,config:r}=G(t),i=this._buildArgs([],n,void 0,r),a=gi(i);return e[a]=e[a]??(async()=>{try{let e=I(await this._rpcRequest(`getBlockHeight`,i),K(z()));if(`error`in e)throw new $(e.error,`failed to get block height information`);return e.result}finally{delete e[a]}})(),await e[a]}})();let n,r,i,a,o,s;t&&typeof t==`string`?this._commitment=t:t&&(this._commitment=t.commitment,this._confirmTransactionInitialTimeout=t.confirmTransactionInitialTimeout,n=t.wsEndpoint,r=t.httpHeaders,i=t.fetch,a=t.fetchMiddleware,o=t.disableRetryOnRateLimit,s=t.httpAgent),this._rpcEndpoint=sr(e),this._rpcWsEndpoint=n||or(e),this._rpcClient=pr(e,r,i,a,o,s),this._rpcRequest=mr(this._rpcClient),this._rpcBatchRequest=hr(this._rpcClient),this._rpcWebSocket=new bi(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:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,void 0,r),a=I(await this._rpcRequest(`getBalance`,i),ur(z()));if(`error`in a)throw new $(a.error,`failed to get balance for ${e.toBase58()}`);return a.result}async getBalance(e,t){return await this.getBalanceAndContext(e,t).then(e=>e.value).catch(t=>{throw Error(`failed to get balance of account `+e.toBase58()+`: `+t)})}async getBlockTime(e){let t=I(await this._rpcRequest(`getBlockTime`,[e]),K(R(z())));if(`error`in t)throw new $(t.error,`failed to get block time for slot ${e}`);return t.result}async getMinimumLedgerSlot(){let e=I(await this._rpcRequest(`minimumLedgerSlot`,[]),K(z()));if(`error`in e)throw new $(e.error,`failed to get minimum ledger slot`);return e.result}async getFirstAvailableBlock(){let e=I(await this._rpcRequest(`getFirstAvailableBlock`,[]),Zi);if(`error`in e)throw new $(e.error,`failed to get first available block`);return e.result}async getSupply(e){let t={};t=typeof e==`string`?{commitment:e}:e?{...e,commitment:e&&e.commitment||this.commitment}:{commitment:this.commitment};let n=I(await this._rpcRequest(`getSupply`,[t]),Qi);if(`error`in n)throw new $(n.error,`failed to get supply`);return n.result}async getTokenSupply(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenSupply`,n),ur($i));if(`error`in r)throw new $(r.error,`failed to get token supply`);return r.result}async getTokenAccountBalance(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenAccountBalance`,n),ur($i));if(`error`in r)throw new $(r.error,`failed to get token account balance`);return r.result}async getTokenAccountsByOwner(e,t,n){let{commitment:r,config:i}=G(n),a=[e.toBase58()];`mint`in t?a.push({mint:t.mint.toBase58()}):a.push({programId:t.programId.toBase58()});let o=this._buildArgs(a,r,`base64`,i),s=I(await this._rpcRequest(`getTokenAccountsByOwner`,o),ta);if(`error`in s)throw new $(s.error,`failed to get token accounts owned by account ${e.toBase58()}`);return s.result}async getParsedTokenAccountsByOwner(e,t,n){let r=[e.toBase58()];`mint`in t?r.push({mint:t.mint.toBase58()}):r.push({programId:t.programId.toBase58()});let i=this._buildArgs(r,n,`jsonParsed`),a=I(await this._rpcRequest(`getTokenAccountsByOwner`,i),ra);if(`error`in a)throw new $(a.error,`failed to get token accounts owned by account ${e.toBase58()}`);return a.result}async getLargestAccounts(e){let t={...e,commitment:e&&e.commitment||this.commitment},n=t.filter||t.commitment?[t]:[],r=I(await this._rpcRequest(`getLargestAccounts`,n),ia);if(`error`in r)throw new $(r.error,`failed to get largest accounts`);return r.result}async getTokenLargestAccounts(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenLargestAccounts`,n),ea);if(`error`in r)throw new $(r.error,`failed to get token largest accounts`);return r.result}async getAccountInfoAndContext(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`base64`,r),a=I(await this._rpcRequest(`getAccountInfo`,i),ur(R(aa)));if(`error`in a)throw new $(a.error,`failed to get info about account ${e.toBase58()}`);return a.result}async getParsedAccountInfo(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getAccountInfo`,i),ur(R(ca)));if(`error`in a)throw new $(a.error,`failed to get info about account ${e.toBase58()}`);return a.result}async getAccountInfo(e,t){try{return(await this.getAccountInfoAndContext(e,t)).value}catch(t){throw Error(`failed to get info about account `+e.toBase58()+`: `+t)}}async getMultipleParsedAccounts(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>e.toBase58()),a=this._buildArgs([i],n,`jsonParsed`,r),o=I(await this._rpcRequest(`getMultipleAccounts`,a),ur(L(R(ca))));if(`error`in o)throw new $(o.error,`failed to get info for accounts ${i}`);return o.result}async getMultipleAccountsInfoAndContext(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>e.toBase58()),a=this._buildArgs([i],n,`base64`,r),o=I(await this._rpcRequest(`getMultipleAccounts`,a),ur(L(R(aa))));if(`error`in o)throw new $(o.error,`failed to get info for accounts ${i}`);return o.result}async getMultipleAccountsInfo(e,t){return(await this.getMultipleAccountsInfoAndContext(e,t)).value}async getStakeActivation(e,t,n){let{commitment:r,config:i}=G(t),a=this._buildArgs([e.toBase58()],r,void 0,{...i,epoch:n??i?.epoch}),o=I(await this._rpcRequest(`getStakeActivation`,a),K(ua));if(`error`in o)throw new $(o.error,`failed to get Stake Activation ${e.toBase58()}`);return o.result}async getProgramAccounts(e,t){let{commitment:n,config:r}=G(t),{encoding:i,...a}=r||{},o=this._buildArgs([e.toBase58()],n,i||`base64`,{...a,...a.filters?{filters:cr(a.filters)}:null}),s=await this._rpcRequest(`getProgramAccounts`,o),c=L(oa),l=a.withContext===!0?I(s,ur(c)):I(s,K(c));if(`error`in l)throw new $(l.error,`failed to get accounts owned by program ${e.toBase58()}`);return l.result}async getParsedProgramAccounts(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getProgramAccounts`,i),K(L(la)));if(`error`in a)throw new $(a.error,`failed to get accounts owned by program ${e.toBase58()}`);return a.result}async confirmTransaction(e,t){let n;if(typeof e==`string`)n=e;else{let t=e;if(t.abortSignal?.aborted)return Promise.reject(t.abortSignal.reason);n=t.signature}let r;try{r=vr.default.decode(n)}catch{throw Error(`signature must be base58 encoded: `+n)}return U(r.length===64,`signature has invalid length`),typeof e==`string`?await this.confirmTransactionUsingLegacyTimeoutStrategy({commitment:t||this.commitment,signature:n}):`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,n)=>{e!=null&&(e.aborted?n(e.reason):e.addEventListener(`abort`,()=>{n(e.reason)}))})}getTransactionConfirmationPromise({commitment:e,signature:t}){let n,r,i=!1;return{abortConfirmation:()=>{r&&=(r(),void 0),n!=null&&(this.removeSignatureListener(n),n=void 0)},confirmationPromise:new Promise((a,o)=>{try{n=this.onSignature(t,(e,t)=>{n=void 0;let r={context:t,value:e};a({__type:Zr.PROCESSED,response:r})},e);let s=new Promise(e=>{n==null?e():r=this._onSubscriptionStateChange(n,t=>{t===`subscribed`&&e()})});(async()=>{if(await s,i)return;let n=await this.getSignatureStatus(t);if(i||n==null)return;let{context:r,value:c}=n;if(c!=null){if(c?.err)o(c.err);else{switch(e){case`confirmed`:case`single`:case`singleGossip`:if(c.confirmationStatus===`processed`)return;break;case`finalized`:case`max`:case`root`:if(c.confirmationStatus===`processed`||c.confirmationStatus===`confirmed`)return}i=!0,a({__type:Zr.PROCESSED,response:{context:r,value:c}})}}})()}catch(e){o(e)}})}}async confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:e,strategy:{abortSignal:t,lastValidBlockHeight:n,signature:r}}){let i=!1,a=new Promise(t=>{let r=async()=>{try{return await this.getBlockHeight(e)}catch{return-1}};(async()=>{let e=await r();if(!i){for(;e<=n;)if(await $n(1e3),i||(e=await r(),i))return;t({__type:Zr.BLOCKHEIGHT_EXCEEDED})}})()}),{abortConfirmation:o,confirmationPromise:s}=this.getTransactionConfirmationPromise({commitment:e,signature:r}),c=this.getCancellationPromise(t),l;try{let e=await Promise.race([c,s,a]);if(e.__type===Zr.PROCESSED)l=e.response;else throw new jr(r)}finally{i=!0,o()}return l}async confirmTransactionUsingDurableNonceStrategy({commitment:e,strategy:{abortSignal:t,minContextSlot:n,nonceAccountPubkey:r,nonceValue:i,signature:a}}){let o=!1,s=new Promise(t=>{let a=i,s=null,c=async()=>{try{let{context:t,value:i}=await this.getNonceAndContext(r,{commitment:e,minContextSlot:n});return s=t.slot,i?.nonce}catch{return a}};(async()=>{if(a=await c(),!o)for(;;){if(i!==a){t({__type:Zr.NONCE_INVALID,slotInWhichNonceDidAdvance:s});return}if(await $n(2e3),o||(a=await c(),o))return}})()}),{abortConfirmation:c,confirmationPromise:l}=this.getTransactionConfirmationPromise({commitment:e,signature:a}),u=this.getCancellationPromise(t),d;try{let t=await Promise.race([u,l,s]);if(t.__type===Zr.PROCESSED)d=t.response;else{let r;for(;;){let e=await this.getSignatureStatus(a);if(e==null)break;if(e.context.slot<(t.slotInWhichNonceDidAdvance??n)){await $n(400);continue}r=e;break}if(r?.value){let t=e||`finalized`,{confirmationStatus:n}=r.value;switch(t){case`processed`:case`recent`:if(n!==`processed`&&n!==`confirmed`&&n!==`finalized`)throw new Nr(a);break;case`confirmed`:case`single`:case`singleGossip`:if(n!==`confirmed`&&n!==`finalized`)throw new Nr(a);break;case`finalized`:case`max`:case`root`:if(n!==`finalized`)throw new Nr(a)}d={context:r.context,value:{err:r.value.err}}}else throw new Nr(a)}}finally{o=!0,c()}return d}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:e,signature:t}){let n,r=new Promise(t=>{let r=this._confirmTransactionInitialTimeout||6e4;switch(e){case`processed`:case`recent`:case`single`:case`confirmed`:case`singleGossip`:r=this._confirmTransactionInitialTimeout||3e4}n=setTimeout(()=>t({__type:Zr.TIMED_OUT,timeoutMs:r}),r)}),{abortConfirmation:i,confirmationPromise:a}=this.getTransactionConfirmationPromise({commitment:e,signature:t}),o;try{let e=await Promise.race([a,r]);if(e.__type===Zr.PROCESSED)o=e.response;else throw new Mr(t,e.timeoutMs/1e3)}finally{clearTimeout(n),i()}return o}async getClusterNodes(){let e=I(await this._rpcRequest(`getClusterNodes`,[]),K(L(Sa)));if(`error`in e)throw new $(e.error,`failed to get cluster nodes`);return e.result}async getVoteAccounts(e){let t=this._buildArgs([],e),n=I(await this._rpcRequest(`getVoteAccounts`,t),wa);if(`error`in n)throw new $(n.error,`failed to get vote accounts`);return n.result}async getSlot(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getSlot`,r),K(z()));if(`error`in i)throw new $(i.error,`failed to get slot`);return i.result}async getSlotLeader(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getSlotLeader`,r),K(V()));if(`error`in i)throw new $(i.error,`failed to get slot leader`);return i.result}async getSlotLeaders(e,t){let n=[e,t],r=I(await this._rpcRequest(`getSlotLeaders`,n),K(L(Ti)));if(`error`in r)throw new $(r.error,`failed to get slot leaders`);return r.result}async getSignatureStatus(e,t){let{context:n,value:r}=await this.getSignatureStatuses([e],t);return U(r.length===1),{context:n,value:r[0]}}async getSignatureStatuses(e,t){let n=[e];t&&n.push(t);let r=I(await this._rpcRequest(`getSignatureStatuses`,n),Da);if(`error`in r)throw new $(r.error,`failed to get signature status`);return r.result}async getTransactionCount(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getTransactionCount`,r),K(z()));if(`error`in i)throw new $(i.error,`failed to get transaction count`);return i.result}async getTotalSupply(e){return(await this.getSupply({commitment:e,excludeNonCirculatingAccountsList:!0})).value.total}async getInflationGovernor(e){let t=this._buildArgs([],e),n=I(await this._rpcRequest(`getInflationGovernor`,t),Gi);if(`error`in n)throw new $(n.error,`failed to get inflation`);return n.result}async getInflationReward(e,t,n){let{commitment:r,config:i}=G(n),a=this._buildArgs([e.map(e=>e.toBase58())],r,void 0,{...i,epoch:t??i?.epoch}),o=I(await this._rpcRequest(`getInflationReward`,a),ji);if(`error`in o)throw new $(o.error,`failed to get inflation reward`);return o.result}async getInflationRate(){let e=I(await this._rpcRequest(`getInflationRate`,[]),Ki);if(`error`in e)throw new $(e.error,`failed to get inflation rate`);return e.result}async getEpochInfo(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getEpochInfo`,r),Ji);if(`error`in i)throw new $(i.error,`failed to get epoch info`);return i.result}async getEpochSchedule(){let e=I(await this._rpcRequest(`getEpochSchedule`,[]),Yi);if(`error`in e)throw new $(e.error,`failed to get epoch schedule`);let t=e.result;return new vi(t.slotsPerEpoch,t.leaderScheduleSlotOffset,t.warmup,t.firstNormalEpoch,t.firstNormalSlot)}async getLeaderSchedule(){let e=I(await this._rpcRequest(`getLeaderSchedule`,[]),Xi);if(`error`in e)throw new $(e.error,`failed to get leader schedule`);return e.result}async getMinimumBalanceForRentExemption(e,t){let n=this._buildArgs([e],t),r=I(await this._rpcRequest(`getMinimumBalanceForRentExemption`,n),Oa);return`error`in r?0:r.result}async getRecentBlockhashAndContext(e){let{context:t,value:{blockhash:n}}=await this.getLatestBlockhashAndContext(e);return{context:t,value:{blockhash:n,feeCalculator:{get lamportsPerSignature(){throw Error("The capability to fetch `lamportsPerSignature` using the `getRecentBlockhash` API is no longer offered by the network. Use the `getFeeForMessage` API to obtain the fee for a given message.")},toJSON(){return{}}}}}}async getRecentPerformanceSamples(e){let t=I(await this._rpcRequest(`getRecentPerformanceSamples`,e?[e]:[]),ao);if(`error`in t)throw new $(t.error,`failed to get recent performance samples`);return t.result}async getFeeCalculatorForBlockhash(e,t){let n=this._buildArgs([e],t),r=I(await this._rpcRequest(`getFeeCalculatorForBlockhash`,n),oo);if(`error`in r)throw new $(r.error,`failed to get fee calculator`);let{context:i,value:a}=r.result;return{context:i,value:a===null?null:a.feeCalculator}}async getFeeForMessage(e,t){let n=J(e.serialize()).toString(`base64`),r=this._buildArgs([n],t),i=I(await this._rpcRequest(`getFeeForMessage`,r),ur(R(z())));if(`error`in i)throw new $(i.error,`failed to get fee for message`);if(i.result===null)throw Error(`invalid blockhash`);return i.result}async getRecentPrioritizationFees(e){let t=e?.lockedWritableAccounts?.map(e=>e.toBase58()),n=t?.length?[t]:[],r=I(await this._rpcRequest(`getRecentPrioritizationFees`,n),qi);if(`error`in r)throw new $(r.error,`failed to get recent prioritization fees`);return r.result}async getRecentBlockhash(e){try{return(await this.getRecentBlockhashAndContext(e)).value}catch(e){throw Error(`failed to get recent blockhash: `+e)}}async getLatestBlockhash(e){try{return(await this.getLatestBlockhashAndContext(e)).value}catch(e){throw Error(`failed to get recent blockhash: `+e)}}async getLatestBlockhashAndContext(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getLatestBlockhash`,r),no);if(`error`in i)throw new $(i.error,`failed to get latest blockhash`);return i.result}async isBlockhashValid(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e],n,void 0,r),a=I(await this._rpcRequest(`isBlockhashValid`,i),ro);if(`error`in a)throw new $(a.error,"failed to determine if the blockhash `"+e+"`is valid");return a.result}async getVersion(){let e=I(await this._rpcRequest(`getVersion`,[]),K(Bi));if(`error`in e)throw new $(e.error,`failed to get version`);return e.result}async getGenesisHash(){let e=I(await this._rpcRequest(`getGenesisHash`,[]),K(V()));if(`error`in e)throw new $(e.error,`failed to get genesis hash`);return e.result}async getBlock(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,void 0,r),a=await this._rpcRequest(`getBlock`,i);try{switch(r?.transactionDetails){case`accounts`:{let e=I(a,Ja);if(`error`in e)throw e.error;return e.result}case`none`:{let e=I(a,qa);if(`error`in e)throw e.error;return e.result}default:{let e=I(a,Ka);if(`error`in e)throw e.error;let{result:t}=e;return t?{...t,transactions:t.transactions.map(({transaction:e,meta:t,version:n})=>({meta:t,transaction:{...e,message:fr(n,e.message)},version:n}))}:null}}}catch(e){throw new $(e,`failed to get confirmed block`)}}async getParsedBlock(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r),a=await this._rpcRequest(`getBlock`,i);try{switch(r?.transactionDetails){case`accounts`:{let e=I(a,Xa);if(`error`in e)throw e.error;return e.result}case`none`:{let e=I(a,Za);if(`error`in e)throw e.error;return e.result}default:{let e=I(a,Ya);if(`error`in e)throw e.error;return e.result}}}catch(e){throw new $(e,`failed to get block`)}}async getBlockProduction(e){let t,n;if(typeof e==`string`)n=e;else if(e){let{commitment:r,...i}=e;n=r,t=i}let r=this._buildArgs([],n,`base64`,t),i=I(await this._rpcRequest(`getBlockProduction`,r),Wi);if(`error`in i)throw new $(i.error,`failed to get block production information`);return i.result}async getTransaction(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,void 0,r),a=I(await this._rpcRequest(`getTransaction`,i),eo);if(`error`in a)throw new $(a.error,`failed to get transaction`);let o=a.result;return o&&{...o,transaction:{...o.transaction,message:fr(o.version,o.transaction.message)}}}async getParsedTransaction(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getTransaction`,i),to);if(`error`in a)throw new $(a.error,`failed to get transaction`);return a.result}async getParsedTransactions(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r)}));return(await this._rpcBatchRequest(i)).map(e=>{let t=I(e,to);if(`error`in t)throw new $(t.error,`failed to get transactions`);return t.result})}async getTransactions(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],n,void 0,r)}));return(await this._rpcBatchRequest(i)).map(e=>{let t=I(e,eo);if(`error`in t)throw new $(t.error,`failed to get transactions`);let n=t.result;return n&&{...n,transaction:{...n.transaction,message:fr(n.version,n.transaction.message)}}})}async getConfirmedBlock(e,t){let n=this._buildArgsAtLeastConfirmed([e],t),r=I(await this._rpcRequest(`getBlock`,n),Qa);if(`error`in r)throw new $(r.error,`failed to get confirmed block`);let i=r.result;if(!i)throw Error(`Confirmed block `+e+` not found`);let a={...i,transactions:i.transactions.map(({transaction:e,meta:t})=>{let n=new Ur(e.message);return{meta:t,transaction:{...e,message:n}}})};return{...a,transactions:a.transactions.map(({transaction:e,meta:t})=>({meta:t,transaction:Q.populate(e.message,e.signatures)}))}}async getBlocks(e,t,n){let r=this._buildArgsAtLeastConfirmed(t===void 0?[e]:[e,t],n),i=I(await this._rpcRequest(`getBlocks`,r),K(L(z())));if(`error`in i)throw new $(i.error,`failed to get blocks`);return i.result}async getBlockSignatures(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:`signatures`,rewards:!1}),r=I(await this._rpcRequest(`getBlock`,n),$a);if(`error`in r)throw new $(r.error,`failed to get block`);let i=r.result;if(!i)throw Error(`Block `+e+` not found`);return i}async getConfirmedBlockSignatures(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:`signatures`,rewards:!1}),r=I(await this._rpcRequest(`getBlock`,n),$a);if(`error`in r)throw new $(r.error,`failed to get confirmed block`);let i=r.result;if(!i)throw Error(`Confirmed block `+e+` not found`);return i}async getConfirmedTransaction(e,t){let n=this._buildArgsAtLeastConfirmed([e],t),r=I(await this._rpcRequest(`getTransaction`,n),eo);if(`error`in r)throw new $(r.error,`failed to get transaction`);let i=r.result;if(!i)return i;let a=new Ur(i.transaction.message),o=i.transaction.signatures;return{...i,transaction:Q.populate(a,o)}}async getParsedConfirmedTransaction(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,`jsonParsed`),r=I(await this._rpcRequest(`getTransaction`,n),to);if(`error`in r)throw new $(r.error,`failed to get confirmed transaction`);return r.result}async getParsedConfirmedTransactions(e,t){let n=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],t,`jsonParsed`)}));return(await this._rpcBatchRequest(n)).map(e=>{let t=I(e,to);if(`error`in t)throw new $(t.error,`failed to get confirmed transactions`);return t.result})}async getConfirmedSignaturesForAddress(e,t,n){let r={},i=await this.getFirstAvailableBlock();for(;!(`until`in r)&&(t--,!(t<=0||t<i));)try{let e=await this.getConfirmedBlockSignatures(t,`finalized`);e.signatures.length>0&&(r.until=e.signatures[e.signatures.length-1].toString())}catch(e){if(e instanceof Error&&e.message.includes(`skipped`))continue;throw e}let a=await this.getSlot(`finalized`);for(;!(`before`in r)&&(n++,!(n>a));)try{let e=await this.getConfirmedBlockSignatures(n);e.signatures.length>0&&(r.before=e.signatures[e.signatures.length-1].toString())}catch(e){if(e instanceof Error&&e.message.includes(`skipped`))continue;throw e}return(await this.getConfirmedSignaturesForAddress2(e,r)).map(e=>e.signature)}async getConfirmedSignaturesForAddress2(e,t,n){let r=this._buildArgsAtLeastConfirmed([e.toBase58()],n,void 0,t),i=I(await this._rpcRequest(`getConfirmedSignaturesForAddress2`,r),da);if(`error`in i)throw new $(i.error,`failed to get confirmed signatures for address`);return i.result}async getSignaturesForAddress(e,t,n){let r=this._buildArgsAtLeastConfirmed([e.toBase58()],n,void 0,t),i=I(await this._rpcRequest(`getSignaturesForAddress`,r),fa);if(`error`in i)throw new $(i.error,`failed to get signatures for address`);return i.result}async getAddressLookupTable(e,t){let{context:n,value:r}=await this.getAccountInfoAndContext(e,t),i=null;return r!==null&&(i=new Si({key:e,state:Si.deserialize(r.data)})),{context:n,value:i}}async getNonceAndContext(e,t){let{context:n,value:r}=await this.getAccountInfoAndContext(e,t),i=null;return r!==null&&(i=li.fromAccountData(r.data)),{context:n,value:i}}async getNonce(e,t){return await this.getNonceAndContext(e,t).then(e=>e.value).catch(t=>{throw Error(`failed to get nonce for account `+e.toBase58()+`: `+t)})}async requestAirdrop(e,t){let n=I(await this._rpcRequest(`requestAirdrop`,[e.toBase58(),t]),so);if(`error`in n)throw new $(n.error,`airdrop to ${e.toBase58()} failed`);return n.result}async _blockhashWithExpiryBlockHeight(e){if(!e){for(;this._pollingBlockhash;)await $n(100);let e=Date.now()-this._blockhashInfo.lastFetch>=Oi;if(this._blockhashInfo.latestBlockhash!==null&&!e)return this._blockhashInfo.latestBlockhash}return await this._pollNewBlockhash()}async _pollNewBlockhash(){this._pollingBlockhash=!0;try{let e=Date.now(),t=this._blockhashInfo.latestBlockhash,n=t?t.blockhash:null;for(let e=0;e<50;e++){let e=await this.getLatestBlockhash(`finalized`);if(n!==e.blockhash)return this._blockhashInfo={latestBlockhash:e,lastFetch:Date.now(),transactionSignatures:[],simulatedSignatures:[]},e;await $n(ei/2)}throw Error(`Unable to obtain a new blockhash after ${Date.now()-e}ms`)}finally{this._pollingBlockhash=!1}}async getStakeMinimumDelegation(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,`base64`,n),i=I(await this._rpcRequest(`getStakeMinimumDelegation`,r),ur(z()));if(`error`in i)throw new $(i.error,`failed to get stake minimum delegation`);return i.result}async simulateTransaction(e,t,n){if(`message`in e){let r=e.serialize(),i=g.from(r).toString(`base64`);if(Array.isArray(t)||n!==void 0)throw Error(`Invalid arguments`);let a=t||{};a.encoding=`base64`,`commitment`in a||(a.commitment=this.commitment),t&&typeof t==`object`&&`innerInstructions`in t&&(a.innerInstructions=t.innerInstructions);let o=[i,a],s=I(await this._rpcRequest(`simulateTransaction`,o),Ui);if(`error`in s)throw Error(`failed to simulate transaction: `+s.error.message);return s.result}let r;if(e instanceof Q){let t=e;r=new Q,r.feePayer=t.feePayer,r.instructions=e.instructions,r.nonceInfo=t.nonceInfo,r.signatures=t.signatures}else r=Q.populate(e),r._message=r._json=void 0;if(t!==void 0&&!Array.isArray(t))throw Error(`Invalid arguments`);let i=t;if(r.nonceInfo&&i)r.sign(...i);else{let e=this._disableBlockhashCaching;for(;;){let t=await this._blockhashWithExpiryBlockHeight(e);if(r.lastValidBlockHeight=t.lastValidBlockHeight,r.recentBlockhash=t.blockhash,!i)break;if(r.sign(...i),!r.signature)throw Error(`!signature`);let n=r.signature.toString(`base64`);if(!this._blockhashInfo.simulatedSignatures.includes(n)&&!this._blockhashInfo.transactionSignatures.includes(n)){this._blockhashInfo.simulatedSignatures.push(n);break}e=!0}}let a=r._compile(),o=a.serialize(),s=r._serialize(o).toString(`base64`),c={encoding:`base64`,commitment:this.commitment};n&&(c.accounts={encoding:`base64`,addresses:(Array.isArray(n)?n:a.nonProgramIds()).map(e=>e.toBase58())}),i&&(c.sigVerify=!0),t&&typeof t==`object`&&`innerInstructions`in t&&(c.innerInstructions=t.innerInstructions);let l=[s,c],u=I(await this._rpcRequest(`simulateTransaction`,l),Ui);if(`error`in u){let e;throw`data`in u.error&&(e=u.error.data.logs,e&&Array.isArray(e))&&``+e.join(`
|
|
2
|
-
`),new ai({action:`simulate`,signature:``,transactionMessage:u.error.message,logs:e})}return u.result}async sendTransaction(e,t,n){if(`version`in e){if(t&&Array.isArray(t))throw Error(`Invalid arguments`);let n=e.serialize();return await this.sendRawTransaction(n,t)}if(t===void 0||!Array.isArray(t))throw Error(`Invalid arguments`);let r=t;if(e.nonceInfo)e.sign(...r);else{let t=this._disableBlockhashCaching;for(;;){let n=await this._blockhashWithExpiryBlockHeight(t);if(e.lastValidBlockHeight=n.lastValidBlockHeight,e.recentBlockhash=n.blockhash,e.sign(...r),!e.signature)throw Error(`!signature`);let i=e.signature.toString(`base64`);if(this._blockhashInfo.transactionSignatures.includes(i))t=!0;else{this._blockhashInfo.transactionSignatures.push(i);break}}}let i=e.serialize();return await this.sendRawTransaction(i,n)}async sendRawTransaction(e,t){let n=J(e).toString(`base64`);return await this.sendEncodedTransaction(n,t)}async sendEncodedTransaction(e,t){let n={encoding:`base64`},r=t&&t.skipPreflight,i=r===!0?`processed`:t&&t.preflightCommitment||this.commitment;t&&t.maxRetries!=null&&(n.maxRetries=t.maxRetries),t&&t.minContextSlot!=null&&(n.minContextSlot=t.minContextSlot),r&&(n.skipPreflight=r),i&&(n.preflightCommitment=i);let a=[e,n],o=I(await this._rpcRequest(`sendTransaction`,a),co);if(`error`in o){let e;throw`data`in o.error&&(e=o.error.data.logs),new ai({action:r?`send`:`simulate`,signature:``,transactionMessage:o.error.message,logs:e})}return o.result}_wsOnOpen(){this._rpcWebSocketConnected=!0,this._rpcWebSocketHeartbeat=setInterval(()=>{(async()=>{try{await this._rpcWebSocket.notify(`ping`)}catch{}})()},5e3),this._updateSubscriptions()}_wsOnError(e){this._rpcWebSocketConnected=!1}_wsOnClose(e){if(this._rpcWebSocketConnected=!1,this._rpcWebSocketGeneration=(this._rpcWebSocketGeneration+1)%(2**53-1),this._rpcWebSocketIdleTimeout&&=(clearTimeout(this._rpcWebSocketIdleTimeout),null),this._rpcWebSocketHeartbeat&&=(clearInterval(this._rpcWebSocketHeartbeat),null),e===1e3){this._updateSubscriptions();return}this._subscriptionCallbacksByServerSubscriptionId={},Object.entries(this._subscriptionsByHash).forEach(([e,t])=>{this._setSubscription(e,{...t,state:`pending`})})}_setSubscription(e,t){let n=this._subscriptionsByHash[e]?.state;if(this._subscriptionsByHash[e]=t,n!==t.state){let n=this._subscriptionStateChangeCallbacksByHash[e];n&&n.forEach(e=>{try{e(t.state)}catch{}})}}_onSubscriptionStateChange(e,t){let n=this._subscriptionHashByClientSubscriptionId[e];if(n==null)return()=>{};let r=this._subscriptionStateChangeCallbacksByHash[n]||=new Set;return r.add(t),()=>{r.delete(t),r.size===0&&delete this._subscriptionStateChangeCallbacksByHash[n]}}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(e){e instanceof Error}},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 e=>{let n=this._subscriptionsByHash[e];if(n!==void 0)switch(n.state){case`pending`:case`unsubscribed`:if(n.callbacks.size===0){delete this._subscriptionsByHash[e],n.state===`unsubscribed`&&delete this._subscriptionCallbacksByServerSubscriptionId[n.serverSubscriptionId],await this._updateSubscriptions();return}await(async()=>{let{args:r,method:i}=n;try{this._setSubscription(e,{...n,state:`subscribing`});let t=await this._rpcWebSocket.call(i,r);this._setSubscription(e,{...n,serverSubscriptionId:t,state:`subscribed`}),this._subscriptionCallbacksByServerSubscriptionId[t]=n.callbacks,await this._updateSubscriptions()}catch{if(!t())return;this._setSubscription(e,{...n,state:`pending`}),await this._updateSubscriptions()}})();break;case`subscribed`:n.callbacks.size===0&&await(async()=>{let{serverSubscriptionId:r,unsubscribeMethod:i}=n;if(this._subscriptionsAutoDisposedByRpc.has(r))this._subscriptionsAutoDisposedByRpc.delete(r);else{this._setSubscription(e,{...n,state:`unsubscribing`}),this._setSubscription(e,{...n,state:`unsubscribing`});try{await this._rpcWebSocket.call(i,[r])}catch(r){if(r instanceof Error,!t())return;this._setSubscription(e,{...n,state:`subscribed`}),await this._updateSubscriptions();return}}this._setSubscription(e,{...n,state:`unsubscribed`}),await this._updateSubscriptions()})()}}))}_handleServerNotification(e,t){let n=this._subscriptionCallbacksByServerSubscriptionId[e];n!==void 0&&n.forEach(e=>{try{e(...t)}catch{}})}_wsOnAccountNotification(e){let{result:t,subscription:n}=I(e,pa);this._handleServerNotification(n,[t.value,t.context])}_makeSubscription(e,t){let n=this._nextClientSubscriptionId++,r=gi([e.method,t]),i=this._subscriptionsByHash[r];return i===void 0?this._subscriptionsByHash[r]={...e,args:t,callbacks:new Set([e.callback]),state:`pending`}:i.callbacks.add(e.callback),this._subscriptionHashByClientSubscriptionId[n]=r,this._subscriptionDisposeFunctionsByClientSubscriptionId[n]=async()=>{delete this._subscriptionDisposeFunctionsByClientSubscriptionId[n],delete this._subscriptionHashByClientSubscriptionId[n];let t=this._subscriptionsByHash[r];U(t!==void 0,`Could not find a \`Subscription\` when tearing down client subscription #${n}`),t.callbacks.delete(e.callback),await this._updateSubscriptions()},this._updateSubscriptions(),n}onAccountChange(e,t,n){let{commitment:r,config:i}=G(n),a=this._buildArgs([e.toBase58()],r||this._commitment||`finalized`,`base64`,i);return this._makeSubscription({callback:t,method:`accountSubscribe`,unsubscribeMethod:`accountUnsubscribe`},a)}async removeAccountChangeListener(e){await this._unsubscribeClientSubscription(e,`account change`)}_wsOnProgramAccountNotification(e){let{result:t,subscription:n}=I(e,ha);this._handleServerNotification(n,[{accountId:t.value.pubkey,accountInfo:t.value.account},t.context])}onProgramAccountChange(e,t,n,r){let{commitment:i,config:a}=G(n),o=this._buildArgs([e.toBase58()],i||this._commitment||`finalized`,`base64`,a||(r?{filters:cr(r)}:void 0));return this._makeSubscription({callback:t,method:`programSubscribe`,unsubscribeMethod:`programUnsubscribe`},o)}async removeProgramAccountChangeListener(e){await this._unsubscribeClientSubscription(e,`program account change`)}onLogs(e,t,n){let r=this._buildArgs([typeof e==`object`?{mentions:[e.toString()]}:e],n||this._commitment||`finalized`);return this._makeSubscription({callback:t,method:`logsSubscribe`,unsubscribeMethod:`logsUnsubscribe`},r)}async removeOnLogsListener(e){await this._unsubscribeClientSubscription(e,`logs`)}_wsOnLogsNotification(e){let{result:t,subscription:n}=I(e,uo);this._handleServerNotification(n,[t.value,t.context])}_wsOnSlotNotification(e){let{result:t,subscription:n}=I(e,_a);this._handleServerNotification(n,[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:n}=I(e,ya);this._handleServerNotification(n,[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 n=this._subscriptionDisposeFunctionsByClientSubscriptionId[e];n&&await n()}_buildArgs(e,t,n,r){let i=t||this._commitment;if(i||n||r){let t={};n&&(t.encoding=n),i&&(t.commitment=i),r&&(t=Object.assign(t,r)),e.push(t)}return e}_buildArgsAtLeastConfirmed(e,t,n,r){let i=t||this._commitment;if(i&&![`confirmed`,`finalized`].includes(i))throw Error("Using Connection with default commitment: `"+this._commitment+"`, but method requires at least `confirmed`");return this._buildArgs(e,t,n,r)}_wsOnSignatureNotification(e){let{result:t,subscription:n}=I(e,ba);t.value!==`receivedSignature`&&this._subscriptionsAutoDisposedByRpc.add(n),this._handleServerNotification(n,t.value===`receivedSignature`?[{type:`received`},t.context]:[{type:`status`,result:t.value},t.context])}onSignature(e,t,n){let r=this._buildArgs([e],n||this._commitment||`finalized`),i=this._makeSubscription({callback:(e,n)=>{if(e.type===`status`){t(e.result,n);try{this.removeSignatureListener(i)}catch{}}},method:`signatureSubscribe`,unsubscribeMethod:`signatureUnsubscribe`},r);return i}onSignatureWithOptions(e,t,n){let{commitment:r,...i}={...n,commitment:n&&n.commitment||this._commitment||`finalized`},a=this._buildArgs([e],r,void 0,i),o=this._makeSubscription({callback:(e,n)=>{t(e,n);try{this.removeSignatureListener(o)}catch{}},method:`signatureSubscribe`,unsubscribeMethod:`signatureUnsubscribe`},a);return o}async removeSignatureListener(e){await this._unsubscribeClientSubscription(e,`signature result`)}_wsOnRootNotification(e){let{result:t,subscription:n}=I(e,xa);this._handleServerNotification(n,[t])}onRootChange(e){return this._makeSubscription({callback:e,method:`rootSubscribe`,unsubscribeMethod:`rootUnsubscribe`},[])}async removeRootChangeListener(e){await this._unsubscribeClientSubscription(e,`root change`)}},mo=class e{constructor(e){this._keypair=void 0,this._keypair=e??Sr()}static generate(){return new e(Sr())}static fromSecretKey(t,n){if(t.byteLength!==64)throw Error(`bad secret key size`);let r=t.slice(32,64);if(!n||!n.skipValidation){let e=t.slice(0,32),n=Cr(e);for(let e=0;e<32;e++)if(r[e]!==n[e])throw Error(`provided secretKey is invalid`)}return new e({publicKey:r,secretKey:t})}static fromSeed(t){let n=Cr(t),r=new Uint8Array(64);return r.set(t),r.set(n,32),new e({publicKey:n,secretKey:r})}get publicKey(){return new Y(this._keypair.publicKey)}get secretKey(){return new Uint8Array(this._keypair.secretKey)}},ho=Object.freeze({CreateLookupTable:{index:0,layout:q.struct([q.u32(`instruction`),er(`recentSlot`),q.u8(`bumpSeed`)])},FreezeLookupTable:{index:1,layout:q.struct([q.u32(`instruction`)])},ExtendLookupTable:{index:2,layout:q.struct([q.u32(`instruction`),er(),q.seq(X(),q.offset(q.u32(),-8),`addresses`)])},DeactivateLookupTable:{index:3,layout:q.struct([q.u32(`instruction`)])},CloseLookupTable:{index:4,layout:q.struct([q.u32(`instruction`)])}}),go=class{constructor(){}static createLookupTable(e){let[t,n]=Y.findProgramAddressSync([e.authority.toBuffer(),at().encode(e.recentSlot)],this.programId),r=ho.CreateLookupTable,i=W(r,{recentSlot:BigInt(e.recentSlot),bumpSeed:n}),a=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:di.programId,isSigner:!1,isWritable:!1}];return[new Z({programId:this.programId,keys:a,data:i}),t]}static freezeLookupTable(e){let t=ho.FreezeLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new Z({programId:this.programId,keys:r,data:n})}static extendLookupTable(e){let t=ho.ExtendLookupTable,n=W(t,{addresses:e.addresses.map(e=>e.toBytes())}),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return e.payer&&r.push({pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:di.programId,isSigner:!1,isWritable:!1}),new Z({programId:this.programId,keys:r,data:n})}static deactivateLookupTable(e){let t=ho.DeactivateLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new Z({programId:this.programId,keys:r,data:n})}static closeLookupTable(e){let t=ho.CloseLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.recipient,isSigner:!1,isWritable:!0}];return new Z({programId:this.programId,keys:r,data:n})}},go.programId=new Y(`AddressLookupTab1e1111111111111111111111111`),_o=Object.freeze({RequestUnits:{index:0,layout:q.struct([q.u8(`instruction`),q.u32(`units`),q.u32(`additionalFee`)])},RequestHeapFrame:{index:1,layout:q.struct([q.u8(`instruction`),q.u32(`bytes`)])},SetComputeUnitLimit:{index:2,layout:q.struct([q.u8(`instruction`),q.u32(`units`)])},SetComputeUnitPrice:{index:3,layout:q.struct([q.u8(`instruction`),er(`microLamports`)])}}),vo=class{constructor(){}static requestUnits(e){let t=_o.RequestUnits,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static requestHeapFrame(e){let t=_o.RequestHeapFrame,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static setComputeUnitLimit(e){let t=_o.SetComputeUnitLimit,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static setComputeUnitPrice(e){let t=_o.SetComputeUnitPrice,n=W(t,{microLamports:BigInt(e.microLamports)});return new Z({keys:[],programId:this.programId,data:n})}},vo.programId=new Y(`ComputeBudget111111111111111111111111111111`),yo=64,bo=32,xo=64,So=q.struct([q.u8(`numSignatures`),q.u8(`padding`),q.u16(`signatureOffset`),q.u16(`signatureInstructionIndex`),q.u16(`publicKeyOffset`),q.u16(`publicKeyInstructionIndex`),q.u16(`messageDataOffset`),q.u16(`messageDataSize`),q.u16(`messageInstructionIndex`)]),Co=class e{constructor(){}static createInstructionWithPublicKey(t){let{publicKey:n,message:r,signature:i,instructionIndex:a}=t;U(n.length===bo,`Public Key must be ${bo} bytes but received ${n.length} bytes`),U(i.length===xo,`Signature must be ${xo} bytes but received ${i.length} bytes`);let o=So.span,s=o+n.length,c=s+i.length,l=g.alloc(c+r.length),u=a??65535;return So.encode({numSignatures:1,padding:0,signatureOffset:s,signatureInstructionIndex:u,publicKeyOffset:o,publicKeyInstructionIndex:u,messageDataOffset:c,messageDataSize:r.length,messageInstructionIndex:u},l),l.fill(n,o),l.fill(i,s),l.fill(r,c),new Z({keys:[],programId:e.programId,data:l})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:n,instructionIndex:r}=e;U(t.length===yo,`Private key must be ${yo} bytes but received ${t.length} bytes`);try{let e=mo.fromSecretKey(t),i=e.publicKey.toBytes(),a=wr(n,e.secretKey);return this.createInstructionWithPublicKey({publicKey:i,message:n,signature:a,instructionIndex:r})}catch(e){throw Error(`Error creating instruction; ${e}`)}}},Co.programId=new Y(`Ed25519SigVerify111111111111111111111111111`),wo=(e,t)=>{let n=w.sign(e,t);return[n.toCompactRawBytes(),n.recovery]},w.utils.isValidPrivateKey,To=w.getPublicKey,Eo=32,Do=20,Oo=64,ko=q.struct([q.u8(`numSignatures`),q.u16(`signatureOffset`),q.u8(`signatureInstructionIndex`),q.u16(`ethAddressOffset`),q.u8(`ethAddressInstructionIndex`),q.u16(`messageDataOffset`),q.u16(`messageDataSize`),q.u8(`messageInstructionIndex`),q.blob(20,`ethAddress`),q.blob(64,`signature`),q.u8(`recoveryId`)]),Ao=class e{constructor(){}static publicKeyToEthAddress(e){U(e.length===Oo,`Public key must be ${Oo} bytes but received ${e.length} bytes`);try{return g.from(m(J(e))).slice(-20)}catch(e){throw Error(`Error constructing Ethereum address: ${e}`)}}static createInstructionWithPublicKey(t){let{publicKey:n,message:r,signature:i,recoveryId:a,instructionIndex:o}=t;return e.createInstructionWithEthAddress({ethAddress:e.publicKeyToEthAddress(n),message:r,signature:i,recoveryId:a,instructionIndex:o})}static createInstructionWithEthAddress(t){let{ethAddress:n,message:r,signature:i,recoveryId:a,instructionIndex:o=0}=t,s;s=typeof n==`string`?n.startsWith(`0x`)?g.from(n.substr(2),`hex`):g.from(n,`hex`):n,U(s.length===Do,`Address must be ${Do} bytes but received ${s.length} bytes`);let c=12+s.length,l=c+i.length+1,u=g.alloc(ko.span+r.length);return ko.encode({numSignatures:1,signatureOffset:c,signatureInstructionIndex:o,ethAddressOffset:12,ethAddressInstructionIndex:o,messageDataOffset:l,messageDataSize:r.length,messageInstructionIndex:o,signature:J(i),ethAddress:J(s),recoveryId:a},u),u.fill(J(r),ko.span),new Z({keys:[],programId:e.programId,data:u})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:n,instructionIndex:r}=e;U(t.length===Eo,`Private key must be ${Eo} bytes but received ${t.length} bytes`);try{let e=J(t),i=To(e,!1).slice(1),a=g.from(m(J(n))),[o,s]=wo(a,e);return this.createInstructionWithPublicKey({publicKey:i,message:n,signature:o,recoveryId:s,instructionIndex:r})}catch(e){throw Error(`Error creating instruction; ${e}`)}}},Ao.programId=new Y(`KeccakSecp256k11111111111111111111111111111`),Mo=new Y(`StakeConfig11111111111111111111111111111111`),No=class{constructor(e,t,n){this.unixTimestamp=void 0,this.epoch=void 0,this.custodian=void 0,this.unixTimestamp=e,this.epoch=t,this.custodian=n}},jo=No,No.default=new jo(0,0,Y.default),Po=Object.freeze({Initialize:{index:0,layout:q.struct([q.u32(`instruction`),Lr(),Rr()])},Authorize:{index:1,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`stakeAuthorizationType`)])},Delegate:{index:2,layout:q.struct([q.u32(`instruction`)])},Split:{index:3,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},Withdraw:{index:4,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},Deactivate:{index:5,layout:q.struct([q.u32(`instruction`)])},Merge:{index:7,layout:q.struct([q.u32(`instruction`)])},AuthorizeWithSeed:{index:8,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`stakeAuthorizationType`),Ir(`authoritySeed`),X(`authorityOwner`)])}}),Object.freeze({Staker:{index:0},Withdrawer:{index:1}}),Fo=class{constructor(){}static initialize(e){let{stakePubkey:t,authorized:n,lockup:r}=e,i=r||No.default,a=Po.Initialize,o=W(a,{authorized:{staker:J(n.staker.toBuffer()),withdrawer:J(n.withdrawer.toBuffer())},lockup:{unixTimestamp:i.unixTimestamp,epoch:i.epoch,custodian:J(i.custodian.toBuffer())}}),s={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:this.programId,data:o};return new Z(s)}static createAccountWithSeed(e){let t=new Q;t.add(di.createAccountWithSeed({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,basePubkey:e.basePubkey,seed:e.seed,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:n,authorized:r,lockup:i}=e;return t.add(this.initialize({stakePubkey:n,authorized:r,lockup:i}))}static createAccount(e){let t=new Q;t.add(di.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:n,authorized:r,lockup:i}=e;return t.add(this.initialize({stakePubkey:n,authorized:r,lockup:i}))}static delegate(e){let{stakePubkey:t,authorizedPubkey:n,votePubkey:r}=e,i=Po.Delegate,a=W(i);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:Mo,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:a})}static authorize(e){let{stakePubkey:t,authorizedPubkey:n,newAuthorizedPubkey:r,stakeAuthorizationType:i,custodianPubkey:a}=e,o=Po.Authorize,s=W(o,{newAuthorized:J(r.toBuffer()),stakeAuthorizationType:i.index}),c=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return a&&c.push({pubkey:a,isSigner:!0,isWritable:!1}),new Q().add({keys:c,programId:this.programId,data:s})}static authorizeWithSeed(e){let{stakePubkey:t,authorityBase:n,authoritySeed:r,authorityOwner:i,newAuthorizedPubkey:a,stakeAuthorizationType:o,custodianPubkey:s}=e,c=Po.AuthorizeWithSeed,l=W(c,{newAuthorized:J(a.toBuffer()),stakeAuthorizationType:o.index,authoritySeed:r,authorityOwner:J(i.toBuffer())}),u=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1}];return s&&u.push({pubkey:s,isSigner:!0,isWritable:!1}),new Q().add({keys:u,programId:this.programId,data:l})}static splitInstruction(e){let{stakePubkey:t,authorizedPubkey:n,splitStakePubkey:r,lamports:i}=e,a=Po.Split,o=W(a,{lamports:i});return new Z({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:o})}static split(e,t){let n=new Q;return n.add(di.createAccount({fromPubkey:e.authorizedPubkey,newAccountPubkey:e.splitStakePubkey,lamports:t,space:this.space,programId:this.programId})),n.add(this.splitInstruction(e))}static splitWithSeed(e,t){let{stakePubkey:n,authorizedPubkey:r,splitStakePubkey:i,basePubkey:a,seed:o,lamports:s}=e,c=new Q;return c.add(di.allocate({accountPubkey:i,basePubkey:a,seed:o,space:this.space,programId:this.programId})),t&&t>0&&c.add(di.transfer({fromPubkey:e.authorizedPubkey,toPubkey:i,lamports:t})),c.add(this.splitInstruction({stakePubkey:n,authorizedPubkey:r,splitStakePubkey:i,lamports:s}))}static merge(e){let{stakePubkey:t,sourceStakePubKey:n,authorizedPubkey:r}=e,i=Po.Merge,a=W(i);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:a})}static withdraw(e){let{stakePubkey:t,authorizedPubkey:n,toPubkey:r,lamports:i,custodianPubkey:a}=e,o=Po.Withdraw,s=W(o,{lamports:i}),c=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return a&&c.push({pubkey:a,isSigner:!0,isWritable:!1}),new Q().add({keys:c,programId:this.programId,data:s})}static deactivate(e){let{stakePubkey:t,authorizedPubkey:n}=e,r=Po.Deactivate,i=W(r);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:i})}},Fo.programId=new Y(`Stake11111111111111111111111111111111111111`),Fo.space=200,Io=Object.freeze({InitializeAccount:{index:0,layout:q.struct([q.u32(`instruction`),zr()])},Authorize:{index:1,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`voteAuthorizationType`)])},Withdraw:{index:3,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},UpdateValidatorIdentity:{index:4,layout:q.struct([q.u32(`instruction`)])},AuthorizeWithSeed:{index:10,layout:q.struct([q.u32(`instruction`),Br()])}}),Object.freeze({Voter:{index:0},Withdrawer:{index:1}}),Lo=class e{constructor(){}static initializeAccount(e){let{votePubkey:t,nodePubkey:n,voteInit:r}=e,i=Io.InitializeAccount,a=W(i,{voteInit:{nodePubkey:J(r.nodePubkey.toBuffer()),authorizedVoter:J(r.authorizedVoter.toBuffer()),authorizedWithdrawer:J(r.authorizedWithdrawer.toBuffer()),commission:r.commission}}),o={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:a};return new Z(o)}static createAccount(e){let t=new Q;return t.add(di.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:n,newAuthorizedPubkey:r,voteAuthorizationType:i}=e,a=Io.Authorize,o=W(a,{newAuthorized:J(r.toBuffer()),voteAuthorizationType:i.index}),s=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:s,programId:this.programId,data:o})}static authorizeWithSeed(e){let{currentAuthorityDerivedKeyBasePubkey:t,currentAuthorityDerivedKeyOwnerPubkey:n,currentAuthorityDerivedKeySeed:r,newAuthorizedPubkey:i,voteAuthorizationType:a,votePubkey:o}=e,s=Io.AuthorizeWithSeed,c=W(s,{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:J(n.toBuffer()),currentAuthorityDerivedKeySeed:r,newAuthorized:J(i.toBuffer()),voteAuthorizationType:a.index}}),l=[{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:t,isSigner:!0,isWritable:!1}];return new Q().add({keys:l,programId:this.programId,data:c})}static withdraw(e){let{votePubkey:t,authorizedWithdrawerPubkey:n,lamports:r,toPubkey:i}=e,a=Io.Withdraw,o=W(a,{lamports:r}),s=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:s,programId:this.programId,data:o})}static safeWithdraw(t,n,r){if(t.lamports>n-r)throw Error(`Withdraw will leave vote account with insufficient funds.`);return e.withdraw(t)}static updateValidatorIdentity(e){let{votePubkey:t,authorizedWithdrawerPubkey:n,nodePubkey:r}=e,i=Io.UpdateValidatorIdentity,a=W(i),o=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:o,programId:this.programId,data:a})}},Lo.programId=new Y(`Vote111111111111111111111111111111111111111`),Lo.space=3762,new Y(`Va1idator1nfo111111111111111111111111111111`),H({name:V(),website:B(V()),details:B(V()),iconUrl:B(V()),keybaseUsername:B(V())}),new Y(`Vote111111111111111111111111111111111111111`),q.struct([X(`nodePubkey`),X(`authorizedWithdrawer`),q.u8(`commission`),q.nu64(),q.seq(q.struct([q.nu64(`slot`),q.u32(`confirmationCount`)]),q.offset(q.u32(),-8),`votes`),q.u8(`rootSlotValid`),q.nu64(`rootSlot`),q.nu64(),q.seq(q.struct([q.nu64(`epoch`),X(`authorizedVoter`)]),q.offset(q.u32(),-8),`authorizedVoters`),q.struct([q.seq(q.struct([X(`authorizedPubkey`),q.nu64(`epochOfLastAuthorizedSwitch`),q.nu64(`targetEpoch`)]),32,`buf`),q.nu64(`idx`),q.u8(`isEmpty`)],`priorVoters`),q.nu64(),q.seq(q.struct([q.nu64(`epoch`),q.nu64(`credits`),q.nu64(`prevCredits`)]),q.offset(q.u32(),-8),`epochCredits`),q.struct([q.nu64(`slot`),q.nu64(`timestamp`)],`lastTimestamp`)]),Ro={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/`}}}));_(),zo();var Bo=s([o({transaction:c}),o({signature:c})]),Vo=o({signature:c}),Ho=o({transactions:l(c)}),Uo=[`solana_signTransaction`,`solana_signMessage`,`solana_signAllTransactions`,`solana_signAndSendTransaction`],Wo=e=>v.from(M(e)?e.serialize():e.serialize({requireAllSignatures:!1,verifySignatures:!1})).toString(`base64`),Go=(e,t)=>{let n=v.from(e,`base64`);return M(t)?$r.deserialize(n):Q.from(n)},Ko=class extends ge{options;name=`WalletConnect`;url=`https://walletconnect.org`;icon=`data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE4NSIgdmlld0JveD0iMCAwIDMwMCAxODUiIHdpZHRoPSIzMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTYxLjQzODU0MjkgMzYuMjU2MjYxMmM0OC45MTEyMjQxLTQ3Ljg4ODE2NjMgMTI4LjIxMTk4NzEtNDcuODg4MTY2MyAxNzcuMTIzMjA5MSAwbDUuODg2NTQ1IDUuNzYzNDE3NGMyLjQ0NTU2MSAyLjM5NDQwODEgMi40NDU1NjEgNi4yNzY1MTEyIDAgOC42NzA5MjA0bC0yMC4xMzY2OTUgMTkuNzE1NTAzYy0xLjIyMjc4MSAxLjE5NzIwNTEtMy4yMDUzIDEuMTk3MjA1MS00LjQyODA4MSAwbC04LjEwMDU4NC03LjkzMTE0NzljLTM0LjEyMTY5Mi0zMy40MDc5ODE3LTg5LjQ0Mzg4Ni0zMy40MDc5ODE3LTEyMy41NjU1Nzg4IDBsLTguNjc1MDU2MiA4LjQ5MzYwNTFjLTEuMjIyNzgxNiAxLjE5NzIwNDEtMy4yMDUzMDEgMS4xOTcyMDQxLTQuNDI4MDgwNiAwbC0yMC4xMzY2OTQ5LTE5LjcxNTUwMzFjLTIuNDQ1NTYxMi0yLjM5NDQwOTItMi40NDU1NjEyLTYuMjc2NTEyMiAwLTguNjcwOTIwNHptMjE4Ljc2Nzc5NjEgNDAuNzczNzQ0OSAxNy45MjE2OTcgMTcuNTQ2ODk3YzIuNDQ1NTQ5IDIuMzk0Mzk2OSAyLjQ0NTU2MyA2LjI3NjQ3NjkuMDAwMDMxIDguNjcwODg5OWwtODAuODEwMTcxIDc5LjEyMTEzNGMtMi40NDU1NDQgMi4zOTQ0MjYtNi40MTA1ODIgMi4zOTQ0NTMtOC44NTYxNi4wMDAwNjItLjAwMDAxLS4wMDAwMS0uMDAwMDIyLS4wMDAwMjItLjAwMDAzMi0uMDAwMDMybC01Ny4zNTQxNDMtNTYuMTU0NTcyYy0uNjExMzktLjU5ODYwMi0xLjYwMjY1LS41OTg2MDItMi4yMTQwNCAwLS4wMDAwMDQuMDAwMDA0LS4wMDAwMDcuMDAwMDA4LS4wMDAwMTEuMDAwMDExbC01Ny4zNTI5MjEyIDU2LjE1NDUzMWMtMi40NDU1MzY4IDIuMzk0NDMyLTYuNDEwNTc1NSAyLjM5NDQ3Mi04Ljg1NjE2MTIuMDAwMDg3LS4wMDAwMTQzLS4wMDAwMTQtLjAwMDAyOTYtLjAwMDAyOC0uMDAwMDQ0OS0uMDAwMDQ0bC04MC44MTI0MTk0My03OS4xMjIxODVjLTIuNDQ1NTYwMjEtMi4zOTQ0MDgtMi40NDU1NjAyMS02LjI3NjUxMTUgMC04LjY3MDkxOTdsMTcuOTIxNzI5NjMtMTcuNTQ2ODY3M2MyLjQ0NTU2MDItMi4zOTQ0MDgyIDYuNDEwNTk4OS0yLjM5NDQwODIgOC44NTYxNjAyIDBsNTcuMzU0OTc3NSA1Ni4xNTUzNTdjLjYxMTM5MDguNTk4NjAyIDEuNjAyNjQ5LjU5ODYwMiAyLjIxNDAzOTggMCAuMDAwMDA5Mi0uMDAwMDA5LjAwMDAxNzQtLjAwMDAxNy4wMDAwMjY1LS4wMDAwMjRsNTcuMzUyMTAzMS01Ni4xNTUzMzNjMi40NDU1MDUtMi4zOTQ0NjMzIDYuNDEwNTQ0LTIuMzk0NTUzMSA4Ljg1NjE2MS0uMDAwMi4wMDAwMzQuMDAwMDMzNi4wMDAwNjguMDAwMDY3My4wMDAxMDEuMDAwMTAxbDU3LjM1NDkwMiA1Ni4xNTU0MzJjLjYxMTM5LjU5ODYwMSAxLjYwMjY1LjU5ODYwMSAyLjIxNDA0IDBsNTcuMzUzOTc1LTU2LjE1NDMyNDljMi40NDU1NjEtMi4zOTQ0MDkyIDYuNDEwNTk5LTIuMzk0NDA5MiA4Ljg1NjE2IDB6IiBmaWxsPSIjM2I5OWZjIi8+PC9zdmc+`;supportedTransactionVersions=new Set([`legacy`,0]);readyState=typeof window>`u`?de.Unsupported:de.Loadable;key=null;session;chainId;connectingPromise;unsubscribeEnded;attempt=0;disposed=!1;endedListeners=new Set;constructor(e){super(),this.options=e}get publicKey(){return this.key}subscribeEnded(e){return this.endedListeners.add(e),()=>{this.endedListeners.delete(e)}}get connecting(){return this.connectingPromise!==void 0}get chains(){return this.options.network===ve.Mainnet?[`solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`,`solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ`]:[`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`,`solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K`]}account(e){for(let t of this.chains)for(let n of e.accounts){if(!n.startsWith(`${t}:`))continue;let e=E.decodeUnsafe(n.slice(t.length+1));if(e?.length===32)return{chainId:t,publicKey:new Y(e)}}}restoredSession(){return this.options.walletConnectProtocol.sessions(`solana`).pipe(d(e=>e.find(e=>this.account(e)!==void 0)))}release(){this.unsubscribeEnded?.(),this.unsubscribeEnded=void 0,this.session=void 0,this.chainId=void 0,this.key=null}connect(){if(this.disposed||this.readyState!==de.Loadable)return Promise.reject(new re);if(this.connected)return Promise.resolve();if(this.connectingPromise)return this.connectingPromise;let e=++this.attempt,t=this.options.walletConnectProtocol;return this.connectingPromise=this.options.runWalletEffect(this.restoredSession().pipe(u(a,()=>t.connect({namespace:`solana`,chains:this.chains,requiredMethods:[],optionalMethods:Uo})))).then(n=>{if(this.disposed||e!==this.attempt)throw new A;let r=this.account(n);if(!r)throw new k(`No Solana account approved`);this.release(),this.session=n,this.chainId=r.chainId,this.key=r.publicKey,this.unsubscribeEnded=t.subscribeEnded(n.topic,()=>{this.release(),this.emit(`disconnect`);for(let e of[...this.endedListeners])e()}),this.emit(`connect`,r.publicKey)}).finally(()=>{e===this.attempt&&(this.connectingPromise=void 0)}),this.connectingPromise}async autoConnect(){if(this.disposed)throw new re;await this.options.runWalletEffect(this.restoredSession())&&await this.connect()}async disconnect(){++this.attempt,this.connectingPromise=void 0;let e=this.session?.topic;this.release();try{e&&await this.options.runWalletEffect(this.options.walletConnectProtocol.disconnect(e))}catch(e){this.emit(`error`,new ae(e instanceof Error?e.message:void 0,e))}finally{this.emit(`disconnect`)}}supports(e){return this.session?.methods.includes(e)??!1}request(e,t,n){if(!this.session||!this.chainId||!this.key)throw new A;if(!this.supports(e))throw Error(`Wallet does not support ${e}`);return this.options.runWalletEffect(this.options.walletConnectProtocol.request({topic:this.session.topic,chainId:this.chainId,method:e,params:t,response:n}))}async signTransaction(e){try{let t=this.key;if(!t)throw new A;let n=await this.request(`solana_signTransaction`,{...M(e)?{}:e,transaction:Wo(e)},Bo);return`transaction`in n?Go(n.transaction,e):(e.addSignature(t,v.from(E.decode(n.signature))),e)}catch(e){return this.signingError(e)}}async signAllTransactions(e){if(!this.key)return this.signingError(new A);if(!this.supports(`solana_signAllTransactions`))return Promise.all(e.map(e=>this.signTransaction(e)));try{let t=await this.request(`solana_signAllTransactions`,{transactions:e.map(Wo)},Ho);if(t.transactions.length!==e.length)throw Error(`Wallet returned a different number of signed transactions`);return e.map((e,n)=>Go(t.transactions[n],e))}catch(e){return this.signingError(e)}}async signMessage(e){try{if(!this.key)throw new A;let t=await this.request(`solana_signMessage`,{pubkey:this.key.toBase58(),message:E.encode(e)},Vo);return E.decode(t.signature)}catch(e){let t=e instanceof A?e:new le(e instanceof Error?e.message:void 0,e);throw this.emit(`error`,t),t}}async signAndSendTransaction(e){try{return(await this.request(`solana_signAndSendTransaction`,{transaction:Wo(e)},Vo)).signature}catch(e){return this.signingError(e)}}signingError(e){let t=e instanceof A?e:new ce(e instanceof Error?e.message:void 0,e);throw this.emit(`error`,t),t}destroy(){this.disposed||(this.disposed=!0,++this.attempt,this.connectingPromise=void 0,this.release(),this.removeAllListeners(),this.endedListeners.clear())}},qo=`data:image/svg+xml,%3csvg%20width='66'%20height='56'%20viewBox='0%200%2066%2056'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20%3e%3cpath%20d='M46.6165%208.90197L33.0006%200L19.3872%208.90197L33.0006%2017.8066L46.6165%208.90197Z'%20fill='white'%20/%3e%3cpath%20d='M19.3872%2046.921L33.0006%2055.8256L46.6165%2046.921L33.0006%2038.019L19.3872%2046.921Z'%20fill='white'%20/%3e%3cpath%20d='M13.6159%2025.3516L0%2034.2535L13.6159%2043.1555L27.2293%2034.2535L13.6159%2025.3516Z'%20fill='white'%20/%3e%3cpath%20d='M52.3843%2025.3516L38.771%2034.2535L52.3843%2043.1555L66.0003%2034.2535L52.3843%2025.3516Z'%20fill='white'%20/%3e%3c/svg%3e`,Jo={Phantom:`https://chromewebstore.google.com/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa`,Trust:`https://chromewebstore.google.com/detail/trust-wallet/egjidjbpglichdcondbcbdnbeeppgdph`},Yo=e=>!!(`isSolanaConnector`in e&&e.isSolanaConnector);_();var Xo=c,Zo=/^[0-9a-fA-F]+$/u,Qo=e=>e.startsWith(`0x`)?e.slice(2):e,$o=e=>{let t=Qo(e.trim());return t.length>0&&t.length%2==0&&Zo.test(t)},es=e=>{let t=e.trim(),n=Qo(t);return $o(t)?{encoding:`hex`,buffer:v.from(n,`hex`)}:{encoding:`base64`,buffer:v.from(t,`base64`)}},ts=e=>es(e).buffer.toString(`hex`);export{re as A,oe as C,ae as D,ie as E,ce as F,j as M,ue as N,D as O,le as P,pe as S,k as T,_e as _,Yo as a,de as b,po as c,Xr as d,$r as f,ge as g,ve as h,Jo as i,se as j,A as k,Y as l,zo as m,ts as n,qo as o,gr as p,Xo as r,Ko as s,es as t,Q as u,M as v,O as w,me as x,fe as y};
|
|
1
|
+
import{n as e,o as t,r as n,s as r,t as i}from"./rolldown-runtime-BcKkbAw3.js";import{zt as a}from"./Result-Bvvef0v1.js";import{A as o,k as s,o as c,z as l}from"./assets-h8USQKgq.js";import{nn as u,wn as d}from"./wagmi-connect-result-B59F3NGW.js";import{n as f,t as p}from"./sha256-DmRqOOd6.js";import{n as m,t as h}from"./sha3-DRlIjSdj.js";import{n as g,r as _,t as v}from"./dist-CELdgNh9.js";import{n as ee,r as y,t as b}from"./eventemitter3-CTnouYki.js";import{n as te,t as x}from"./ed25519-DWgFEKI3.js";import{t as S}from"./dist-VPhQpe2v.js";import{t as ne}from"./bn-CqGbRtYY.js";import{t as C}from"./bs58-DoSnopGu.js";import{n as w,t as T}from"./secp256k1-BcfUQvi6.js";import{t as E}from"./esm-DhvlA6gG.js";y();var D=class extends Error{constructor(e,t){super(e),this.error=t}},re=class extends D{constructor(){super(...arguments),this.name=`WalletNotReadyError`}},O=class extends D{constructor(){super(...arguments),this.name=`WalletConfigError`}},k=class extends D{constructor(){super(...arguments),this.name=`WalletConnectionError`}},ie=class extends D{constructor(){super(...arguments),this.name=`WalletDisconnectedError`}},ae=class extends D{constructor(){super(...arguments),this.name=`WalletDisconnectionError`}},oe=class extends D{constructor(){super(...arguments),this.name=`WalletAccountError`}},se=class extends D{constructor(){super(...arguments),this.name=`WalletPublicKeyError`}},A=class extends D{constructor(){super(...arguments),this.name=`WalletNotConnectedError`}},j=class extends D{constructor(){super(...arguments),this.name=`WalletSendTransactionError`}},ce=class extends D{constructor(){super(...arguments),this.name=`WalletSignTransactionError`}},le=class extends D{constructor(){super(...arguments),this.name=`WalletSignMessageError`}},ue=class extends D{constructor(){super(...arguments),this.name=`WalletSignInError`}},de;(function(e){e.Installed=`Installed`,e.NotDetected=`NotDetected`,e.Loadable=`Loadable`,e.Unsupported=`Unsupported`})(de||={});var fe=class extends b{get connected(){return!!this.publicKey}async autoConnect(){await this.connect()}async prepareTransaction(e,t,n={}){let r=this.publicKey;if(!r)throw new A;return e.feePayer=e.feePayer||r,e.recentBlockhash=e.recentBlockhash||(await t.getLatestBlockhash({commitment:n.preflightCommitment,minContextSlot:n.minContextSlot})).blockhash,e}};function pe(e){if(typeof window>`u`||typeof document>`u`)return;let t=[];function n(){if(e())for(let e of t)e()}let r=setInterval(n,1e3);t.push(()=>clearInterval(r)),document.readyState===`loading`&&(document.addEventListener(`DOMContentLoaded`,n,{once:!0}),t.push(()=>document.removeEventListener(`DOMContentLoaded`,n))),document.readyState!==`complete`&&(window.addEventListener(`load`,n,{once:!0}),t.push(()=>window.removeEventListener(`load`,n))),n()}function me(){if(!navigator)return!1;let e=navigator.userAgent.toLowerCase(),t=e.includes(`iphone`)||e.includes(`ipad`),n=e.includes(`safari`);return t&&n}function M(e){return`version`in e}var he=class extends fe{async sendTransaction(e,t,n={}){let r=!0;try{if(M(e)){if(!this.supportedTransactionVersions)throw new j(`Sending versioned transactions isn't supported by this wallet`);if(!this.supportedTransactionVersions.has(e.version))throw new j(`Sending transaction version ${e.version} isn't supported by this wallet`);try{e=await this.signTransaction(e);let r=e.serialize();return await t.sendRawTransaction(r,n)}catch(e){throw e instanceof ce?(r=!1,e):new j(e?.message,e)}}try{let{signers:r,...i}=n;e=await this.prepareTransaction(e,t,i),r?.length&&e.partialSign(...r),e=await this.signTransaction(e);let a=e.serialize();return await t.sendRawTransaction(a,i)}catch(e){throw e instanceof ce?(r=!1,e):new j(e?.message,e)}}catch(e){throw r&&this.emit(`error`,e),e}}async signAllTransactions(e){for(let t of e)if(M(t)){if(!this.supportedTransactionVersions)throw new ce(`Signing versioned transactions isn't supported by this wallet`);if(!this.supportedTransactionVersions.has(t.version))throw new ce(`Signing transaction version ${t.version} isn't supported by this wallet`)}let t=[];for(let n of e)t.push(await this.signTransaction(n));return t}},ge=class extends he{},_e=class extends ge{},ve;(function(e){e.Mainnet=`mainnet-beta`,e.Testnet=`testnet`,e.Devnet=`devnet`})(ve||={});var ye=i(((e,t)=>{(function(e,t){function n(e,t){if(!e)throw Error(t||`Assertion failed`)}function r(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}function i(e,t,n){if(i.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,e!==null&&((t===`le`||t===`be`)&&(n=t,t=10),this._init(e||0,t||10,n||`be`))}typeof e==`object`?e.exports=i:t.BN=i,i.BN=i,i.wordSize=26;var a;try{a=typeof window<`u`&&window.Buffer!==void 0?window.Buffer:S().Buffer}catch{}i.isBN=function(e){return e instanceof i||typeof e==`object`&&!!e&&e.constructor.wordSize===i.wordSize&&Array.isArray(e.words)},i.max=function(e,t){return e.cmp(t)>0?e:t},i.min=function(e,t){return e.cmp(t)<0?e:t},i.prototype._init=function(e,t,r){if(typeof e==`number`)return this._initNumber(e,t,r);if(typeof e==`object`)return this._initArray(e,t,r);t===`hex`&&(t=16),n(t===(t|0)&&t>=2&&t<=36),e=e.toString().replace(/\s+/g,``);var i=0;e[0]===`-`&&(i++,this.negative=1),i<e.length&&(t===16?this._parseHex(e,i,r):(this._parseBase(e,t,i),r===`le`&&this._initArray(this.toArray(),t,r)))},i.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),r===`le`&&this._initArray(this.toArray(),t,r)},i.prototype._initArray=function(e,t,r){if(n(typeof e.length==`number`),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var a,o,s=0;if(r===`be`)for(i=e.length-1,a=0;i>=0;i-=3)o=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);else if(r===`le`)for(i=0,a=0;i<e.length;i+=3)o=e[i]|e[i+1]<<8|e[i+2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);return this._strip()};function o(e,t){var r=e.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;n(!1,`Invalid character in `+e)}function s(e,t,n){var r=o(e,n);return n-1>=t&&(r|=o(e,n-1)<<4),r}i.prototype._parseHex=function(e,t,n){this.length=Math.ceil((e.length-t)/6),this.words=Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var i=0,a=0,o;if(n===`be`)for(r=e.length-1;r>=t;r-=2)o=s(e,t,r)<<i,this.words[a]|=o&67108863,i>=18?(i-=18,a+=1,this.words[a]|=o>>>26):i+=8;else for(r=(e.length-t)%2==0?t+1:t;r<e.length;r+=2)o=s(e,t,r)<<i,this.words[a]|=o&67108863,i>=18?(i-=18,a+=1,this.words[a]|=o>>>26):i+=8;this._strip()};function c(e,t,r,i){for(var a=0,o=0,s=Math.min(e.length,r),c=t;c<s;c++){var l=e.charCodeAt(c)-48;a*=i,o=l>=49?l-49+10:l>=17?l-17+10:l,n(l>=0&&o<i,`Invalid character`),a+=o}return a}i.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var r=0,i=1;i<=67108863;i*=t)r++;r--,i=i/t|0;for(var a=e.length-n,o=a%r,s=Math.min(a,a-o)+n,l=0,u=n;u<s;u+=r)l=c(e,u,u+r,t),this.imuln(i),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(o!==0){var d=1;for(l=c(e,u,e.length,t),u=0;u<o;u++)d*=t;this.imuln(d),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this._strip()},i.prototype.copy=function(e){e.words=Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red};function l(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(i.prototype._move=function(e){l(e,this)},i.prototype.clone=function(){var e=new i(null);return this.copy(e),e},i.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<`u`&&typeof Symbol.for==`function`)try{i.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=u}catch{i.prototype.inspect=u}else i.prototype.inspect=u;function u(){return(this.red?`<BN-R: `:`<BN: `)+this.toString(16)+`>`}var d=`.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`.split(`.`),f=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(e,t){e||=10,t=t|0||1;var r;if(e===16||e===`hex`){r=``;for(var i=0,a=0,o=0;o<this.length;o++){var s=this.words[o],c=((s<<i|a)&16777215).toString(16);a=s>>>24-i&16777215,i+=2,i>=26&&(i-=26,o--),r=a!==0||o!==this.length-1?d[6-c.length]+c+r:c+r}for(a!==0&&(r=a.toString(16)+r);r.length%t!==0;)r=`0`+r;return this.negative!==0&&(r=`-`+r),r}if(e===(e|0)&&e>=2&&e<=36){var l=f[e],u=p[e];r=``;var m=this.clone();for(m.negative=0;!m.isZero();){var h=m.modrn(u).toString(e);m=m.idivn(u),r=m.isZero()?h+r:d[l-h.length]+h+r}for(this.isZero()&&(r=`0`+r);r.length%t!==0;)r=`0`+r;return this.negative!==0&&(r=`-`+r),r}n(!1,`Base should be between 2 and 36`)},i.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,`Number can only safely store up to 53 bits`),this.negative===0?e:-e},i.prototype.toJSON=function(){return this.toString(16,2)},a&&(i.prototype.toBuffer=function(e,t){return this.toArrayLike(a,e,t)}),i.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)};var m=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)};i.prototype.toArrayLike=function(e,t,r){this._strip();var i=this.byteLength(),a=r||Math.max(1,i);n(i<=a,`byte array longer than desired length`),n(a>0,`Requested array length <= 0`);var o=m(e,a),s=t===`le`?`LE`:`BE`;return this[`_toArrayLike`+s](o,i),o},i.prototype._toArrayLikeLE=function(e,t){for(var n=0,r=0,i=0,a=0;i<this.length;i++){var o=this.words[i]<<a|r;e[n++]=o&255,n<e.length&&(e[n++]=o>>8&255),n<e.length&&(e[n++]=o>>16&255),a===6?(n<e.length&&(e[n++]=o>>24&255),r=0,a=0):(r=o>>>24,a+=2)}if(n<e.length)for(e[n++]=r;n<e.length;)e[n++]=0},i.prototype._toArrayLikeBE=function(e,t){for(var n=e.length-1,r=0,i=0,a=0;i<this.length;i++){var o=this.words[i]<<a|r;e[n--]=o&255,n>=0&&(e[n--]=o>>8&255),n>=0&&(e[n--]=o>>16&255),a===6?(n>=0&&(e[n--]=o>>24&255),r=0,a=0):(r=o>>>24,a+=2)}if(n>=0)for(e[n--]=r;n>=0;)e[n--]=0},Math.clz32?i.prototype._countBits=function(e){return 32-Math.clz32(e)}:i.prototype._countBits=function(e){var t=e,n=0;return t>=4096&&(n+=13,t>>>=13),t>=64&&(n+=7,t>>>=7),t>=8&&(n+=4,t>>>=4),t>=2&&(n+=2,t>>>=2),n+t},i.prototype._zeroBits=function(e){if(e===0)return 26;var t=e,n=0;return t&8191||(n+=13,t>>>=13),t&127||(n+=7,t>>>=7),t&15||(n+=4,t>>>=4),t&3||(n+=2,t>>>=2),t&1||n++,n},i.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return(this.length-1)*26+t};function h(e){for(var t=Array(e.bitLength()),n=0;n<t.length;n++){var r=n/26|0,i=n%26;t[n]=e.words[r]>>>i&1}return t}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var n=this._zeroBits(this.words[t]);if(e+=n,n!==26)break}return e},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(e){return this.negative===0?this.clone():this.abs().inotn(e).iaddn(1)},i.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},i.prototype.ior=function(e){return n((this.negative|e.negative)===0),this.iuor(e)},i.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},i.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},i.prototype.iuand=function(e){for(var t=this.length>e.length?e:this,n=0;n<t.length;n++)this.words[n]=this.words[n]&e.words[n];return this.length=t.length,this._strip()},i.prototype.iand=function(e){return n((this.negative|e.negative)===0),this.iuand(e)},i.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},i.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},i.prototype.iuxor=function(e){var t,n;this.length>e.length?(t=this,n=e):(t=e,n=this);for(var r=0;r<n.length;r++)this.words[r]=t.words[r]^n.words[r];if(this!==t)for(;r<t.length;r++)this.words[r]=t.words[r];return this.length=t.length,this._strip()},i.prototype.ixor=function(e){return n((this.negative|e.negative)===0),this.iuxor(e)},i.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},i.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},i.prototype.inotn=function(e){n(typeof e==`number`&&e>=0);var t=Math.ceil(e/26)|0,r=e%26;this._expand(t),r>0&&t--;for(var i=0;i<t;i++)this.words[i]=~this.words[i]&67108863;for(r>0&&(this.words[i]=~this.words[i]&67108863>>26-r,i++);i<this.length;i++)this.words[i]=0;return this._strip()},i.prototype.notn=function(e){return this.clone().inotn(e)},i.prototype.setn=function(e,t){n(typeof e==`number`&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),t?this.words[r]=this.words[r]|1<<i:this.words[r]=this.words[r]&~(1<<i),this._strip()},i.prototype.iadd=function(e){var t;if(this.negative!==0&&e.negative===0)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();var n,r;this.length>e.length?(n=this,r=e):(n=e,r=this);for(var i=0,a=0;a<r.length;a++)t=(n.words[a]|0)+(r.words[a]|0)+i,this.words[a]=t&67108863,i=t>>>26;for(;i!==0&&a<n.length;a++)t=(n.words[a]|0)+i,this.words[a]=t&67108863,i=t>>>26;if(this.length=n.length,i!==0)this.words[this.length]=i,this.length++;else if(n!==this)for(;a<n.length;a++)this.words[a]=n.words[a];return this},i.prototype.add=function(e){var t;return e.negative!==0&&this.negative===0?(e.negative=0,t=this.sub(e),e.negative^=1,t):e.negative===0&&this.negative!==0?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},i.prototype.isub=function(e){if(e.negative!==0){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(this.negative!==0)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n=this.cmp(e);if(n===0)return this.negative=0,this.length=1,this.words[0]=0,this;var r,i;n>0?(r=this,i=e):(r=e,i=this);for(var a=0,o=0;o<i.length;o++)t=(r.words[o]|0)-(i.words[o]|0)+a,a=t>>26,this.words[o]=t&67108863;for(;a!==0&&o<r.length;o++)t=(r.words[o]|0)+a,a=t>>26,this.words[o]=t&67108863;if(a===0&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(e){return this.clone().isub(e)};function g(e,t,n){n.negative=t.negative^e.negative;var r=e.length+t.length|0;n.length=r,r=r-1|0;var i=e.words[0]|0,a=t.words[0]|0,o=i*a,s=o&67108863,c=o/67108864|0;n.words[0]=s;for(var l=1;l<r;l++){for(var u=c>>>26,d=c&67108863,f=Math.min(l,t.length-1),p=Math.max(0,l-e.length+1);p<=f;p++){var m=l-p|0;i=e.words[m]|0,a=t.words[p]|0,o=i*a+d,u+=o/67108864|0,d=o&67108863}n.words[l]=d|0,c=u|0}return c===0?n.length--:n.words[l]=c|0,n._strip()}var _=function(e,t,n){var r=e.words,i=t.words,a=n.words,o=0,s,c,l,u=r[0]|0,d=u&8191,f=u>>>13,p=r[1]|0,m=p&8191,h=p>>>13,g=r[2]|0,_=g&8191,v=g>>>13,ee=r[3]|0,y=ee&8191,b=ee>>>13,te=r[4]|0,x=te&8191,S=te>>>13,ne=r[5]|0,C=ne&8191,w=ne>>>13,T=r[6]|0,E=T&8191,D=T>>>13,re=r[7]|0,O=re&8191,k=re>>>13,ie=r[8]|0,ae=ie&8191,oe=ie>>>13,se=r[9]|0,A=se&8191,j=se>>>13,ce=i[0]|0,le=ce&8191,ue=ce>>>13,de=i[1]|0,fe=de&8191,pe=de>>>13,me=i[2]|0,M=me&8191,he=me>>>13,ge=i[3]|0,_e=ge&8191,ve=ge>>>13,ye=i[4]|0,be=ye&8191,N=ye>>>13,xe=i[5]|0,Se=xe&8191,Ce=xe>>>13,we=i[6]|0,Te=we&8191,Ee=we>>>13,De=i[7]|0,Oe=De&8191,ke=De>>>13,Ae=i[8]|0,P=Ae&8191,F=Ae>>>13,je=i[9]|0,Me=je&8191,Ne=je>>>13;n.negative=e.negative^t.negative,n.length=19,s=Math.imul(d,le),c=Math.imul(d,ue),c=c+Math.imul(f,le)|0,l=Math.imul(f,ue);var Pe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,s=Math.imul(m,le),c=Math.imul(m,ue),c=c+Math.imul(h,le)|0,l=Math.imul(h,ue),s=s+Math.imul(d,fe)|0,c=c+Math.imul(d,pe)|0,c=c+Math.imul(f,fe)|0,l=l+Math.imul(f,pe)|0;var Fe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,s=Math.imul(_,le),c=Math.imul(_,ue),c=c+Math.imul(v,le)|0,l=Math.imul(v,ue),s=s+Math.imul(m,fe)|0,c=c+Math.imul(m,pe)|0,c=c+Math.imul(h,fe)|0,l=l+Math.imul(h,pe)|0,s=s+Math.imul(d,M)|0,c=c+Math.imul(d,he)|0,c=c+Math.imul(f,M)|0,l=l+Math.imul(f,he)|0;var Ie=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,s=Math.imul(y,le),c=Math.imul(y,ue),c=c+Math.imul(b,le)|0,l=Math.imul(b,ue),s=s+Math.imul(_,fe)|0,c=c+Math.imul(_,pe)|0,c=c+Math.imul(v,fe)|0,l=l+Math.imul(v,pe)|0,s=s+Math.imul(m,M)|0,c=c+Math.imul(m,he)|0,c=c+Math.imul(h,M)|0,l=l+Math.imul(h,he)|0,s=s+Math.imul(d,_e)|0,c=c+Math.imul(d,ve)|0,c=c+Math.imul(f,_e)|0,l=l+Math.imul(f,ve)|0;var Le=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Le>>>26)|0,Le&=67108863,s=Math.imul(x,le),c=Math.imul(x,ue),c=c+Math.imul(S,le)|0,l=Math.imul(S,ue),s=s+Math.imul(y,fe)|0,c=c+Math.imul(y,pe)|0,c=c+Math.imul(b,fe)|0,l=l+Math.imul(b,pe)|0,s=s+Math.imul(_,M)|0,c=c+Math.imul(_,he)|0,c=c+Math.imul(v,M)|0,l=l+Math.imul(v,he)|0,s=s+Math.imul(m,_e)|0,c=c+Math.imul(m,ve)|0,c=c+Math.imul(h,_e)|0,l=l+Math.imul(h,ve)|0,s=s+Math.imul(d,be)|0,c=c+Math.imul(d,N)|0,c=c+Math.imul(f,be)|0,l=l+Math.imul(f,N)|0;var Re=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Re>>>26)|0,Re&=67108863,s=Math.imul(C,le),c=Math.imul(C,ue),c=c+Math.imul(w,le)|0,l=Math.imul(w,ue),s=s+Math.imul(x,fe)|0,c=c+Math.imul(x,pe)|0,c=c+Math.imul(S,fe)|0,l=l+Math.imul(S,pe)|0,s=s+Math.imul(y,M)|0,c=c+Math.imul(y,he)|0,c=c+Math.imul(b,M)|0,l=l+Math.imul(b,he)|0,s=s+Math.imul(_,_e)|0,c=c+Math.imul(_,ve)|0,c=c+Math.imul(v,_e)|0,l=l+Math.imul(v,ve)|0,s=s+Math.imul(m,be)|0,c=c+Math.imul(m,N)|0,c=c+Math.imul(h,be)|0,l=l+Math.imul(h,N)|0,s=s+Math.imul(d,Se)|0,c=c+Math.imul(d,Ce)|0,c=c+Math.imul(f,Se)|0,l=l+Math.imul(f,Ce)|0;var ze=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(ze>>>26)|0,ze&=67108863,s=Math.imul(E,le),c=Math.imul(E,ue),c=c+Math.imul(D,le)|0,l=Math.imul(D,ue),s=s+Math.imul(C,fe)|0,c=c+Math.imul(C,pe)|0,c=c+Math.imul(w,fe)|0,l=l+Math.imul(w,pe)|0,s=s+Math.imul(x,M)|0,c=c+Math.imul(x,he)|0,c=c+Math.imul(S,M)|0,l=l+Math.imul(S,he)|0,s=s+Math.imul(y,_e)|0,c=c+Math.imul(y,ve)|0,c=c+Math.imul(b,_e)|0,l=l+Math.imul(b,ve)|0,s=s+Math.imul(_,be)|0,c=c+Math.imul(_,N)|0,c=c+Math.imul(v,be)|0,l=l+Math.imul(v,N)|0,s=s+Math.imul(m,Se)|0,c=c+Math.imul(m,Ce)|0,c=c+Math.imul(h,Se)|0,l=l+Math.imul(h,Ce)|0,s=s+Math.imul(d,Te)|0,c=c+Math.imul(d,Ee)|0,c=c+Math.imul(f,Te)|0,l=l+Math.imul(f,Ee)|0;var Be=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Be>>>26)|0,Be&=67108863,s=Math.imul(O,le),c=Math.imul(O,ue),c=c+Math.imul(k,le)|0,l=Math.imul(k,ue),s=s+Math.imul(E,fe)|0,c=c+Math.imul(E,pe)|0,c=c+Math.imul(D,fe)|0,l=l+Math.imul(D,pe)|0,s=s+Math.imul(C,M)|0,c=c+Math.imul(C,he)|0,c=c+Math.imul(w,M)|0,l=l+Math.imul(w,he)|0,s=s+Math.imul(x,_e)|0,c=c+Math.imul(x,ve)|0,c=c+Math.imul(S,_e)|0,l=l+Math.imul(S,ve)|0,s=s+Math.imul(y,be)|0,c=c+Math.imul(y,N)|0,c=c+Math.imul(b,be)|0,l=l+Math.imul(b,N)|0,s=s+Math.imul(_,Se)|0,c=c+Math.imul(_,Ce)|0,c=c+Math.imul(v,Se)|0,l=l+Math.imul(v,Ce)|0,s=s+Math.imul(m,Te)|0,c=c+Math.imul(m,Ee)|0,c=c+Math.imul(h,Te)|0,l=l+Math.imul(h,Ee)|0,s=s+Math.imul(d,Oe)|0,c=c+Math.imul(d,ke)|0,c=c+Math.imul(f,Oe)|0,l=l+Math.imul(f,ke)|0;var Ve=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,s=Math.imul(ae,le),c=Math.imul(ae,ue),c=c+Math.imul(oe,le)|0,l=Math.imul(oe,ue),s=s+Math.imul(O,fe)|0,c=c+Math.imul(O,pe)|0,c=c+Math.imul(k,fe)|0,l=l+Math.imul(k,pe)|0,s=s+Math.imul(E,M)|0,c=c+Math.imul(E,he)|0,c=c+Math.imul(D,M)|0,l=l+Math.imul(D,he)|0,s=s+Math.imul(C,_e)|0,c=c+Math.imul(C,ve)|0,c=c+Math.imul(w,_e)|0,l=l+Math.imul(w,ve)|0,s=s+Math.imul(x,be)|0,c=c+Math.imul(x,N)|0,c=c+Math.imul(S,be)|0,l=l+Math.imul(S,N)|0,s=s+Math.imul(y,Se)|0,c=c+Math.imul(y,Ce)|0,c=c+Math.imul(b,Se)|0,l=l+Math.imul(b,Ce)|0,s=s+Math.imul(_,Te)|0,c=c+Math.imul(_,Ee)|0,c=c+Math.imul(v,Te)|0,l=l+Math.imul(v,Ee)|0,s=s+Math.imul(m,Oe)|0,c=c+Math.imul(m,ke)|0,c=c+Math.imul(h,Oe)|0,l=l+Math.imul(h,ke)|0,s=s+Math.imul(d,P)|0,c=c+Math.imul(d,F)|0,c=c+Math.imul(f,P)|0,l=l+Math.imul(f,F)|0;var He=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(He>>>26)|0,He&=67108863,s=Math.imul(A,le),c=Math.imul(A,ue),c=c+Math.imul(j,le)|0,l=Math.imul(j,ue),s=s+Math.imul(ae,fe)|0,c=c+Math.imul(ae,pe)|0,c=c+Math.imul(oe,fe)|0,l=l+Math.imul(oe,pe)|0,s=s+Math.imul(O,M)|0,c=c+Math.imul(O,he)|0,c=c+Math.imul(k,M)|0,l=l+Math.imul(k,he)|0,s=s+Math.imul(E,_e)|0,c=c+Math.imul(E,ve)|0,c=c+Math.imul(D,_e)|0,l=l+Math.imul(D,ve)|0,s=s+Math.imul(C,be)|0,c=c+Math.imul(C,N)|0,c=c+Math.imul(w,be)|0,l=l+Math.imul(w,N)|0,s=s+Math.imul(x,Se)|0,c=c+Math.imul(x,Ce)|0,c=c+Math.imul(S,Se)|0,l=l+Math.imul(S,Ce)|0,s=s+Math.imul(y,Te)|0,c=c+Math.imul(y,Ee)|0,c=c+Math.imul(b,Te)|0,l=l+Math.imul(b,Ee)|0,s=s+Math.imul(_,Oe)|0,c=c+Math.imul(_,ke)|0,c=c+Math.imul(v,Oe)|0,l=l+Math.imul(v,ke)|0,s=s+Math.imul(m,P)|0,c=c+Math.imul(m,F)|0,c=c+Math.imul(h,P)|0,l=l+Math.imul(h,F)|0,s=s+Math.imul(d,Me)|0,c=c+Math.imul(d,Ne)|0,c=c+Math.imul(f,Me)|0,l=l+Math.imul(f,Ne)|0;var Ue=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ue>>>26)|0,Ue&=67108863,s=Math.imul(A,fe),c=Math.imul(A,pe),c=c+Math.imul(j,fe)|0,l=Math.imul(j,pe),s=s+Math.imul(ae,M)|0,c=c+Math.imul(ae,he)|0,c=c+Math.imul(oe,M)|0,l=l+Math.imul(oe,he)|0,s=s+Math.imul(O,_e)|0,c=c+Math.imul(O,ve)|0,c=c+Math.imul(k,_e)|0,l=l+Math.imul(k,ve)|0,s=s+Math.imul(E,be)|0,c=c+Math.imul(E,N)|0,c=c+Math.imul(D,be)|0,l=l+Math.imul(D,N)|0,s=s+Math.imul(C,Se)|0,c=c+Math.imul(C,Ce)|0,c=c+Math.imul(w,Se)|0,l=l+Math.imul(w,Ce)|0,s=s+Math.imul(x,Te)|0,c=c+Math.imul(x,Ee)|0,c=c+Math.imul(S,Te)|0,l=l+Math.imul(S,Ee)|0,s=s+Math.imul(y,Oe)|0,c=c+Math.imul(y,ke)|0,c=c+Math.imul(b,Oe)|0,l=l+Math.imul(b,ke)|0,s=s+Math.imul(_,P)|0,c=c+Math.imul(_,F)|0,c=c+Math.imul(v,P)|0,l=l+Math.imul(v,F)|0,s=s+Math.imul(m,Me)|0,c=c+Math.imul(m,Ne)|0,c=c+Math.imul(h,Me)|0,l=l+Math.imul(h,Ne)|0;var We=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(We>>>26)|0,We&=67108863,s=Math.imul(A,M),c=Math.imul(A,he),c=c+Math.imul(j,M)|0,l=Math.imul(j,he),s=s+Math.imul(ae,_e)|0,c=c+Math.imul(ae,ve)|0,c=c+Math.imul(oe,_e)|0,l=l+Math.imul(oe,ve)|0,s=s+Math.imul(O,be)|0,c=c+Math.imul(O,N)|0,c=c+Math.imul(k,be)|0,l=l+Math.imul(k,N)|0,s=s+Math.imul(E,Se)|0,c=c+Math.imul(E,Ce)|0,c=c+Math.imul(D,Se)|0,l=l+Math.imul(D,Ce)|0,s=s+Math.imul(C,Te)|0,c=c+Math.imul(C,Ee)|0,c=c+Math.imul(w,Te)|0,l=l+Math.imul(w,Ee)|0,s=s+Math.imul(x,Oe)|0,c=c+Math.imul(x,ke)|0,c=c+Math.imul(S,Oe)|0,l=l+Math.imul(S,ke)|0,s=s+Math.imul(y,P)|0,c=c+Math.imul(y,F)|0,c=c+Math.imul(b,P)|0,l=l+Math.imul(b,F)|0,s=s+Math.imul(_,Me)|0,c=c+Math.imul(_,Ne)|0,c=c+Math.imul(v,Me)|0,l=l+Math.imul(v,Ne)|0;var Ge=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,s=Math.imul(A,_e),c=Math.imul(A,ve),c=c+Math.imul(j,_e)|0,l=Math.imul(j,ve),s=s+Math.imul(ae,be)|0,c=c+Math.imul(ae,N)|0,c=c+Math.imul(oe,be)|0,l=l+Math.imul(oe,N)|0,s=s+Math.imul(O,Se)|0,c=c+Math.imul(O,Ce)|0,c=c+Math.imul(k,Se)|0,l=l+Math.imul(k,Ce)|0,s=s+Math.imul(E,Te)|0,c=c+Math.imul(E,Ee)|0,c=c+Math.imul(D,Te)|0,l=l+Math.imul(D,Ee)|0,s=s+Math.imul(C,Oe)|0,c=c+Math.imul(C,ke)|0,c=c+Math.imul(w,Oe)|0,l=l+Math.imul(w,ke)|0,s=s+Math.imul(x,P)|0,c=c+Math.imul(x,F)|0,c=c+Math.imul(S,P)|0,l=l+Math.imul(S,F)|0,s=s+Math.imul(y,Me)|0,c=c+Math.imul(y,Ne)|0,c=c+Math.imul(b,Me)|0,l=l+Math.imul(b,Ne)|0;var Ke=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,s=Math.imul(A,be),c=Math.imul(A,N),c=c+Math.imul(j,be)|0,l=Math.imul(j,N),s=s+Math.imul(ae,Se)|0,c=c+Math.imul(ae,Ce)|0,c=c+Math.imul(oe,Se)|0,l=l+Math.imul(oe,Ce)|0,s=s+Math.imul(O,Te)|0,c=c+Math.imul(O,Ee)|0,c=c+Math.imul(k,Te)|0,l=l+Math.imul(k,Ee)|0,s=s+Math.imul(E,Oe)|0,c=c+Math.imul(E,ke)|0,c=c+Math.imul(D,Oe)|0,l=l+Math.imul(D,ke)|0,s=s+Math.imul(C,P)|0,c=c+Math.imul(C,F)|0,c=c+Math.imul(w,P)|0,l=l+Math.imul(w,F)|0,s=s+Math.imul(x,Me)|0,c=c+Math.imul(x,Ne)|0,c=c+Math.imul(S,Me)|0,l=l+Math.imul(S,Ne)|0;var qe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(qe>>>26)|0,qe&=67108863,s=Math.imul(A,Se),c=Math.imul(A,Ce),c=c+Math.imul(j,Se)|0,l=Math.imul(j,Ce),s=s+Math.imul(ae,Te)|0,c=c+Math.imul(ae,Ee)|0,c=c+Math.imul(oe,Te)|0,l=l+Math.imul(oe,Ee)|0,s=s+Math.imul(O,Oe)|0,c=c+Math.imul(O,ke)|0,c=c+Math.imul(k,Oe)|0,l=l+Math.imul(k,ke)|0,s=s+Math.imul(E,P)|0,c=c+Math.imul(E,F)|0,c=c+Math.imul(D,P)|0,l=l+Math.imul(D,F)|0,s=s+Math.imul(C,Me)|0,c=c+Math.imul(C,Ne)|0,c=c+Math.imul(w,Me)|0,l=l+Math.imul(w,Ne)|0;var Je=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Je>>>26)|0,Je&=67108863,s=Math.imul(A,Te),c=Math.imul(A,Ee),c=c+Math.imul(j,Te)|0,l=Math.imul(j,Ee),s=s+Math.imul(ae,Oe)|0,c=c+Math.imul(ae,ke)|0,c=c+Math.imul(oe,Oe)|0,l=l+Math.imul(oe,ke)|0,s=s+Math.imul(O,P)|0,c=c+Math.imul(O,F)|0,c=c+Math.imul(k,P)|0,l=l+Math.imul(k,F)|0,s=s+Math.imul(E,Me)|0,c=c+Math.imul(E,Ne)|0,c=c+Math.imul(D,Me)|0,l=l+Math.imul(D,Ne)|0;var Ye=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,s=Math.imul(A,Oe),c=Math.imul(A,ke),c=c+Math.imul(j,Oe)|0,l=Math.imul(j,ke),s=s+Math.imul(ae,P)|0,c=c+Math.imul(ae,F)|0,c=c+Math.imul(oe,P)|0,l=l+Math.imul(oe,F)|0,s=s+Math.imul(O,Me)|0,c=c+Math.imul(O,Ne)|0,c=c+Math.imul(k,Me)|0,l=l+Math.imul(k,Ne)|0;var Xe=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,s=Math.imul(A,P),c=Math.imul(A,F),c=c+Math.imul(j,P)|0,l=Math.imul(j,F),s=s+Math.imul(ae,Me)|0,c=c+Math.imul(ae,Ne)|0,c=c+Math.imul(oe,Me)|0,l=l+Math.imul(oe,Ne)|0;var Ze=(o+s|0)+((c&8191)<<13)|0;o=(l+(c>>>13)|0)+(Ze>>>26)|0,Ze&=67108863,s=Math.imul(A,Me),c=Math.imul(A,Ne),c=c+Math.imul(j,Me)|0,l=Math.imul(j,Ne);var Qe=(o+s|0)+((c&8191)<<13)|0;return o=(l+(c>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,a[0]=Pe,a[1]=Fe,a[2]=Ie,a[3]=Le,a[4]=Re,a[5]=ze,a[6]=Be,a[7]=Ve,a[8]=He,a[9]=Ue,a[10]=We,a[11]=Ge,a[12]=Ke,a[13]=qe,a[14]=Je,a[15]=Ye,a[16]=Xe,a[17]=Ze,a[18]=Qe,o!==0&&(a[19]=o,n.length++),n};Math.imul||(_=g);function v(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var r=0,i=0,a=0;a<n.length-1;a++){var o=i;i=0;for(var s=r&67108863,c=Math.min(a,t.length-1),l=Math.max(0,a-e.length+1);l<=c;l++){var u=a-l,d=(e.words[u]|0)*(t.words[l]|0),f=d&67108863;o=o+(d/67108864|0)|0,f=f+s|0,s=f&67108863,o=o+(f>>>26)|0,i+=o>>>26,o&=67108863}n.words[a]=s,r=o,o=i}return r===0?n.length--:n.words[a]=r,n._strip()}function ee(e,t,n){return v(e,t,n)}i.prototype.mulTo=function(e,t){var n,r=this.length+e.length;return n=this.length===10&&e.length===10?_(this,e,t):r<63?g(this,e,t):r<1024?v(this,e,t):ee(this,e,t),n};function y(e,t){this.x=e,this.y=t}y.prototype.makeRBT=function(e){for(var t=Array(e),n=i.prototype._countBits(e)-1,r=0;r<e;r++)t[r]=this.revBin(r,n,e);return t},y.prototype.revBin=function(e,t,n){if(e===0||e===n-1)return e;for(var r=0,i=0;i<t;i++)r|=(e&1)<<t-i-1,e>>=1;return r},y.prototype.permute=function(e,t,n,r,i,a){for(var o=0;o<a;o++)r[o]=t[e[o]],i[o]=n[e[o]]},y.prototype.transform=function(e,t,n,r,i,a){this.permute(a,e,t,n,r,i);for(var o=1;o<i;o<<=1)for(var s=o<<1,c=Math.cos(2*Math.PI/s),l=Math.sin(2*Math.PI/s),u=0;u<i;u+=s)for(var d=c,f=l,p=0;p<o;p++){var m=n[u+p],h=r[u+p],g=n[u+p+o],_=r[u+p+o],v=d*g-f*_;_=d*_+f*g,g=v,n[u+p]=m+g,r[u+p]=h+_,n[u+p+o]=m-g,r[u+p+o]=h-_,p!==s&&(v=c*d-l*f,f=c*f+l*d,d=v)}},y.prototype.guessLen13b=function(e,t){var n=Math.max(t,e)|1,r=n&1,i=0;for(n=n/2|0;n;n>>>=1)i++;return 1<<i+1+r},y.prototype.conjugate=function(e,t,n){if(!(n<=1))for(var r=0;r<n/2;r++){var i=e[r];e[r]=e[n-r-1],e[n-r-1]=i,i=t[r],t[r]=-t[n-r-1],t[n-r-1]=-i}},y.prototype.normalize13b=function(e,t){for(var n=0,r=0;r<t/2;r++){var i=Math.round(e[2*r+1]/t)*8192+Math.round(e[2*r]/t)+n;e[r]=i&67108863,n=i<67108864?0:i/67108864|0}return e},y.prototype.convert13b=function(e,t,r,i){for(var a=0,o=0;o<t;o++)a+=e[o]|0,r[2*o]=a&8191,a>>>=13,r[2*o+1]=a&8191,a>>>=13;for(o=2*t;o<i;++o)r[o]=0;n(a===0),n(!(a&-8192))},y.prototype.stub=function(e){for(var t=Array(e),n=0;n<e;n++)t[n]=0;return t},y.prototype.mulp=function(e,t,n){var r=2*this.guessLen13b(e.length,t.length),i=this.makeRBT(r),a=this.stub(r),o=Array(r),s=Array(r),c=Array(r),l=Array(r),u=Array(r),d=Array(r),f=n.words;f.length=r,this.convert13b(e.words,e.length,o,r),this.convert13b(t.words,t.length,l,r),this.transform(o,a,s,c,r,i),this.transform(l,a,u,d,r,i);for(var p=0;p<r;p++){var m=s[p]*u[p]-c[p]*d[p];c[p]=s[p]*d[p]+c[p]*u[p],s[p]=m}return this.conjugate(s,c,r),this.transform(s,c,f,a,r,i),this.conjugate(f,a,r),this.normalize13b(f,r),n.negative=e.negative^t.negative,n.length=e.length+t.length,n._strip()},i.prototype.mul=function(e){var t=new i(null);return t.words=Array(this.length+e.length),this.mulTo(e,t)},i.prototype.mulf=function(e){var t=new i(null);return t.words=Array(this.length+e.length),ee(this,e,t)},i.prototype.imul=function(e){return this.clone().mulTo(e,this)},i.prototype.imuln=function(e){var t=e<0;t&&(e=-e),n(typeof e==`number`),n(e<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*e,o=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=o>>>26,this.words[i]=o&67108863}return r!==0&&(this.words[i]=r,this.length++),e===0&&(this.length=1,this._normSign()),t?this.ineg():this},i.prototype.muln=function(e){return this.clone().imuln(e)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(e){var t=h(e);if(t.length===0)return new i(1);for(var n=this,r=0;r<t.length&&t[r]===0;r++,n=n.sqr());if(++r<t.length)for(var a=n.sqr();r<t.length;r++,a=a.sqr())t[r]!==0&&(n=n.mul(a));return n},i.prototype.iushln=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26,i=67108863>>>26-t<<26-t,a;if(t!==0){var o=0;for(a=0;a<this.length;a++){var s=this.words[a]&i,c=(this.words[a]|0)-s<<t;this.words[a]=c|o,o=s>>>26-t}o&&(this.words[a]=o,this.length++)}if(r!==0){for(a=this.length-1;a>=0;a--)this.words[a+r]=this.words[a];for(a=0;a<r;a++)this.words[a]=0;this.length+=r}return this._strip()},i.prototype.ishln=function(e){return n(this.negative===0),this.iushln(e)},i.prototype.iushrn=function(e,t,r){n(typeof e==`number`&&e>=0);var i=t?(t-t%26)/26:0,a=e%26,o=Math.min((e-a)/26,this.length),s=67108863^67108863>>>a<<a,c=r;if(i-=o,i=Math.max(0,i),c){for(var l=0;l<o;l++)c.words[l]=this.words[l];c.length=o}if(o!==0){if(this.length>o)for(this.length-=o,l=0;l<this.length;l++)this.words[l]=this.words[l+o];else this.words[0]=0,this.length=1}var u=0;for(l=this.length-1;l>=0&&(u!==0||l>=i);l--){var d=this.words[l]|0;this.words[l]=u<<26-a|d>>>a,u=d&s}return c&&u!==0&&(c.words[c.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(e,t,r){return n(this.negative===0),this.iushrn(e,t,r)},i.prototype.shln=function(e){return this.clone().ishln(e)},i.prototype.ushln=function(e){return this.clone().iushln(e)},i.prototype.shrn=function(e){return this.clone().ishrn(e)},i.prototype.ushrn=function(e){return this.clone().iushrn(e)},i.prototype.testn=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26,i=1<<t;return this.length<=r?!1:!!(this.words[r]&i)},i.prototype.imaskn=function(e){n(typeof e==`number`&&e>=0);var t=e%26,r=(e-t)/26;if(n(this.negative===0,`imaskn works only with positive numbers`),this.length<=r)return this;if(t!==0&&r++,this.length=Math.min(r,this.length),t!==0){var i=67108863^67108863>>>t<<t;this.words[this.length-1]&=i}return this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.maskn=function(e){return this.clone().imaskn(e)},i.prototype.iaddn=function(e){return n(typeof e==`number`),n(e<67108864),e<0?this.isubn(-e):this.negative===0?this._iaddn(e):this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this)},i.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},i.prototype.isubn=function(e){if(n(typeof e==`number`),n(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,--this.words[t+1];return this._strip()},i.prototype.addn=function(e){return this.clone().iaddn(e)},i.prototype.subn=function(e){return this.clone().isubn(e)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(e,t,r){var i=e.length+r,a;this._expand(i);var o,s=0;for(a=0;a<e.length;a++){o=(this.words[a+r]|0)+s;var c=(e.words[a]|0)*t;o-=c&67108863,s=(o>>26)-(c/67108864|0),this.words[a+r]=o&67108863}for(;a<this.length-r;a++)o=(this.words[a+r]|0)+s,s=o>>26,this.words[a+r]=o&67108863;if(s===0)return this._strip();for(n(s===-1),s=0,a=0;a<this.length;a++)o=-(this.words[a]|0)+s,s=o>>26,this.words[a]=o&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(e,t){var n=this.length-e.length,r=this.clone(),a=e,o=a.words[a.length-1]|0;n=26-this._countBits(o),n!==0&&(a=a.ushln(n),r.iushln(n),o=a.words[a.length-1]|0);var s=r.length-a.length,c;if(t!==`mod`){c=new i(null),c.length=s+1,c.words=Array(c.length);for(var l=0;l<c.length;l++)c.words[l]=0}var u=r.clone()._ishlnsubmul(a,1,s);u.negative===0&&(r=u,c&&(c.words[s]=1));for(var d=s-1;d>=0;d--){var f=(r.words[a.length+d]|0)*67108864+(r.words[a.length+d-1]|0);for(f=Math.min(f/o|0,67108863),r._ishlnsubmul(a,f,d);r.negative!==0;)f--,r.negative=0,r._ishlnsubmul(a,1,d),r.isZero()||(r.negative^=1);c&&(c.words[d]=f)}return c&&c._strip(),r._strip(),t!==`div`&&n!==0&&r.iushrn(n),{div:c||null,mod:r}},i.prototype.divmod=function(e,t,r){if(n(!e.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var a,o,s;return this.negative!==0&&e.negative===0?(s=this.neg().divmod(e,t),t!==`mod`&&(a=s.div.neg()),t!==`div`&&(o=s.mod.neg(),r&&o.negative!==0&&o.iadd(e)),{div:a,mod:o}):this.negative===0&&e.negative!==0?(s=this.divmod(e.neg(),t),t!==`mod`&&(a=s.div.neg()),{div:a,mod:s.mod}):(this.negative&e.negative)===0?e.length>this.length||this.cmp(e)<0?{div:new i(0),mod:this}:e.length===1?t===`div`?{div:this.divn(e.words[0]),mod:null}:t===`mod`?{div:null,mod:new i(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new i(this.modrn(e.words[0]))}:this._wordDiv(e,t):(s=this.neg().divmod(e.neg(),t),t!==`div`&&(o=s.mod.neg(),r&&o.negative!==0&&o.isub(e)),{div:s.div,mod:o})},i.prototype.div=function(e){return this.divmod(e,`div`,!1).div},i.prototype.mod=function(e){return this.divmod(e,`mod`,!1).mod},i.prototype.umod=function(e){return this.divmod(e,`mod`,!0).mod},i.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=t.mod.abs(),r=e.abs().iushrn(1),a=e.words[0]&1,o=n.cmp(r);if(o<0||a===1&&o===0)return t.div;var s=new i(1);return s.negative=this.negative^e.negative,t.div.iadd(s)},i.prototype.modrn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=(1<<26)%e,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%e;return t?-i:i},i.prototype.modn=function(e){return this.modrn(e)},i.prototype.idivn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/e|0,r=a%e}return this._strip(),t?this.ineg():this},i.prototype.divn=function(e){return this.clone().idivn(e)},i.prototype.egcd=function(e){n(e.negative===0),n(!e.isZero());var t=this,r=e.clone();t=t.negative===0?t.clone():t.umod(e);for(var a=new i(1),o=new i(0),s=new i(0),c=new i(1),l=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++l;for(var u=r.clone(),d=t.clone();!t.isZero();){for(var f=0,p=1;(t.words[0]&p)===0&&f<26;++f,p<<=1);if(f>0)for(t.iushrn(f);f-->0;)(a.isOdd()||o.isOdd())&&(a.iadd(u),o.isub(d)),a.iushrn(1),o.iushrn(1);for(var m=0,h=1;(r.words[0]&h)===0&&m<26;++m,h<<=1);if(m>0)for(r.iushrn(m);m-->0;)(s.isOdd()||c.isOdd())&&(s.iadd(u),c.isub(d)),s.iushrn(1),c.iushrn(1);t.cmp(r)>=0?(t.isub(r),a.isub(s),o.isub(c)):(r.isub(t),s.isub(a),c.isub(o))}return{a:s,b:c,gcd:r.iushln(l)}},i.prototype._invmp=function(e){n(e.negative===0),n(!e.isZero());var t=this,r=e.clone();t=t.negative===0?t.clone():t.umod(e);for(var a=new i(1),o=new i(0),s=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,l=1;(t.words[0]&l)===0&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-->0;)a.isOdd()&&a.iadd(s),a.iushrn(1);for(var u=0,d=1;(r.words[0]&d)===0&&u<26;++u,d<<=1);if(u>0)for(r.iushrn(u);u-->0;)o.isOdd()&&o.iadd(s),o.iushrn(1);t.cmp(r)>=0?(t.isub(r),a.isub(o)):(r.isub(t),o.isub(a))}var f=t.cmpn(1)===0?a:o;return f.cmpn(0)<0&&f.iadd(e),f},i.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),n=e.clone();t.negative=0,n.negative=0;for(var r=0;t.isEven()&&n.isEven();r++)t.iushrn(1),n.iushrn(1);do{for(;t.isEven();)t.iushrn(1);for(;n.isEven();)n.iushrn(1);var i=t.cmp(n);if(i<0){var a=t;t=n,n=a}else if(i===0||n.cmpn(1)===0)break;t.isub(n)}while(1);return n.iushln(r)},i.prototype.invm=function(e){return this.egcd(e).a.umod(e)},i.prototype.isEven=function(){return!(this.words[0]&1)},i.prototype.isOdd=function(){return(this.words[0]&1)==1},i.prototype.andln=function(e){return this.words[0]&e},i.prototype.bincn=function(e){n(typeof e==`number`);var t=e%26,r=(e-t)/26,i=1<<t;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var a=i,o=r;a!==0&&o<this.length;o++){var s=this.words[o]|0;s+=a,a=s>>>26,s&=67108863,this.words[o]=s}return a!==0&&(this.words[o]=a,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(e){var t=e<0;if(this.negative!==0&&!t)return-1;if(this.negative===0&&t)return 1;this._strip();var r;if(this.length>1)r=1;else{t&&(e=-e),n(e<=67108863,`Number is too big`);var i=this.words[0]|0;r=i===e?0:i<e?-1:1}return this.negative===0?r:-r|0},i.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var t=this.ucmp(e);return this.negative===0?t:-t|0},i.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,n=this.length-1;n>=0;n--){var r=this.words[n]|0,i=e.words[n]|0;if(r!==i){r<i?t=-1:r>i&&(t=1);break}}return t},i.prototype.gtn=function(e){return this.cmpn(e)===1},i.prototype.gt=function(e){return this.cmp(e)===1},i.prototype.gten=function(e){return this.cmpn(e)>=0},i.prototype.gte=function(e){return this.cmp(e)>=0},i.prototype.ltn=function(e){return this.cmpn(e)===-1},i.prototype.lt=function(e){return this.cmp(e)===-1},i.prototype.lten=function(e){return this.cmpn(e)<=0},i.prototype.lte=function(e){return this.cmp(e)<=0},i.prototype.eqn=function(e){return this.cmpn(e)===0},i.prototype.eq=function(e){return this.cmp(e)===0},i.red=function(e){return new T(e)},i.prototype.toRed=function(e){return n(!this.red,`Already a number in reduction context`),n(this.negative===0,`red works only with positives`),e.convertTo(this)._forceRed(e)},i.prototype.fromRed=function(){return n(this.red,`fromRed works only with numbers in reduction context`),this.red.convertFrom(this)},i.prototype._forceRed=function(e){return this.red=e,this},i.prototype.forceRed=function(e){return n(!this.red,`Already a number in reduction context`),this._forceRed(e)},i.prototype.redAdd=function(e){return n(this.red,`redAdd works only with red numbers`),this.red.add(this,e)},i.prototype.redIAdd=function(e){return n(this.red,`redIAdd works only with red numbers`),this.red.iadd(this,e)},i.prototype.redSub=function(e){return n(this.red,`redSub works only with red numbers`),this.red.sub(this,e)},i.prototype.redISub=function(e){return n(this.red,`redISub works only with red numbers`),this.red.isub(this,e)},i.prototype.redShl=function(e){return n(this.red,`redShl works only with red numbers`),this.red.shl(this,e)},i.prototype.redMul=function(e){return n(this.red,`redMul works only with red numbers`),this.red._verify2(this,e),this.red.mul(this,e)},i.prototype.redIMul=function(e){return n(this.red,`redMul works only with red numbers`),this.red._verify2(this,e),this.red.imul(this,e)},i.prototype.redSqr=function(){return n(this.red,`redSqr works only with red numbers`),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,`redISqr works only with red numbers`),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,`redSqrt works only with red numbers`),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,`redInvm works only with red numbers`),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,`redNeg works only with red numbers`),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(e){return n(this.red&&!e.red,`redPow(normalNum)`),this.red._verify1(this),this.red.pow(this,e)};var b={k256:null,p224:null,p192:null,p25519:null};function te(e,t){this.name=e,this.p=new i(t,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}te.prototype._tmp=function(){var e=new i(null);return e.words=Array(Math.ceil(this.n/13)),e},te.prototype.ireduce=function(e){var t=e,n;do this.split(t,this.tmp),t=this.imulK(t),t=t.iadd(this.tmp),n=t.bitLength();while(n>this.n);var r=n<this.n?-1:t.ucmp(this.p);return r===0?(t.words[0]=0,t.length=1):r>0?t.isub(this.p):t.strip===void 0?t._strip():t.strip(),t},te.prototype.split=function(e,t){e.iushrn(this.n,0,t)},te.prototype.imulK=function(e){return e.imul(this.k)};function x(){te.call(this,`k256`,`ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f`)}r(x,te),x.prototype.split=function(e,t){for(var n=4194303,r=Math.min(e.length,9),i=0;i<r;i++)t.words[i]=e.words[i];if(t.length=r,e.length<=9){e.words[0]=0,e.length=1;return}var a=e.words[9];for(t.words[t.length++]=a&n,i=10;i<e.length;i++){var o=e.words[i]|0;e.words[i-10]=(o&n)<<4|a>>>22,a=o}a>>>=22,e.words[i-10]=a,a===0&&e.length>10?e.length-=10:e.length-=9},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0;n<e.length;n++){var r=e.words[n]|0;t+=r*977,e.words[n]=t&67108863,t=r*64+(t/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function ne(){te.call(this,`p224`,`ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001`)}r(ne,te);function C(){te.call(this,`p192`,`ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff`)}r(C,te);function w(){te.call(this,`25519`,`7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed`)}r(w,te),w.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var r=(e.words[n]|0)*19+t,i=r&67108863;r>>>=26,e.words[n]=i,t=r}return t!==0&&(e.words[e.length++]=t),e},i._prime=function(e){if(b[e])return b[e];var t;if(e===`k256`)t=new x;else if(e===`p224`)t=new ne;else if(e===`p192`)t=new C;else if(e===`p25519`)t=new w;else throw Error(`Unknown prime `+e);return b[e]=t,t};function T(e){if(typeof e==`string`){var t=i._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),`modulus must be greater than 1`),this.m=e,this.prime=null}T.prototype._verify1=function(e){n(e.negative===0,`red works only with positives`),n(e.red,`red works only with red numbers`)},T.prototype._verify2=function(e,t){n((e.negative|t.negative)===0,`red works only with positives`),n(e.red&&e.red===t.red,`red works only with red numbers`)},T.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(l(e,e.umod(this.m)._forceRed(this)),e)},T.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},T.prototype.add=function(e,t){this._verify2(e,t);var n=e.add(t);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},T.prototype.iadd=function(e,t){this._verify2(e,t);var n=e.iadd(t);return n.cmp(this.m)>=0&&n.isub(this.m),n},T.prototype.sub=function(e,t){this._verify2(e,t);var n=e.sub(t);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},T.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return n.cmpn(0)<0&&n.iadd(this.m),n},T.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},T.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},T.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},T.prototype.isqr=function(e){return this.imul(e,e.clone())},T.prototype.sqr=function(e){return this.mul(e,e)},T.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),t===3){var r=this.m.add(new i(1)).iushrn(2);return this.pow(e,r)}for(var a=this.m.subn(1),o=0;!a.isZero()&&a.andln(1)===0;)o++,a.iushrn(1);n(!a.isZero());var s=new i(1).toRed(this),c=s.redNeg(),l=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new i(2*u*u).toRed(this);this.pow(u,l).cmp(c)!==0;)u.redIAdd(c);for(var d=this.pow(u,a),f=this.pow(e,a.addn(1).iushrn(1)),p=this.pow(e,a),m=o;p.cmp(s)!==0;){for(var h=p,g=0;h.cmp(s)!==0;g++)h=h.redSqr();n(g<m);var _=this.pow(d,new i(1).iushln(m-g-1));f=f.redMul(_),d=_.redSqr(),p=p.redMul(d),m=g}return f},T.prototype.invm=function(e){var t=e._invmp(this.m);return t.negative===0?this.imod(t):(t.negative=0,this.imod(t).redNeg())},T.prototype.pow=function(e,t){if(t.isZero())return new i(1).toRed(this);if(t.cmpn(1)===0)return e.clone();var n=4,r=Array(1<<n);r[0]=new i(1).toRed(this),r[1]=e;for(var a=2;a<r.length;a++)r[a]=this.mul(r[a-1],e);var o=r[0],s=0,c=0,l=t.bitLength()%26;for(l===0&&(l=26),a=t.length-1;a>=0;a--){for(var u=t.words[a],d=l-1;d>=0;d--){var f=u>>d&1;if(o!==r[0]&&(o=this.sqr(o)),f===0&&s===0){c=0;continue}s<<=1,s|=f,c++,(c===n||a===0&&d===0)&&(o=this.mul(o,r[s]),c=0,s=0)}l=26}return o},T.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},T.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},i.mont=function(e){return new E(e)};function E(e){T.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(E,T),E.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},E.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},E.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var n=e.imul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),a=i;return i.cmp(this.m)>=0?a=i.isub(this.m):i.cmpn(0)<0&&(a=i.iadd(this.m)),a._forceRed(this)},E.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new i(0)._forceRed(this);var n=e.mul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),a=n.isub(r).iushrn(this.shift),o=a;return a.cmp(this.m)>=0?o=a.isub(this.m):a.cmpn(0)<0&&(o=a.iadd(this.m)),o._forceRed(this)},E.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}})(t===void 0||t,e)})),be=n({TextDecoder:()=>Ee,TextEncoder:()=>De});function N(e,t,n){return t<=e&&e<=n}function xe(e){if(e===void 0)return{};if(e===Object(e))return e;throw TypeError(`Could not convert argument to dictionary`)}function Se(e){for(var t=String(e),n=t.length,r=0,i=[];r<n;){var a=t.charCodeAt(r);if(a<55296||a>57343)i.push(a);else if(56320<=a&&a<=57343)i.push(65533);else if(55296<=a&&a<=56319){if(r===n-1)i.push(65533);else{var o=e.charCodeAt(r+1);if(56320<=o&&o<=57343){var s=a&1023,c=o&1023;i.push(65536+(s<<10)+c),r+=1}else i.push(65533)}}r+=1}return i}function Ce(e){for(var t=``,n=0;n<e.length;++n){var r=e[n];r<=65535?t+=String.fromCharCode(r):(r-=65536,t+=String.fromCharCode((r>>10)+55296,(r&1023)+56320))}return t}function we(e){this.tokens=[].slice.call(e)}function Te(e,t){if(e)throw TypeError(`Decoder error`);return t||65533}function Ee(e,t){if(!(this instanceof Ee))return new Ee(e,t);if(e=e===void 0?F:String(e).toLowerCase(),e!==F)throw Error(`Encoding not supported. Only utf-8 is supported`);t=xe(t),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=!!t.fatal,this._ignoreBOM=!!t.ignoreBOM,Object.defineProperty(this,"encoding",{value:`utf-8`}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function De(e,t){if(!(this instanceof De))return new De(e,t);if(e=e===void 0?F:String(e).toLowerCase(),e!==F)throw Error(`Encoding not supported. Only utf-8 is supported`);t=xe(t),this._streaming=!1,this._encoder=null,this._options={fatal:!!t.fatal},Object.defineProperty(this,"encoding",{value:`utf-8`})}function Oe(e){var t=e.fatal,n=0,r=0,i=0,a=128,o=191;this.handler=function(e,s){if(s===Ae&&i!==0)return i=0,Te(t);if(s===Ae)return P;if(i===0){if(N(s,0,127))return s;if(N(s,194,223))i=1,n=s-192;else if(N(s,224,239))s===224&&(a=160),s===237&&(o=159),i=2,n=s-224;else if(N(s,240,244))s===240&&(a=144),s===244&&(o=143),i=3,n=s-240;else return Te(t);return n<<=6*i,null}if(!N(s,a,o))return n=i=r=0,a=128,o=191,e.prepend(s),Te(t);if(a=128,o=191,r+=1,n+=s-128<<6*(i-r),r!==i)return null;var c=n;return n=i=r=0,c}}function ke(e){e.fatal,this.handler=function(e,t){if(t===Ae)return P;if(N(t,0,127))return t;var n,r;N(t,128,2047)?(n=1,r=192):N(t,2048,65535)?(n=2,r=224):N(t,65536,1114111)&&(n=3,r=240);for(var i=[(t>>6*n)+r];n>0;){var a=t>>6*(n-1);i.push(128|a&63),--n}return i}}var Ae,P,F,je=e((()=>{Ae=-1,we.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Ae},prepend:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.unshift(t.pop());else this.tokens.unshift(e)},push:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.push(t.shift());else this.tokens.push(e)}},P=-1,F=`utf-8`,Ee.prototype={decode:function(e,t){var n=typeof e==`object`&&e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`object`&&`buffer`in e&&e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array;t=xe(t),this._streaming||(this._decoder=new Oe({fatal:this._fatal}),this._BOMseen=!1),this._streaming=!!t.stream;for(var r=new we(n),i=[],a;!r.endOfStream()&&(a=this._decoder.handler(r,r.read()),a!==P);)a!==null&&(Array.isArray(a)?i.push.apply(i,a):i.push(a));if(!this._streaming){do{if(a=this._decoder.handler(r,r.read()),a===P)break;a!==null&&(Array.isArray(a)?i.push.apply(i,a):i.push(a))}while(!r.endOfStream());this._decoder=null}return i.length&&[`utf-8`].indexOf(this.encoding)!==-1&&!this._ignoreBOM&&!this._BOMseen&&(i[0]===65279?(this._BOMseen=!0,i.shift()):this._BOMseen=!0),Ce(i)}},De.prototype={encode:function(e,t){e=e?String(e):``,t=xe(t),this._streaming||(this._encoder=new ke(this._options)),this._streaming=!!t.stream;for(var n=[],r=new we(Se(e)),i;!r.endOfStream()&&(i=this._encoder.handler(r,r.read()),i!==P);)Array.isArray(i)?n.push.apply(n,i):n.push(i);if(!this._streaming){for(;i=this._encoder.handler(r,r.read()),i!==P;)Array.isArray(i)?n.push.apply(n,i):n.push(i);this._encoder=null}return new Uint8Array(n)}}})),Me=i((e=>{_();var n=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),r=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),i=e&&e.__decorate||function(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a},a=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var i in e)i!=="default"&&Object.hasOwnProperty.call(e,i)&&n(t,e,i);return r(t,e),t},o=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.deserializeUnchecked=e.deserialize=e.serialize=e.BinaryReader=e.BinaryWriter=e.BorshError=e.baseDecode=e.baseEncode=void 0;var s=o(ne()),c=o(C()),l=a((je(),t(be))),u=new(typeof TextDecoder==`function`?TextDecoder:l.TextDecoder)(`utf-8`,{fatal:!0});function d(e){return typeof e==`string`&&(e=v.from(e,`utf8`)),c.default.encode(v.from(e))}e.baseEncode=d;function f(e){return v.from(c.default.decode(e))}e.baseDecode=f;var p=1024,m=class extends Error{constructor(e){super(e),this.fieldPath=[],this.originalMessage=e}addToFieldPath(e){this.fieldPath.splice(0,0,e),this.message=this.originalMessage+`: `+this.fieldPath.join(`.`)}};e.BorshError=m;var h=class{constructor(){this.buf=v.alloc(p),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=v.concat([this.buf,v.alloc(p)]))}writeU8(e){this.maybeResize(),this.buf.writeUInt8(e,this.length),this.length+=1}writeU16(e){this.maybeResize(),this.buf.writeUInt16LE(e,this.length),this.length+=2}writeU32(e){this.maybeResize(),this.buf.writeUInt32LE(e,this.length),this.length+=4}writeU64(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,8)))}writeU128(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,16)))}writeU256(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,32)))}writeU512(e){this.maybeResize(),this.writeBuffer(v.from(new s.default(e).toArray(`le`,64)))}writeBuffer(e){this.buf=v.concat([v.from(this.buf.subarray(0,this.length)),e,v.alloc(p)]),this.length+=e.length}writeString(e){this.maybeResize();let t=v.from(e,`utf8`);this.writeU32(t.length),this.writeBuffer(t)}writeFixedArray(e){this.writeBuffer(v.from(e))}writeArray(e,t){this.maybeResize(),this.writeU32(e.length);for(let n of e)this.maybeResize(),t(n)}toArray(){return this.buf.subarray(0,this.length)}};e.BinaryWriter=h;function g(e,t,n){let r=n.value;n.value=function(...e){try{return r.apply(this,e)}catch(e){if(e instanceof RangeError){let t=e.code;if([`ERR_BUFFER_OUT_OF_BOUNDS`,`ERR_OUT_OF_RANGE`].indexOf(t)>=0)throw new m(`Reached the end of buffer when deserializing`)}throw e}}}var ee=class{constructor(e){this.buf=e,this.offset=0}readU8(){let e=this.buf.readUInt8(this.offset);return this.offset+=1,e}readU16(){let e=this.buf.readUInt16LE(this.offset);return this.offset+=2,e}readU32(){let e=this.buf.readUInt32LE(this.offset);return this.offset+=4,e}readU64(){let e=this.readBuffer(8);return new s.default(e,`le`)}readU128(){let e=this.readBuffer(16);return new s.default(e,`le`)}readU256(){let e=this.readBuffer(32);return new s.default(e,`le`)}readU512(){let e=this.readBuffer(64);return new s.default(e,`le`)}readBuffer(e){if(this.offset+e>this.buf.length)throw new m(`Expected buffer length ${e} isn't within bounds`);let t=this.buf.slice(this.offset,this.offset+e);return this.offset+=e,t}readString(){let e=this.readU32(),t=this.readBuffer(e);try{return u.decode(t)}catch(e){throw new m(`Error decoding UTF-8 string: ${e}`)}}readFixedArray(e){return new Uint8Array(this.readBuffer(e))}readArray(e){let t=this.readU32(),n=[];for(let r=0;r<t;++r)n.push(e());return n}};i([g],ee.prototype,`readU8`,null),i([g],ee.prototype,`readU16`,null),i([g],ee.prototype,`readU32`,null),i([g],ee.prototype,`readU64`,null),i([g],ee.prototype,`readU128`,null),i([g],ee.prototype,`readU256`,null),i([g],ee.prototype,`readU512`,null),i([g],ee.prototype,`readString`,null),i([g],ee.prototype,`readFixedArray`,null),i([g],ee.prototype,`readArray`,null),e.BinaryReader=ee;function y(e){return e.charAt(0).toUpperCase()+e.slice(1)}function b(e,t,n,r,i){try{if(typeof r==`string`)i[`write${y(r)}`](n);else if(r instanceof Array){if(typeof r[0]==`number`){if(n.length!==r[0])throw new m(`Expecting byte array of length ${r[0]}, but got ${n.length} bytes`);i.writeFixedArray(n)}else if(r.length===2&&typeof r[1]==`number`){if(n.length!==r[1])throw new m(`Expecting byte array of length ${r[1]}, but got ${n.length} bytes`);for(let t=0;t<r[1];t++)b(e,null,n[t],r[0],i)}else i.writeArray(n,n=>{b(e,t,n,r[0],i)})}else if(r.kind!==void 0)switch(r.kind){case`option`:n==null?i.writeU8(0):(i.writeU8(1),b(e,t,n,r.type,i));break;case`map`:i.writeU32(n.size),n.forEach((n,a)=>{b(e,t,a,r.key,i),b(e,t,n,r.value,i)});break;default:throw new m(`FieldType ${r} unrecognized`)}else te(e,n,i)}catch(e){throw e instanceof m&&e.addToFieldPath(t),e}}function te(e,t,n){if(typeof t.borshSerialize==`function`){t.borshSerialize(n);return}let r=e.get(t.constructor);if(!r)throw new m(`Class ${t.constructor.name} is missing in schema`);if(r.kind===`struct`)r.fields.map(([r,i])=>{b(e,r,t[r],i,n)});else if(r.kind===`enum`){let i=t[r.field];for(let a=0;a<r.values.length;++a){let[o,s]=r.values[a];if(o===i){n.writeU8(a),b(e,o,t[o],s,n);break}}}else throw new m(`Unexpected schema kind: ${r.kind} for ${t.constructor.name}`)}function x(e,t,n=h){let r=new n;return te(e,t,r),r.toArray()}e.serialize=x;function S(e,t,n,r){try{if(typeof n==`string`)return r[`read${y(n)}`]();if(n instanceof Array){if(typeof n[0]==`number`)return r.readFixedArray(n[0]);if(typeof n[1]==`number`){let t=[];for(let i=0;i<n[1];i++)t.push(S(e,null,n[0],r));return t}return r.readArray(()=>S(e,t,n[0],r))}if(n.kind===`option`)return r.readU8()?S(e,t,n.type,r):void 0;if(n.kind===`map`){let i=new Map,a=r.readU32();for(let o=0;o<a;o++){let a=S(e,t,n.key,r),o=S(e,t,n.value,r);i.set(a,o)}return i}return w(e,n,r)}catch(e){throw e instanceof m&&e.addToFieldPath(t),e}}function w(e,t,n){if(typeof t.borshDeserialize==`function`)return t.borshDeserialize(n);let r=e.get(t);if(!r)throw new m(`Class ${t.name} is missing in schema`);if(r.kind===`struct`){let r={};for(let[i,a]of e.get(t).fields)r[i]=S(e,i,a,n);return new t(r)}if(r.kind===`enum`){let i=n.readU8();if(i>=r.values.length)throw new m(`Enum index: ${i} is out of range`);let[a,o]=r.values[i],s=S(e,a,o,n);return new t({[a]:s})}throw new m(`Unexpected schema kind: ${r.kind} for ${t.constructor.name}`)}function T(e,t,n,r=ee){let i=new r(n),a=w(e,t,i);if(i.offset<n.length)throw new m(`Unexpected ${n.length-i.offset} bytes after deserialized data`);return a}e.deserialize=T;function E(e,t,n,r=ee){return w(e,t,new r(n))}e.deserializeUnchecked=E})),Ne=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.s16=e.s8=e.nu64be=e.u48be=e.u40be=e.u32be=e.u24be=e.u16be=e.nu64=e.u48=e.u40=e.u32=e.u24=e.u16=e.u8=e.offset=e.greedy=e.Constant=e.UTF8=e.CString=e.Blob=e.Boolean=e.BitField=e.BitStructure=e.VariantLayout=e.Union=e.UnionLayoutDiscriminator=e.UnionDiscriminator=e.Structure=e.Sequence=e.DoubleBE=e.Double=e.FloatBE=e.Float=e.NearInt64BE=e.NearInt64=e.NearUInt64BE=e.NearUInt64=e.IntBE=e.Int=e.UIntBE=e.UInt=e.OffsetLayout=e.GreedyCount=e.ExternalLayout=e.bindConstructorLayout=e.nameWithProperty=e.Layout=e.uint8ArrayToBuffer=e.checkUint8Array=void 0,e.constant=e.utf8=e.cstr=e.blob=e.unionLayoutDiscriminator=e.union=e.seq=e.bits=e.struct=e.f64be=e.f64=e.f32be=e.f32=e.ns64be=e.s48be=e.s40be=e.s32be=e.s24be=e.s16be=e.ns64=e.s48=e.s40=e.s32=e.s24=void 0;var t=S();function n(e){if(!(e instanceof Uint8Array))throw TypeError(`b must be a Uint8Array`)}e.checkUint8Array=n;function r(e){return n(e),t.Buffer.from(e.buffer,e.byteOffset,e.length)}e.uint8ArrayToBuffer=r;var i=class{constructor(e,t){if(!Number.isInteger(e))throw TypeError(`span must be an integer`);this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw 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){}};e.Layout=i;function a(e,t){return t.property?e+`[`+t.property+`]`:e}e.nameWithProperty=a;function o(e,t){if(typeof e!=`function`)throw TypeError(`Class must be constructor`);if(Object.prototype.hasOwnProperty.call(e,`layout_`))throw Error(`Class is already bound to a layout`);if(!(t&&t instanceof i))throw TypeError(`layout must be a Layout`);if(Object.prototype.hasOwnProperty.call(t,`boundConstructor_`))throw Error(`layout is already bound to a constructor`);e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=(()=>new e),Object.defineProperty(e.prototype,"encode",{value(e,n){return t.encode(this,e,n)},writable:!0}),Object.defineProperty(e,"decode",{value(e,n){return t.decode(e,n)},writable:!0})}e.bindConstructorLayout=o;var s=class extends i{isCount(){throw Error(`ExternalLayout is abstract`)}};e.ExternalLayout=s;var c=class extends s{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw TypeError(`elementSpan must be a (positive) integer`);super(-1,t),this.elementSpan=e}isCount(){return!0}decode(e,t=0){n(e);let r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,n){return 0}};e.GreedyCount=c;var l=class extends s{constructor(e,t=0,n){if(!(e instanceof i))throw TypeError(`layout must be a Layout`);if(!Number.isInteger(t))throw TypeError(`offset must be integer or undefined`);super(e.span,n||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof u||this.layout instanceof d}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,n=0){return this.layout.encode(e,t,n+this.offset)}};e.OffsetLayout=l;var u=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readUIntLE(t,this.span)}encode(e,t,n=0){return r(t).writeUIntLE(e,n,this.span),this.span}};e.UInt=u;var d=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readUIntBE(t,this.span)}encode(e,t,n=0){return r(t).writeUIntBE(e,n,this.span),this.span}};e.UIntBE=d;var f=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readIntLE(t,this.span)}encode(e,t,n=0){return r(t).writeIntLE(e,n,this.span),this.span}};e.Int=f;var p=class extends i{constructor(e,t){if(super(e,t),6<this.span)throw RangeError(`span must not exceed 6 bytes`)}decode(e,t=0){return r(e).readIntBE(t,this.span)}encode(e,t,n=0){return r(t).writeIntBE(e,n,this.span),this.span}};e.IntBE=p;var m=2**32;function h(e){let t=Math.floor(e/m);return{hi32:t,lo32:e-t*m}}function g(e,t){return e*m+t}var _=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e),i=n.readUInt32LE(t);return g(n.readUInt32LE(t+4),i)}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32LE(i.lo32,n),a.writeUInt32LE(i.hi32,n+4),8}};e.NearUInt64=_;var v=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e);return g(n.readUInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32BE(i.hi32,n),a.writeUInt32BE(i.lo32,n+4),8}};e.NearUInt64BE=v;var ee=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e),i=n.readUInt32LE(t);return g(n.readInt32LE(t+4),i)}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeUInt32LE(i.lo32,n),a.writeInt32LE(i.hi32,n+4),8}};e.NearInt64=ee;var y=class extends i{constructor(e){super(8,e)}decode(e,t=0){let n=r(e);return g(n.readInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){let i=h(e),a=r(t);return a.writeInt32BE(i.hi32,n),a.writeUInt32BE(i.lo32,n+4),8}};e.NearInt64BE=y;var b=class extends i{constructor(e){super(4,e)}decode(e,t=0){return r(e).readFloatLE(t)}encode(e,t,n=0){return r(t).writeFloatLE(e,n),4}};e.Float=b;var te=class extends i{constructor(e){super(4,e)}decode(e,t=0){return r(e).readFloatBE(t)}encode(e,t,n=0){return r(t).writeFloatBE(e,n),4}};e.FloatBE=te;var x=class extends i{constructor(e){super(8,e)}decode(e,t=0){return r(e).readDoubleLE(t)}encode(e,t,n=0){return r(t).writeDoubleLE(e,n),8}};e.Double=x;var ne=class extends i{constructor(e){super(8,e)}decode(e,t=0){return r(e).readDoubleBE(t)}encode(e,t,n=0){return r(t).writeDoubleBE(e,n),8}};e.DoubleBE=ne;var C=class extends i{constructor(e,t,n){if(!(e instanceof i))throw TypeError(`elementLayout must be a Layout`);if(!(t instanceof s&&t.isCount()||Number.isInteger(t)&&0<=t))throw TypeError(`count must be non-negative integer or an unsigned integer ExternalLayout`);let r=-1;!(t instanceof s)&&0<e.span&&(r=t*e.span),super(r,n),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0,r=this.count;if(r instanceof s&&(r=r.decode(e,t)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let i=0;for(;i<r;)n+=this.elementLayout.getSpan(e,t+n),++i}return n}decode(e,t=0){let n=[],r=0,i=this.count;for(i instanceof s&&(i=i.decode(e,t));r<i;)n.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),r+=1;return n}encode(e,t,n=0){let r=this.elementLayout,i=e.reduce((e,i)=>e+r.encode(i,t,n+e),0);return this.count instanceof s&&this.count.encode(e.length,t,n),i}};e.Sequence=C;var w=class extends i{constructor(e,t,n){if(!(Array.isArray(e)&&e.reduce((e,t)=>e&&t instanceof i,!0)))throw TypeError(`fields must be array of Layout instances`);typeof t==`boolean`&&n===void 0&&(n=t,t=void 0);for(let t of e)if(0>t.span&&t.property===void 0)throw Error(`fields cannot contain unnamed variable-length layout`);let r=-1;try{r=e.reduce((e,t)=>e+t.getSpan(),0)}catch{}super(r,t),this.fields=e,this.decodePrefixes=!!n}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;try{n=this.fields.reduce((n,r)=>{let i=r.getSpan(e,t);return t+=i,n+i},0)}catch{throw RangeError(`indeterminate span`)}return n}decode(e,t=0){n(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,n=0){let r=n,i=0,a=0;for(let r of this.fields){let o=r.span;if(a=0<o?o:0,r.property!==void 0){let i=e[r.property];i!==void 0&&(a=r.encode(i,t,n),0>o&&(o=r.getSpan(t,n)))}i=n,n+=o}return i+a-r}fromArray(e){let t=this.makeDestinationObject();for(let n of this.fields)n.property!==void 0&&0<e.length&&(t[n.property]=e.shift());return t}layoutFor(e){if(typeof e!=`string`)throw TypeError(`property must be string`);for(let t of this.fields)if(t.property===e)return t}offsetOf(e){if(typeof e!=`string`)throw TypeError(`property must be string`);let t=0;for(let n of this.fields){if(n.property===e)return t;0>n.span?t=-1:0<=t&&(t+=n.span)}}};e.Structure=w;var T=class{constructor(e){this.property=e}decode(e,t){throw Error(`UnionDiscriminator is abstract`)}encode(e,t,n){throw Error(`UnionDiscriminator is abstract`)}};e.UnionDiscriminator=T;var E=class extends T{constructor(e,t){if(!(e instanceof s&&e.isCount()))throw 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,n){return this.layout.encode(e,t,n)}};e.UnionLayoutDiscriminator=E;var D=class extends i{constructor(e,t,n){let r;if(e instanceof u||e instanceof d)r=new E(new l(e));else if(e instanceof s&&e.isCount())r=new E(e);else if(e instanceof T)r=e;else throw TypeError(`discr must be a UnionDiscriminator or an unsigned integer layout`);if(t===void 0&&(t=null),!(t===null||t instanceof i))throw TypeError(`defaultLayout must be null or a Layout`);if(t!==null){if(0>t.span)throw Error(`defaultLayout must have constant span`);t.property===void 0&&(t=t.replicate(`content`))}let a=-1;t&&(a=t.span,0<=a&&(e instanceof u||e instanceof d)&&(a+=r.layout.span)),super(a,n),this.discriminator=r,this.usesPrefixDiscriminator=e instanceof u||e instanceof d,this.defaultLayout=t,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return o(e)},this.configGetSourceVariant=function(e){o=e.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;let n=this.getVariant(e,t);if(!n)throw Error(`unable to determine span for unrecognized variant`);return n.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 n=this.registry[t];if(n.property&&Object.prototype.hasOwnProperty.call(e,n.property))return n}throw Error(`unable to infer src variant`)}decode(e,t=0){let n,r=this.discriminator,i=r.decode(e,t),a=this.registry[i];if(a===void 0){let a=this.defaultLayout,o=0;this.usesPrefixDiscriminator&&(o=r.layout.span),n=this.makeDestinationObject(),n[r.property]=i,n[a.property]=a.decode(e,t+o)}else n=a.decode(e,t);return n}encode(e,t,n=0){let r=this.getSourceVariant(e);if(r===void 0){let r=this.discriminator,i=this.defaultLayout,a=0;return this.usesPrefixDiscriminator&&(a=r.layout.span),r.encode(e[r.property],t,n),a+i.encode(e[i.property],t,n+a)}return r.encode(e,t,n)}addVariant(e,t,n){let r=new re(this,e,t,n);return this.registry[e]=r,r}getVariant(e,t=0){let n;return n=e instanceof Uint8Array?this.discriminator.decode(e,t):e,this.registry[n]}};e.Union=D;var re=class extends i{constructor(e,t,n,r){if(!(e instanceof D))throw TypeError(`union must be a Union`);if(!Number.isInteger(t)||0>t)throw TypeError(`variant must be a (non-negative) integer`);if(typeof n==`string`&&r===void 0&&(r=n,n=null),n){if(!(n instanceof i))throw TypeError(`layout must be a Layout`);if(e.defaultLayout!==null&&0<=n.span&&n.span>e.defaultLayout.span)throw Error(`variant span exceeds span of containing union`);if(typeof r!=`string`)throw TypeError(`variant must have a String property`)}let a=e.span;0>e.span&&(a=n?n.span:0,0<=a&&e.usesPrefixDiscriminator&&(a+=e.discriminator.layout.span)),super(a,r),this.union=e,this.variant=t,this.layout=n||null}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span);let r=0;return this.layout&&(r=this.layout.getSpan(e,t+n)),n+r}decode(e,t=0){let n=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw Error(`variant mismatch`);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout?n[this.property]=this.layout.decode(e,t+r):this.property?n[this.property]=!0:this.union.usesPrefixDiscriminator&&(n[this.union.discriminator.property]=this.variant),n}encode(e,t,n=0){let r=0;if(this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw TypeError(`variant lacks property `+this.property);this.union.discriminator.encode(this.variant,t,n);let i=r;if(this.layout&&(this.layout.encode(e[this.property],t,n+r),i+=this.layout.getSpan(t,n+r),0<=this.union.span&&i>this.union.span))throw Error(`encoded variant overruns containing union`);return i}fromArray(e){if(this.layout)return this.layout.fromArray(e)}};e.VariantLayout=re;function O(e){return 0>e&&(e+=4294967296),e}var k=class extends i{constructor(e,t,n){if(!(e instanceof u||e instanceof d))throw TypeError(`word must be a UInt or UIntBE layout`);if(typeof t==`string`&&n===void 0&&(n=t,t=!1),4<e.span)throw RangeError(`word cannot exceed 32 bits`);super(e.span,n),this.word=e,this.msb=!!t,this.fields=[];let r=0;this._packedSetValue=function(e){return r=O(e),this},this._packedGetValue=function(){return r}}decode(e,t=0){let n=this.makeDestinationObject(),r=this.word.decode(e,t);this._packedSetValue(r);for(let t of this.fields)t.property!==void 0&&(n[t.property]=t.decode(e));return n}encode(e,t,n=0){let r=this.word.decode(t,n);this._packedSetValue(r);for(let t of this.fields)if(t.property!==void 0){let n=e[t.property];n!==void 0&&t.encode(n)}return this.word.encode(this._packedGetValue(),t,n)}addField(e,t){let n=new ie(this,e,t);return this.fields.push(n),n}addBoolean(e){let t=new ae(this,e);return this.fields.push(t),t}fieldFor(e){if(typeof e!=`string`)throw TypeError(`property must be string`);for(let t of this.fields)if(t.property===e)return t}};e.BitStructure=k;var ie=class{constructor(e,t,n){if(!(e instanceof k))throw TypeError(`container must be a BitStructure`);if(!Number.isInteger(t)||0>=t)throw TypeError(`bits must be positive integer`);let r=8*e.span,i=e.fields.reduce((e,t)=>e+t.bits,0);if(t+i>r)throw Error(`bits too long for span remainder (`+(r-i)+` of `+r+` 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=r-i-t),this.wordMask=O(this.valueMask<<this.start),this.property=n}decode(e,t){return O(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(typeof e!=`number`||!Number.isInteger(e)||e!==O(e&this.valueMask))throw TypeError(a(`BitField.encode`,this)+` value must be integer not exceeding `+this.valueMask);let t=this.container._packedGetValue(),n=O(e<<this.start);this.container._packedSetValue(O(t&~this.wordMask)|n)}};e.BitField=ie;var ae=class extends ie{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)}};e.Boolean=ae;var oe=class extends i{constructor(e,t){if(!(e instanceof s&&e.isCount()||Number.isInteger(e)&&0<=e))throw TypeError(`length must be positive integer or an unsigned integer ExternalLayout`);let n=-1;e instanceof s||(n=e),super(n,t),this.length=e}getSpan(e,t){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),n}decode(e,t=0){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),r(e).slice(t,t+n)}encode(e,t,n){let i=this.length;if(this.length instanceof s&&(i=e.length),!(e instanceof Uint8Array&&i===e.length))throw TypeError(a(`Blob.encode`,this)+` requires (length `+i+`) Uint8Array as src`);if(n+i>t.length)throw RangeError(`encoding overruns Uint8Array`);let o=r(e);return r(t).write(o.toString(`hex`),n,i,`hex`),this.length instanceof s&&this.length.encode(i,t,n),i}};e.Blob=oe;var se=class extends i{constructor(e){super(-1,e)}getSpan(e,t=0){n(e);let r=t;for(;r<e.length&&e[r]!==0;)r+=1;return 1+r-t}decode(e,t=0){let n=this.getSpan(e,t);return r(e).slice(t,t+n-1).toString(`utf-8`)}encode(e,n,i=0){typeof e!=`string`&&(e=String(e));let a=t.Buffer.from(e,`utf8`),o=a.length;if(i+o>n.length)throw RangeError(`encoding overruns Buffer`);let s=r(n);return a.copy(s,i),s[i+o]=0,o+1}};e.CString=se;var A=class extends i{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 TypeError(`maxSpan must be an integer`);super(-1,t),this.maxSpan=e}getSpan(e,t=0){return n(e),e.length-t}decode(e,t=0){let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw RangeError(`text length exceeds maxSpan`);return r(e).slice(t,t+n).toString(`utf-8`)}encode(e,n,i=0){typeof e!=`string`&&(e=String(e));let a=t.Buffer.from(e,`utf8`),o=a.length;if(0<=this.maxSpan&&this.maxSpan<o)throw RangeError(`text length exceeds maxSpan`);if(i+o>n.length)throw RangeError(`encoding overruns Buffer`);return a.copy(r(n),i),o}};e.UTF8=A;var j=class extends i{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,n){return 0}};e.Constant=j,e.greedy=((e,t)=>new c(e,t)),e.offset=((e,t,n)=>new l(e,t,n)),e.u8=(e=>new u(1,e)),e.u16=(e=>new u(2,e)),e.u24=(e=>new u(3,e)),e.u32=(e=>new u(4,e)),e.u40=(e=>new u(5,e)),e.u48=(e=>new u(6,e)),e.nu64=(e=>new _(e)),e.u16be=(e=>new d(2,e)),e.u24be=(e=>new d(3,e)),e.u32be=(e=>new d(4,e)),e.u40be=(e=>new d(5,e)),e.u48be=(e=>new d(6,e)),e.nu64be=(e=>new v(e)),e.s8=(e=>new f(1,e)),e.s16=(e=>new f(2,e)),e.s24=(e=>new f(3,e)),e.s32=(e=>new f(4,e)),e.s40=(e=>new f(5,e)),e.s48=(e=>new f(6,e)),e.ns64=(e=>new ee(e)),e.s16be=(e=>new p(2,e)),e.s24be=(e=>new p(3,e)),e.s32be=(e=>new p(4,e)),e.s40be=(e=>new p(5,e)),e.s48be=(e=>new p(6,e)),e.ns64be=(e=>new y(e)),e.f32=(e=>new b(e)),e.f32be=(e=>new te(e)),e.f64=(e=>new x(e)),e.f64be=(e=>new ne(e)),e.struct=((e,t,n)=>new w(e,t,n)),e.bits=((e,t,n)=>new k(e,t,n)),e.seq=((e,t,n)=>new C(e,t,n)),e.union=((e,t,n)=>new D(e,t,n)),e.unionLayoutDiscriminator=((e,t)=>new E(e,t)),e.blob=((e,t)=>new oe(e,t)),e.cstr=(e=>new se(e)),e.utf8=((e,t)=>new A(e,t)),e.constant=((e,t)=>new j(e,t))}));function Pe(e){return Array.isArray(e)?`%5B`+e.map(Pe).join(`%2C%20`)+`%5D`:typeof e==`bigint`?`${e}n`:encodeURIComponent(String(e!=null&&Object.getPrototypeOf(e)===null?{...e}:e))}function Fe([e,t]){return`${e}=${Pe(t)}`}function Ie(e){let t=Object.entries(e).map(Fe).join(`&`);return btoa(t)}function Le(e,t={}){{let n=`Solana error #${e}; Decode this error by running \`npx @solana/errors decode -- ${e}`;return Object.keys(t).length&&(n+=` '${Ie(t)}'`),`${n}\``}}var Re,ze,Be,Ve,He,Ue,We,Ge=e((()=>{Re=8078e3,ze=8078001,Be=8078004,Ve=8078005,He=8078006,Ue=8078011,We=class extends Error{cause=this.cause;context;constructor(...[e,t]){let n,r;t&&Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([t,i])=>{t===`cause`?r={cause:i.value}:(n===void 0&&(n={__code:e}),Object.defineProperty(n,t,i))});let i=Le(e,n);super(i,r),this.context=Object.freeze(n===void 0?{__code:e}:n),this.name=`SolanaError`}}}));function Ke(e,t){return`fixedSize`in t?t.fixedSize:t.getSizeFromValue(e)}function qe(e){return Object.freeze({...e,encode:t=>{let n=new Uint8Array(Ke(t,e));return e.write(t,n,0),n}})}function Je(e){return Object.freeze({...e,decode:(t,n=0)=>e.read(t,n)[0]})}function Ye(e){return`fixedSize`in e&&typeof e.fixedSize==`number`}function Xe(e,t){if(Ye(e)!==Ye(t))throw new We(Be);if(Ye(e)&&Ye(t)&&e.fixedSize!==t.fixedSize)throw new We(Ve,{decoderFixedSize:t.fixedSize,encoderFixedSize:e.fixedSize});if(!Ye(e)&&!Ye(t)&&e.maxSize!==t.maxSize)throw new We(He,{decoderMaxSize:t.maxSize,encoderMaxSize:e.maxSize});return{...t,...e,decode:t.decode,encode:e.encode,read:t.read,write:e.write}}function Ze(e,t,n=0){if(t.length-n<=0)throw new We(Re,{codecDescription:e})}function Qe(e,t,n,r=0){let i=n.length-r;if(i<t)throw new We(ze,{bytesLength:i,codecDescription:e,expected:t})}function $e(e,t,n){let r=e.byteOffset+(t??0),i=n??e.byteLength,a;return typeof SharedArrayBuffer>`u`?a=e.buffer:e.buffer instanceof SharedArrayBuffer?(a=new ArrayBuffer(e.length),new Uint8Array(a).set(new Uint8Array(e))):a=e.buffer,(r===0||r===-e.byteLength)&&i===e.byteLength?a:a.slice(r,r+i)}var et=e((()=>{Ge()}));function tt(e,t,n,r){if(r<t||r>n)throw new We(Ue,{codecDescription:e,max:n,min:t,value:r})}function nt(e){return e?.endian!==1}function rt(e){return qe({fixedSize:e.size,write(t,n,r){e.range&&tt(e.name,e.range[0],e.range[1],t);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),t,nt(e.config)),n.set(new Uint8Array(i),r),r+e.size}})}function it(e){return Je({fixedSize:e.size,read(t,n=0){Ze(e.name,t,n),Qe(e.name,e.size,t,n);let r=new DataView($e(t,n,e.size));return[e.get(r,nt(e.config)),n+e.size]}})}var at,ot,st,ct=e((()=>{Ge(),et(),at=(e={})=>rt({config:e,name:`u64`,range:[0n,BigInt(`0xffffffffffffffff`)],set:(e,t,n)=>e.setBigUint64(0,BigInt(t),n),size:8}),ot=(e={})=>it({config:e,get:(e,t)=>e.getBigUint64(0,t),name:`u64`,size:8}),st=(e={})=>Xe(at(e),ot(e))}));function lt(e){return ut(e)&&typeof e[Symbol.iterator]==`function`}function ut(e){return typeof e==`object`&&!!e}function dt(e){return ut(e)&&!Array.isArray(e)}function ft(e){return typeof e==`symbol`?e.toString():typeof e==`string`?JSON.stringify(e):`${e}`}function pt(e){let{done:t,value:n}=e.next();return t?void 0:n}function mt(e,t,n,r){if(e===!0)return;e===!1?e={}:typeof e==`string`&&(e={message:e});let{path:i,branch:a}=t,{type:o}=n,{refinement:s,message:c=`Expected a value of type \`${o}\`${s?` with refinement \`${s}\``:``}, but received: \`${ft(r)}\``}=e;return{value:r,type:o,refinement:s,key:i[i.length-1],path:i,branch:a,...e,message:c}}function*ht(e,t,n,r){lt(e)||(e=[e]);for(let i of e){let e=mt(i,t,n,r);e&&(yield e)}}function*gt(e,t,n={}){let{path:r=[],branch:i=[e],coerce:a=!1,mask:o=!1}=n,s={path:r,branch:i,mask:o};a&&(e=t.coercer(e,s));let c=`valid`;for(let r of t.validator(e,s))r.explanation=n.message,c=`not_valid`,yield[r,void 0];for(let[l,u,d]of t.entries(e,s)){let t=gt(u,d,{path:l===void 0?r:[...r,l],branch:l===void 0?i:[...i,u],coerce:a,mask:o,message:n.message});for(let n of t)n[0]?(c=n[0].refinement==null?`not_valid`:`not_refined`,yield[n[0],void 0]):a&&(u=n[1],l===void 0?e=u:e instanceof Map?e.set(l,u):e instanceof Set?e.add(u):ut(e)&&(u!==void 0||l in e)&&(e[l]=u))}if(c!==`not_valid`)for(let r of t.refiner(e,s))r.explanation=n.message,c=`not_refined`,yield[r,void 0];c===`valid`&&(yield[void 0,e])}function _t(e,t,n){let r=bt(e,t,{message:n});if(r[0])throw r[0]}function I(e,t,n){let r=bt(e,t,{coerce:!0,message:n});if(r[0])throw r[0];return r[1]}function vt(e,t,n){let r=bt(e,t,{coerce:!0,mask:!0,message:n});if(r[0])throw r[0];return r[1]}function yt(e,t){return!bt(e,t)[0]}function bt(e,t,n={}){let r=gt(e,t,n),i=pt(r);return i[0]?[new Mt(i[0],function*(){for(let e of r)e[0]&&(yield e[0])}),void 0]:[void 0,i[1]]}function xt(e,t){return new Nt({type:e,schema:null,validator:t})}function St(){return xt(`any`,()=>!0)}function L(e){return new Nt({type:`array`,schema:e,*entries(t){if(e&&Array.isArray(t))for(let[n,r]of t.entries())yield[n,r,e]},coercer(e){return Array.isArray(e)?e.slice():e},validator(e){return Array.isArray(e)||`Expected an array value, but received: ${ft(e)}`}})}function Ct(){return xt(`boolean`,e=>typeof e==`boolean`)}function wt(e){return xt(`instance`,t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${ft(t)}`)}function Tt(e){let t=ft(e),n=typeof e;return new Nt({type:`literal`,schema:n===`string`||n===`number`||n===`boolean`?e:null,validator(n){return n===e||`Expected the literal \`${t}\`, but received: ${ft(n)}`}})}function Et(){return xt(`never`,()=>!1)}function R(e){return new Nt({...e,validator:(t,n)=>t===null||e.validator(t,n),refiner:(t,n)=>t===null||e.refiner(t,n)})}function z(){return xt(`number`,e=>typeof e==`number`&&!isNaN(e)||`Expected a number, but received: ${ft(e)}`)}function B(e){return new Nt({...e,validator:(t,n)=>t===void 0||e.validator(t,n),refiner:(t,n)=>t===void 0||e.refiner(t,n)})}function Dt(e,t){return new Nt({type:`record`,schema:null,*entries(n){if(ut(n))for(let r in n){let i=n[r];yield[r,r,e],yield[r,i,t]}},validator(e){return dt(e)||`Expected an object, but received: ${ft(e)}`},coercer(e){return dt(e)?{...e}:e}})}function V(){return xt(`string`,e=>typeof e==`string`||`Expected a string, but received: ${ft(e)}`)}function Ot(e){let t=Et();return new Nt({type:`tuple`,schema:null,*entries(n){if(Array.isArray(n)){let r=Math.max(e.length,n.length);for(let i=0;i<r;i++)yield[i,n[i],e[i]||t]}},validator(e){return Array.isArray(e)||`Expected an array, but received: ${ft(e)}`},coercer(e){return Array.isArray(e)?e.slice():e}})}function H(e){let t=Object.keys(e);return new Nt({type:`type`,schema:e,*entries(n){if(ut(n))for(let r of t)yield[r,n[r],e[r]]},validator(e){return dt(e)||`Expected an object, but received: ${ft(e)}`},coercer(e){return dt(e)?{...e}:e}})}function kt(e){let t=e.map(e=>e.type).join(` | `);return new Nt({type:`union`,schema:null,coercer(t,n){for(let r of e){let[e,i]=r.validate(t,{coerce:!0,mask:n.mask});if(!e)return i}return t},validator(n,r){let i=[];for(let t of e){let[...e]=gt(n,t,r),[a]=e;if(a[0])for(let[t]of e)t&&i.push(t);else return[]}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${ft(n)}`,...i]}})}function At(){return xt(`unknown`,()=>!0)}function jt(e,t,n){return new Nt({...e,coercer:(r,i)=>yt(r,t)?e.coercer(n(r,i),i):e.coercer(r,i)})}var Mt,Nt,Pt=e((()=>{Mt=class extends TypeError{constructor(e,t){let n,{message:r,explanation:i,...a}=e,{path:o}=e,s=o.length===0?r:`At path: ${o.join(`.`)} -- ${r}`;super(i??s),i!=null&&(this.cause=s),Object.assign(this,a),this.name=this.constructor.name,this.failures=()=>n??=[e,...t()]}},Nt=class{constructor(e){let{type:t,schema:n,validator:r,refiner:i,coercer:a=e=>e,entries:o=function*(){}}=e;this.type=t,this.schema=n,this.entries=o,this.coercer=a,this.validator=r?(e,t)=>ht(r(e,t),t,this,e):()=>[],this.refiner=i?(e,t)=>ht(i(e,t),t,this,e):()=>[]}assert(e,t){return _t(e,this,t)}create(e,t){return I(e,this,t)}is(e){return yt(e,this)}mask(e,t){return vt(e,this,t)}validate(e,t={}){return bt(e,this,t)}}}));function Ft(){if(!It&&(It=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<`u`&&typeof msCrypto.getRandomValues==`function`&&msCrypto.getRandomValues.bind(msCrypto),!It))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return It(Lt)}var It,Lt,Rt=e((()=>{Lt=new Uint8Array(16)})),zt,Bt=e((()=>{zt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i}));function Vt(e){return typeof e==`string`&&zt.test(e)}var Ht=e((()=>{Bt()}));function Ut(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(Wt[e[t+0]]+Wt[e[t+1]]+Wt[e[t+2]]+Wt[e[t+3]]+`-`+Wt[e[t+4]]+Wt[e[t+5]]+`-`+Wt[e[t+6]]+Wt[e[t+7]]+`-`+Wt[e[t+8]]+Wt[e[t+9]]+`-`+Wt[e[t+10]]+Wt[e[t+11]]+Wt[e[t+12]]+Wt[e[t+13]]+Wt[e[t+14]]+Wt[e[t+15]]).toLowerCase();if(!Vt(n))throw TypeError(`Stringified UUID is invalid`);return n}var Wt,Gt,Kt=e((()=>{for(Ht(),Wt=[],Gt=0;Gt<256;++Gt)Wt.push((Gt+256).toString(16).substr(1))}));function qt(e,t,n){var r=t&&n||0,i=t||Array(16);e||={};var a=e.node||Jt,o=e.clockseq===void 0?Yt:e.clockseq;if(a==null||o==null){var s=e.random||(e.rng||Ft)();a??=Jt=[s[0]|1,s[1],s[2],s[3],s[4],s[5]],o??=Yt=(s[6]<<8|s[7])&16383}var c=e.msecs===void 0?Date.now():e.msecs,l=e.nsecs===void 0?Zt+1:e.nsecs,u=c-Xt+(l-Zt)/1e4;if(u<0&&e.clockseq===void 0&&(o=o+1&16383),(u<0||c>Xt)&&e.nsecs===void 0&&(l=0),l>=1e4)throw Error(`uuid.v1(): Can't create more than 10M uuids/sec`);Xt=c,Zt=l,Yt=o,c+=0xb1d069b5400;var d=((c&268435455)*1e4+l)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=d&255;var f=c/4294967296*1e4&268435455;i[r++]=f>>>8&255,i[r++]=f&255,i[r++]=f>>>24&15|16,i[r++]=f>>>16&255,i[r++]=o>>>8|128,i[r++]=o&255;for(var p=0;p<6;++p)i[r+p]=a[p];return t||Ut(i)}var Jt,Yt,Xt,Zt,Qt=e((()=>{Rt(),Kt(),Xt=0,Zt=0}));function $t(e){if(!Vt(e))throw TypeError(`Invalid UUID`);var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=t&255,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=t&255,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=t&255,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=t&255,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=t&255,n}var en=e((()=>{Ht()}));function tn(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}function nn(e,t,n){function r(e,r,i,a){if(typeof e==`string`&&(e=tn(e)),typeof r==`string`&&(r=$t(r)),r.length!==16)throw TypeError(`Namespace must be array-like (16 iterable integer values, 0-255)`);var o=new Uint8Array(16+e.length);if(o.set(r),o.set(e,r.length),o=n(o),o[6]=o[6]&15|t,o[8]=o[8]&63|128,i){a||=0;for(var s=0;s<16;++s)i[a+s]=o[s];return i}return Ut(o)}try{r.name=e}catch{}return r.DNS=rn,r.URL=an,r}var rn,an,on=e((()=>{Kt(),en(),rn=`6ba7b810-9dad-11d1-80b4-00c04fd430c8`,an=`6ba7b811-9dad-11d1-80b4-00c04fd430c8`}));function sn(e){if(typeof e==`string`){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return cn(un(dn(e),e.length*8))}function cn(e){for(var t=[],n=e.length*32,r=`0123456789abcdef`,i=0;i<n;i+=8){var a=e[i>>5]>>>i%32&255,o=parseInt(r.charAt(a>>>4&15)+r.charAt(a&15),16);t.push(o)}return t}function ln(e){return(e+64>>>9<<4)+14+1}function un(e,t){e[t>>5]|=128<<t%32,e[ln(t)-1]=t;for(var n=1732584193,r=-271733879,i=-1732584194,a=271733878,o=0;o<e.length;o+=16){var s=n,c=r,l=i,u=a;n=hn(n,r,i,a,e[o],7,-680876936),a=hn(a,n,r,i,e[o+1],12,-389564586),i=hn(i,a,n,r,e[o+2],17,606105819),r=hn(r,i,a,n,e[o+3],22,-1044525330),n=hn(n,r,i,a,e[o+4],7,-176418897),a=hn(a,n,r,i,e[o+5],12,1200080426),i=hn(i,a,n,r,e[o+6],17,-1473231341),r=hn(r,i,a,n,e[o+7],22,-45705983),n=hn(n,r,i,a,e[o+8],7,1770035416),a=hn(a,n,r,i,e[o+9],12,-1958414417),i=hn(i,a,n,r,e[o+10],17,-42063),r=hn(r,i,a,n,e[o+11],22,-1990404162),n=hn(n,r,i,a,e[o+12],7,1804603682),a=hn(a,n,r,i,e[o+13],12,-40341101),i=hn(i,a,n,r,e[o+14],17,-1502002290),r=hn(r,i,a,n,e[o+15],22,1236535329),n=gn(n,r,i,a,e[o+1],5,-165796510),a=gn(a,n,r,i,e[o+6],9,-1069501632),i=gn(i,a,n,r,e[o+11],14,643717713),r=gn(r,i,a,n,e[o],20,-373897302),n=gn(n,r,i,a,e[o+5],5,-701558691),a=gn(a,n,r,i,e[o+10],9,38016083),i=gn(i,a,n,r,e[o+15],14,-660478335),r=gn(r,i,a,n,e[o+4],20,-405537848),n=gn(n,r,i,a,e[o+9],5,568446438),a=gn(a,n,r,i,e[o+14],9,-1019803690),i=gn(i,a,n,r,e[o+3],14,-187363961),r=gn(r,i,a,n,e[o+8],20,1163531501),n=gn(n,r,i,a,e[o+13],5,-1444681467),a=gn(a,n,r,i,e[o+2],9,-51403784),i=gn(i,a,n,r,e[o+7],14,1735328473),r=gn(r,i,a,n,e[o+12],20,-1926607734),n=_n(n,r,i,a,e[o+5],4,-378558),a=_n(a,n,r,i,e[o+8],11,-2022574463),i=_n(i,a,n,r,e[o+11],16,1839030562),r=_n(r,i,a,n,e[o+14],23,-35309556),n=_n(n,r,i,a,e[o+1],4,-1530992060),a=_n(a,n,r,i,e[o+4],11,1272893353),i=_n(i,a,n,r,e[o+7],16,-155497632),r=_n(r,i,a,n,e[o+10],23,-1094730640),n=_n(n,r,i,a,e[o+13],4,681279174),a=_n(a,n,r,i,e[o],11,-358537222),i=_n(i,a,n,r,e[o+3],16,-722521979),r=_n(r,i,a,n,e[o+6],23,76029189),n=_n(n,r,i,a,e[o+9],4,-640364487),a=_n(a,n,r,i,e[o+12],11,-421815835),i=_n(i,a,n,r,e[o+15],16,530742520),r=_n(r,i,a,n,e[o+2],23,-995338651),n=vn(n,r,i,a,e[o],6,-198630844),a=vn(a,n,r,i,e[o+7],10,1126891415),i=vn(i,a,n,r,e[o+14],15,-1416354905),r=vn(r,i,a,n,e[o+5],21,-57434055),n=vn(n,r,i,a,e[o+12],6,1700485571),a=vn(a,n,r,i,e[o+3],10,-1894986606),i=vn(i,a,n,r,e[o+10],15,-1051523),r=vn(r,i,a,n,e[o+1],21,-2054922799),n=vn(n,r,i,a,e[o+8],6,1873313359),a=vn(a,n,r,i,e[o+15],10,-30611744),i=vn(i,a,n,r,e[o+6],15,-1560198380),r=vn(r,i,a,n,e[o+13],21,1309151649),n=vn(n,r,i,a,e[o+4],6,-145523070),a=vn(a,n,r,i,e[o+11],10,-1120210379),i=vn(i,a,n,r,e[o+2],15,718787259),r=vn(r,i,a,n,e[o+9],21,-343485551),n=fn(n,s),r=fn(r,c),i=fn(i,l),a=fn(a,u)}return[n,r,i,a]}function dn(e){if(e.length===0)return[];for(var t=e.length*8,n=new Uint32Array(ln(t)),r=0;r<t;r+=8)n[r>>5]|=(e[r/8]&255)<<r%32;return n}function fn(e,t){var n=(e&65535)+(t&65535);return(e>>16)+(t>>16)+(n>>16)<<16|n&65535}function pn(e,t){return e<<t|e>>>32-t}function mn(e,t,n,r,i,a){return fn(pn(fn(fn(t,e),fn(r,a)),i),n)}function hn(e,t,n,r,i,a,o){return mn(t&n|~t&r,e,t,i,a,o)}function gn(e,t,n,r,i,a,o){return mn(t&r|n&~r,e,t,i,a,o)}function _n(e,t,n,r,i,a,o){return mn(t^n^r,e,t,i,a,o)}function vn(e,t,n,r,i,a,o){return mn(n^(t|~r),e,t,i,a,o)}var yn=e((()=>{})),bn,xn=e((()=>{on(),yn(),bn=nn(`v3`,48,sn)}));function Sn(e,t,n){e||={};var r=e.random||(e.rng||Ft)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return Ut(r)}var Cn=e((()=>{Rt(),Kt()}));function wn(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function Tn(e,t){return e<<t|e>>>32-t}function En(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e==`string`){var r=unescape(encodeURIComponent(e));e=[];for(var i=0;i<r.length;++i)e.push(r.charCodeAt(i))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var a=e.length/4+2,o=Math.ceil(a/16),s=Array(o),c=0;c<o;++c){for(var l=new Uint32Array(16),u=0;u<16;++u)l[u]=e[c*64+u*4]<<24|e[c*64+u*4+1]<<16|e[c*64+u*4+2]<<8|e[c*64+u*4+3];s[c]=l}s[o-1][14]=(e.length-1)*8/2**32,s[o-1][14]=Math.floor(s[o-1][14]),s[o-1][15]=(e.length-1)*8&4294967295;for(var d=0;d<o;++d){for(var f=new Uint32Array(80),p=0;p<16;++p)f[p]=s[d][p];for(var m=16;m<80;++m)f[m]=Tn(f[m-3]^f[m-8]^f[m-14]^f[m-16],1);for(var h=n[0],g=n[1],_=n[2],v=n[3],ee=n[4],y=0;y<80;++y){var b=Math.floor(y/20),te=Tn(h,5)+wn(b,g,_,v)+ee+t[b]+f[y]>>>0;ee=v,v=_,_=Tn(g,30)>>>0,g=h,h=te}n[0]=n[0]+h>>>0,n[1]=n[1]+g>>>0,n[2]=n[2]+_>>>0,n[3]=n[3]+v>>>0,n[4]=n[4]+ee>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,n[0]&255,n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,n[1]&255,n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,n[2]&255,n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,n[3]&255,n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,n[4]&255]}var Dn=e((()=>{})),On,kn=e((()=>{on(),Dn(),On=nn(`v5`,80,En)})),An,jn=e((()=>{An=`00000000-0000-0000-0000-000000000000`}));function Mn(e){if(!Vt(e))throw TypeError(`Invalid UUID`);return parseInt(e.substr(14,1),16)}var Nn=e((()=>{Ht()})),Pn=n({NIL:()=>An,parse:()=>$t,stringify:()=>Ut,v1:()=>qt,v3:()=>bn,v4:()=>Sn,v5:()=>On,validate:()=>Vt,version:()=>Mn}),Fn=e((()=>{Qt(),xn(),Cn(),kn(),jn(),Nn(),Ht(),Kt(),en()})),In=i(((e,n)=>{var r=(Fn(),t(Pn)).v4;n.exports=function(e,t,n,i){if(typeof e!=`string`)throw TypeError(e+` must be a string`);i||={};let a=typeof i.version==`number`?i.version:2;if(a!==1&&a!==2)throw TypeError(a+` must be 1 or 2`);let o={method:e};if(a===2&&(o.jsonrpc=`2.0`),t){if(typeof t!=`object`&&!Array.isArray(t))throw TypeError(t+` must be an object, array or omitted`);o.params=t}return n===void 0?o.id=(typeof i.generator==`function`?i.generator:function(){return r()})(o,i):a===2&&n===null?i.notificationIdNull&&(o.id=null):o.id=n,o}})),Ln=i(((e,n)=>{var r=(Fn(),t(Pn)).v4,i=In(),a=function(e,t){if(!(this instanceof a))return new a(e,t);t||={},this.options={reviver:t.reviver===void 0?null:t.reviver,replacer:t.replacer===void 0?null:t.replacer,generator:t.generator===void 0?function(){return r()}:t.generator,version:t.version===void 0?2:t.version,notificationIdNull:typeof t.notificationIdNull==`boolean`&&t.notificationIdNull},this.callServer=e};n.exports=a,a.prototype.request=function(e,t,n,r){let a=this,o=null,s=Array.isArray(e)&&typeof t==`function`;if(this.options.version===1&&s)throw TypeError(`JSON-RPC 1.0 does not support batching`);if(s||!s&&e&&typeof e==`object`&&typeof t==`function`)r=t,o=e;else{typeof n==`function`&&(r=n,n=void 0);let a=typeof r==`function`;try{o=i(e,t,n,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(e){if(a){r(e);return}throw e}if(!a)return o}let c;try{c=JSON.stringify(o,this.options.replacer)}catch(e){r(e);return}return this.callServer(c,function(e,t){a._parseResponse(e,t,r)}),o},a.prototype._parseResponse=function(e,t,n){if(e){n(e);return}if(!t){n();return}let r;try{r=JSON.parse(t,this.options.reviver)}catch(e){n(e);return}if(n.length===3){if(Array.isArray(r)){let e=function(e){return e.error!==void 0};n(null,r.filter(e),r.filter(function(t){return!e(t)}));return}n(null,r.error,r.result);return}n(null,r)}}));function Rn(e,t){return new zn(e,t)}var zn,Bn,Vn,Hn=e((()=>{_(),y(),zn=class extends ee.default{socket;constructor(e,t,n){super(),this.socket=new window.WebSocket(e,n),this.socket.onopen=()=>this.emit(`open`),this.socket.onmessage=e=>this.emit(`message`,e.data),this.socket.onerror=e=>this.emit(`error`,e),this.socket.onclose=e=>{this.emit(`close`,e.code,e.reason)}}send(e,t,n){let r=n||t;try{this.socket.send(e),r()}catch(e){r(e)}}close(e,t){this.socket.close(e,t)}addEventListener(e,t,n){this.socket.addEventListener(e,t,n)}},Bn=class{encode(e){return JSON.stringify(e)}decode(e){return JSON.parse(e)}},Vn=class extends ee.default{address;rpc_id;queue;options;autoconnect;ready;reconnect;reconnect_timer_id;reconnect_interval;max_reconnects;rest_options;current_reconnects;generate_request_id;socket;webSocketFactory;dataPack;constructor(e,t=`ws://localhost:8080`,{autoconnect:n=!0,reconnect:r=!0,reconnect_interval:i=1e3,max_reconnects:a=5,...o}={},s,c){super(),this.webSocketFactory=e,this.queue={},this.rpc_id=0,this.address=t,this.autoconnect=n,this.ready=!1,this.reconnect=r,this.reconnect_timer_id=void 0,this.reconnect_interval=i,this.max_reconnects=a,this.rest_options=o,this.current_reconnects=0,this.generate_request_id=s||(()=>typeof this.rpc_id==`number`?++this.rpc_id:Number(this.rpc_id)+1),this.dataPack=c||new Bn,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,n,r){return!r&&typeof n==`object`&&(r=n,n=null),new Promise((i,a)=>{if(!this.ready)return a(Error(`socket not ready`));let o=this.generate_request_id(e,t),s={jsonrpc:`2.0`,method:e,params:t||void 0,id:o};this.socket.send(this.dataPack.encode(s),r,e=>{if(e)return a(e);this.queue[o]={promise:[i,a]},n&&(this.queue[o].timeout=setTimeout(()=>{delete this.queue[o],a(Error(`reply timeout`))},n))})})}async login(e){let t=await this.call(`rpc.login`,e);if(!t)throw Error(`authentication failed`);return t}async listMethods(){return await this.call(`__listMethods`)}notify(e,t){return new Promise((n,r)=>{if(!this.ready)return r(Error(`socket not ready`));let i={jsonrpc:`2.0`,method:e,params:t};this.socket.send(this.dataPack.encode(i),e=>{if(e)return r(e);n()})})}async subscribe(e){typeof e==`string`&&(e=[e]);let t=await this.call(`rpc.on`,e);if(typeof e==`string`&&t[e]!==`ok`)throw 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 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:e})=>{e instanceof ArrayBuffer&&(e=g.from(e).toString());try{e=this.dataPack.decode(e)}catch{return}if(e.notification&&this.listeners(e.notification).length){if(!Object.keys(e.params).length)return this.emit(e.notification);let t=[e.notification];if(e.params.constructor===Object)t.push(e.params);else for(let n=0;n<e.params.length;n++)t.push(e.params[n]);return Promise.resolve().then(()=>{this.emit.apply(this,t)})}if(!this.queue[e.id])return e.method?Promise.resolve().then(()=>{this.emit(e.method,e?.params)}):void 0;`error`in e==`result`in e&&this.queue[e.id].promise[1](Error(`Server response malformed. Response must include either "result" or "error", but not both.`)),this.queue[e.id].timeout&&clearTimeout(this.queue[e.id].timeout),e.error?this.queue[e.id].promise[1](e.error):this.queue[e.id].promise[0](e.result),delete this.queue[e.id]}),this.socket.addEventListener(`error`,e=>this.emit(`error`,e)),this.socket.addEventListener(`close`,({code:n,reason:r})=>{this.ready&&setTimeout(()=>this.emit(`close`,n,r),0),this.ready=!1,this.socket=void 0,n!==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)))})}}}));function Un(e){try{return x.ExtendedPoint.fromHex(e),!0}catch{return!1}}function Wn(e){return e._bn!==void 0}function Gn(e,t){let n=e=>{if(e.span>=0)return e.span;if(typeof e.alloc==`function`)return e.alloc(t[e.property]);if(`count`in e&&`elementLayout`in e){let r=t[e.property];if(Array.isArray(r))return r.length*n(e.elementLayout)}else if(`fields`in e)return Gn({layout:e},t[e.property]);return 0},r=0;return e.layout.fields.forEach(e=>{r+=n(e)}),r}function Kn(e){let t=0,n=0;for(;;){let r=e.shift();if(t|=(r&127)<<n*7,n+=1,!(r&128))break}return t}function qn(e,t){let n=t;for(;;){let t=n&127;if(n>>=7,n==0){e.push(t);break}t|=128,e.push(t)}}function U(e,t){if(!e)throw Error(t||`Assertion failed`)}function Jn(e){if(e.length===0)throw Error(Hr);return e.shift()}function Yn(e,...t){let[n]=t;if(t.length===2?n+(t[1]??0)>e.length:n>=e.length)throw Error(Hr);return e.splice(...t)}function Xn(e){let t=Yn(e,0,4);return t[0]+t[1]*256+t[2]*2**16+t[3]*2**24}function Zn(e){let t=Yn(e,0,8),n=BigInt(0);for(let e=t.length-1;e>=0;e--)n=n<<BigInt(8)|BigInt(t[e]);return U(n<=BigInt(2**53-1),`Expected u64 value to be within the safe integer range`),Number(n)}async function Qn(e,t,n,r){let i=r&&{skipPreflight:r.skipPreflight,preflightCommitment:r.preflightCommitment||r.commitment,maxRetries:r.maxRetries,minContextSlot:r.minContextSlot},a=await e.sendTransaction(t,n,i),o;if(t.recentBlockhash!=null&&t.lastValidBlockHeight!=null)o=(await e.confirmTransaction({abortSignal:r?.abortSignal,signature:a,blockhash:t.recentBlockhash,lastValidBlockHeight:t.lastValidBlockHeight},r&&r.commitment)).value;else if(t.minNonceContextSlot!=null&&t.nonceInfo!=null){let{nonceInstruction:n}=t.nonceInfo,i=n.keys[0].pubkey;o=(await e.confirmTransaction({abortSignal:r?.abortSignal,minContextSlot:t.minNonceContextSlot,nonceAccountPubkey:i,nonceValue:t.nonceInfo.nonce,signature:a},r&&r.commitment)).value}else r?.abortSignal,o=(await e.confirmTransaction(a,r&&r.commitment)).value;if(o.err)throw a==null?Error(`Transaction ${a} failed (${JSON.stringify(o)})`):new ai({action:`send`,signature:a,transactionMessage:`Status: (${JSON.stringify(o)})`});return a}function $n(e){return new Promise(t=>setTimeout(t,e))}function W(e,t){let n=e.layout.span>=0?e.layout.span:Gn(e,t),r=g.alloc(n),i=Object.assign({instruction:e.index},t);return e.layout.encode(i,r),r}function er(e){let t=(0,br.blob)(8,e),n=t.decode.bind(t),r=t.encode.bind(t),i=t,a=st();return i.decode=(e,t)=>{let r=n(e,t);return a.decode(r)},i.encode=(e,t,n)=>{let i=a.encode(e);return r(i,t,n)},i}function tr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function nr(){if(hi)return mi;hi=1;var e=Object.prototype.toString,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};function n(r,i){var a,o,s,c,l,u,d;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 n(r.toJSON(),i);if(d=e.call(r),d===`[object Array]`){for(s=`[`,o=r.length-1,a=0;a<o;a++)s+=n(r[a],!0)+`,`;return o>-1&&(s+=n(r[a],!0)),s+`]`}if(d===`[object Object]`){for(c=t(r).sort(),o=c.length,s=``,a=0;a<o;)l=c[a],u=n(r[l],!1),u!==void 0&&(s&&(s+=`,`),s+=JSON.stringify(l)+`:`+u),a++;return`{`+s+`}`}return JSON.stringify(r);case`function`:case`undefined`:return i?null:void 0;case`string`:return JSON.stringify(r);default:return isFinite(r)?r:null}}return mi=function(e){var t=n(e,!1);if(t!==void 0)return``+t},mi}function rr(e){let t=0;for(;e>1;)e/=2,t++;return t}function ir(e){return e===0?1:(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e|=e>>32,e+1)}function ar(e,t){let n;try{n=e.layout.decode(t)}catch(e){throw Error(`invalid instruction; `+e)}if(n.typeIndex!==e.index)throw Error(`invalid account data; account type mismatch ${n.typeIndex} != ${e.index}`);return n}function or(e){let t=e.match(wi);if(t==null)throw TypeError(`Failed to validate endpoint URL \`${e}\``);let[n,r,i,a]=t,o=e.startsWith(`https:`)?`wss:`:`ws:`,s=i==null?null:parseInt(i.slice(1),10);return`${o}//${r}${s==null?``:`:${s+1}`}${a}`}function sr(e){if(/^https?:/.test(e)===!1)throw TypeError("Endpoint URL must start with `http:` or `https:`.");return e}function G(e){let t,n;if(typeof e==`string`)t=e;else if(e){let{commitment:r,...i}=e;t=r,n=i}return{commitment:t,config:n}}function cr(e){return e.map(e=>`memcmp`in e?{...e,memcmp:{...e.memcmp,encoding:e.memcmp.encoding??`base58`}}:e)}function lr(e){return kt([H({jsonrpc:Tt(`2.0`),id:V(),result:e}),H({jsonrpc:Tt(`2.0`),id:V(),error:H({code:At(),message:V(),data:B(St())})})])}function K(e){return jt(lr(e),ki,t=>`error`in t?t:{...t,result:I(t.result,e)})}function ur(e){return K(H({context:H({slot:z()}),value:e}))}function dr(e){return H({context:H({slot:z()}),value:e})}function fr(e,t){if(e===0)return new Wr({header:t.header,staticAccountKeys:t.accountKeys.map(e=>new Y(e)),recentBlockhash:t.recentBlockhash,compiledInstructions:t.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)})),addressTableLookups:t.addressTableLookups});if(e===1){let e=t.transactionConfig;if(e==null)throw Error("Expected a version 1 transaction message response to have a `transactionConfig`");return new Yr({header:t.header,staticAccountKeys:t.accountKeys.map(e=>new Y(e)),recentBlockhash:t.recentBlockhash,compiledInstructions:t.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)})),transactionConfig:e})}return new Ur(t)}function pr(e,t,n,r,i,a){let o=n||yi,s,c;return r&&(c=async(e,t)=>{let n=await new Promise((n,i)=>{try{r(e,t,(e,t)=>n([e,t]))}catch(e){i(e)}});return await o(...n)}),new xr.default(async(n,r)=>{let a={method:`POST`,body:n,agent:s,headers:Object.assign({"Content-Type":`application/json`},t||{},fo)};try{let t=5,n,s=500;for(;n=c?await c(e,a):await o(e,a),!(n.status!==429||i===!0||(--t,t===0));)await $n(s),s*=2;let l=await n.text();n.ok?r(null,l):r(Error(`${n.status} ${n.statusText}: ${l}`))}catch(e){e instanceof Error&&r(e)}},{})}function mr(e){return(t,n)=>new Promise((r,i)=>{e.request(t,n,(e,t)=>{if(e){i(e);return}r(t)})})}function hr(e){return t=>new Promise((n,r)=>{t.length===0&&n([]);let i=t.map(t=>e.request(t.methodName,t.args));e.request(i,(e,t)=>{if(e){r(e);return}n(t)})})}function gr(e,t){let n=t===!1?`http`:`https`;if(!e)return Ro[n].devnet;let r=Ro[n][e];if(!r)throw Error(`Unknown ${n} cluster: ${e}`);return r}var _r,vr,yr,q,br,xr,Sr,Cr,wr,Tr,J,Er,Dr,Or,kr,Y,Ar,jr,Mr,Nr,Pr,X,Fr,Ir,Lr,Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,Z,Q,$r,ei,ti,ni,ri,ii,ai,$,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo=e((()=>{_(),te(),_r=r(ye()),vr=r(C()),p(),yr=Me(),q=r(Ne()),br=r(Ne()),ct(),Pt(),xr=r(Ln()),Hn(),h(),T(),x.utils.randomPrivateKey,Sr=()=>{let e=x.utils.randomPrivateKey(),t=Cr(e),n=new Uint8Array(64);return n.set(e),n.set(t,32),{publicKey:t,secretKey:n}},Cr=x.getPublicKey,wr=(e,t)=>x.sign(e,t.slice(0,32)),Tr=x.verify,J=e=>g.isBuffer(e)?e:e instanceof Uint8Array?g.from(e.buffer,e.byteOffset,e.byteLength):g.from(e),Er=class{constructor(e){Object.assign(this,e)}encode(){return g.from((0,yr.serialize)(Dr,this))}static decode(e){return(0,yr.deserialize)(Dr,this,e)}static decodeUnchecked(e){return(0,yr.deserializeUnchecked)(Dr,this,e)}},Dr=new Map,kr=1,Y=class e extends Er{constructor(e){if(super({}),this._bn=void 0,Wn(e))this._bn=e._bn;else{if(typeof e==`string`){let t=vr.default.decode(e);if(t.length!=32)throw Error(`Invalid public key input`);this._bn=new _r.default(t)}else this._bn=new _r.default(e);if(this._bn.byteLength()>32)throw Error(`Invalid public key input`)}}static unique(){let t=new e(kr);return kr+=1,new e(t.toBuffer())}equals(e){return this._bn.eq(e._bn)}toBase58(){return vr.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(g);if(e.length===32)return e;let t=g.alloc(32);return e.copy(t,32-e.length),t}get[Symbol.toStringTag](){return`PublicKey(${this.toString()})`}toString(){return this.toBase58()}static async createWithSeed(t,n,r){let i=g.concat([t.toBuffer(),g.from(n),r.toBuffer()]),a=f(i);return new e(a)}static createProgramAddressSync(t,n){let r=g.alloc(0);t.forEach(function(e){if(e.length>32)throw TypeError(`Max seed length exceeded`);r=g.concat([r,J(e)])}),r=g.concat([r,n.toBuffer(),g.from(`ProgramDerivedAddress`)]);let i=f(r);if(Un(i))throw Error(`Invalid seeds, address must fall off the curve`);return new e(i)}static async createProgramAddress(e,t){return this.createProgramAddressSync(e,t)}static findProgramAddressSync(e,t){let n=255,r;for(;n!=0;){try{let i=e.concat(g.from([n]));r=this.createProgramAddressSync(i,t)}catch(e){if(e instanceof TypeError)throw e;n--;continue}return[r,n]}throw Error(`Unable to find a viable program address nonce`)}static async findProgramAddress(e,t){return this.findProgramAddressSync(e,t)}static isOnCurve(t){return Un(new e(t).toBytes())}},Or=Y,Y.default=new Or(`11111111111111111111111111111111`),Dr.set(Y,{kind:`struct`,fields:[[`_bn`,`u256`]]}),new Y(`BPFLoader1111111111111111111111111111111111`),Ar=1232,jr=class extends Error{constructor(e){super(`Signature ${e} has expired: block height exceeded.`),this.signature=void 0,this.signature=e}},Object.defineProperty(jr.prototype,"name",{value:`TransactionExpiredBlockheightExceededError`}),Mr=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(Mr.prototype,"name",{value:`TransactionExpiredTimeoutError`}),Nr=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(Nr.prototype,"name",{value:`TransactionExpiredNonceInvalidError`}),Pr=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];else e-=t.length}get length(){return this.keySegments().flat().length}compileInstructions(e){if(this.length>256)throw Error(`Account index overflow encountered during compilation`);let t=new Map;this.keySegments().flat().forEach((e,n)=>{t.set(e.toBase58(),n)});let n=e=>{let n=t.get(e.toBase58());if(n===void 0)throw Error(`Encountered an unknown instruction account key during compilation`);return n};return e.map(e=>({programIdIndex:n(e.programId),accountKeyIndexes:e.keys.map(e=>n(e.pubkey)),data:e.data}))}},X=(e=`publicKey`)=>q.blob(32,e),Fr=(e=`signature`)=>q.blob(64,e),Ir=(e=`string`)=>{let t=q.struct([q.u32(`length`),q.u32(`lengthPadding`),q.blob(q.offset(q.u32(),-8),`chars`)],e),n=t.decode.bind(t),r=t.encode.bind(t),i=t;return i.decode=(e,t)=>n(e,t).chars.toString(),i.encode=(e,t,n)=>{let i={chars:g.from(e,`utf8`)};return r(i,t,n)},i.alloc=e=>q.u32().span+q.u32().span+g.from(e,`utf8`).length,i},Lr=(e=`authorized`)=>q.struct([X(`staker`),X(`withdrawer`)],e),Rr=(e=`lockup`)=>q.struct([q.ns64(`unixTimestamp`),q.ns64(`epoch`),X(`custodian`)],e),zr=(e=`voteInit`)=>q.struct([X(`nodePubkey`),X(`authorizedVoter`),X(`authorizedWithdrawer`),q.u8(`commission`)],e),Br=(e=`voteAuthorizeWithSeedArgs`)=>q.struct([q.u32(`voteAuthorizationType`),X(`currentAuthorityDerivedKeyOwnerPubkey`),Ir(`currentAuthorityDerivedKeySeed`),X(`newAuthorized`)],e),Vr=class e{constructor(e,t){this.payer=void 0,this.keyMetaMap=void 0,this.payer=e,this.keyMetaMap=t}static compile(t,n){let r=new Map,i=e=>{let t=e.toBase58(),n=r.get(t);return n===void 0&&(n={isSigner:!1,isWritable:!1,isInvoked:!1},r.set(t,n)),n},a=i(n);a.isSigner=!0,a.isWritable=!0;for(let e of t){i(e.programId).isInvoked=!0;for(let t of e.keys){let e=i(t.pubkey);e.isSigner||=t.isSigner,e.isWritable||=t.isWritable}}return new e(n,r)}getMessageComponents(){let e=[...this.keyMetaMap.entries()];U(e.length<=256,`Max static account keys length exceeded`);let t=e.filter(([,e])=>e.isSigner&&e.isWritable),n=e.filter(([,e])=>e.isSigner&&!e.isWritable),r=e.filter(([,e])=>!e.isSigner&&e.isWritable),i=e.filter(([,e])=>!e.isSigner&&!e.isWritable),a={numRequiredSignatures:t.length+n.length,numReadonlySignedAccounts:n.length,numReadonlyUnsignedAccounts:i.length};{U(t.length>0,`Expected at least one writable signer key`);let[e]=t[0];U(e===this.payer.toBase58(),`Expected first writable signer key to be the fee payer`)}return[a,[...t.map(([e])=>new Y(e)),...n.map(([e])=>new Y(e)),...r.map(([e])=>new Y(e)),...i.map(([e])=>new Y(e))]]}extractTableLookup(e){let[t,n]=this.drainKeysFoundInLookupTable(e.state.addresses,e=>!e.isSigner&&!e.isInvoked&&e.isWritable),[r,i]=this.drainKeysFoundInLookupTable(e.state.addresses,e=>!e.isSigner&&!e.isInvoked&&!e.isWritable);if(t.length!==0||r.length!==0)return[{accountKey:e.key,writableIndexes:t,readonlyIndexes:r},{writable:n,readonly:i}]}drainKeysFoundInLookupTable(e,t){let n=[],r=[];for(let[i,a]of this.keyMetaMap.entries())if(t(a)){let t=new Y(i),a=e.findIndex(e=>e.equals(t));a>=0&&(U(a<256,`Max lookup table index exceeded`),n.push(a),r.push(t),this.keyMetaMap.delete(i))}return[n,r]}},Hr=`Reached end of buffer unexpectedly`,Ur=class e{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(e=>new Y(e)),this.recentBlockhash=e.recentBlockhash,this.instructions=e.instructions,this.instructions.forEach(e=>this.indexToProgramIds.set(e.programIdIndex,this.accountKeys[e.programIdIndex]))}get version(){return`legacy`}get staticAccountKeys(){return this.accountKeys}get compiledInstructions(){return this.instructions.map(e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:vr.default.decode(e.data)}))}get addressTableLookups(){return[]}getAccountKeys(){return new Pr(this.staticAccountKeys)}static compile(t){let[n,r]=Vr.compile(t.instructions,t.payerKey).getMessageComponents(),i=new Pr(r).compileInstructions(t.instructions).map(e=>({programIdIndex:e.programIdIndex,accounts:e.accountKeyIndexes,data:vr.default.encode(e.data)}));return new e({header:n,accountKeys:r,recentBlockhash:t.recentBlockhash,instructions:i})}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures;return e>=this.header.numRequiredSignatures?e-t<this.accountKeys.length-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}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=[];qn(t,e);let n=this.instructions.map(e=>{let{accounts:t,programIdIndex:n}=e,r=Array.from(vr.default.decode(e.data)),i=[];qn(i,t.length);let a=[];return qn(a,r.length),{programIdIndex:n,keyIndicesCount:g.from(i),keyIndices:t,dataLength:g.from(a),data:r}}),r=[];qn(r,n.length);let i=g.alloc(Ar);g.from(r).copy(i);let a=r.length;n.forEach(e=>{let t=q.struct([q.u8(`programIdIndex`),q.blob(e.keyIndicesCount.length,`keyIndicesCount`),q.seq(q.u8(`keyIndex`),e.keyIndices.length,`keyIndices`),q.blob(e.dataLength.length,`dataLength`),q.seq(q.u8(`userdatum`),e.data.length,`data`)]).encode(e,i,a);a+=t}),i=i.slice(0,a);let o=q.struct([q.blob(1,`numRequiredSignatures`),q.blob(1,`numReadonlySignedAccounts`),q.blob(1,`numReadonlyUnsignedAccounts`),q.blob(t.length,`keyCount`),q.seq(X(`key`),e,`keys`),X(`recentBlockhash`)]),s={numRequiredSignatures:g.from([this.header.numRequiredSignatures]),numReadonlySignedAccounts:g.from([this.header.numReadonlySignedAccounts]),numReadonlyUnsignedAccounts:g.from([this.header.numReadonlyUnsignedAccounts]),keyCount:g.from(t),keys:this.accountKeys.map(e=>J(e.toBytes())),recentBlockhash:vr.default.decode(this.recentBlockhash)},c=g.alloc(2048),l=o.encode(s,c);return i.copy(c,l),c.slice(0,l+i.length)}static from(t){let n=[...t],r=Jn(n);if(r!==(r&127))throw Error(`Versioned messages must be deserialized with VersionedMessage.deserialize()`);let i=Jn(n),a=Jn(n),o=Kn(n),s=[];for(let e=0;e<o;e++){let e=Yn(n,0,32);s.push(new Y(g.from(e)))}let c=Yn(n,0,32),l=Kn(n),u=[];for(let e=0;e<l;e++){let e=Jn(n),t=Yn(n,0,Kn(n)),r=Yn(n,0,Kn(n)),i=vr.default.encode(g.from(r));u.push({programIdIndex:e,accounts:t,data:i})}let d={header:{numRequiredSignatures:r,numReadonlySignedAccounts:i,numReadonlyUnsignedAccounts:a},recentBlockhash:vr.default.encode(g.from(c)),accountKeys:s,instructions:u};return new e(d)}},Wr=class e{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 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 Error(`Failed to get account keys because address table lookups were not resolved`);return new Pr(this.staticAccountKeys,t)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures,n=this.staticAccountKeys.length;return e>=n?e-n<this.addressTableLookups.reduce((e,t)=>e+t.writableIndexes.length,0):e>=this.header.numRequiredSignatures?e-t<n-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}resolveAddressTableLookups(e){let t={writable:[],readonly:[]};for(let n of this.addressTableLookups){let r=e.find(e=>e.key.equals(n.accountKey));if(!r)throw Error(`Failed to find address lookup table account for table key ${n.accountKey.toBase58()}`);for(let e of n.writableIndexes)if(e<r.state.addresses.length)t.writable.push(r.state.addresses[e]);else throw Error(`Failed to find address for index ${e} in address lookup table ${n.accountKey.toBase58()}`);for(let e of n.readonlyIndexes)if(e<r.state.addresses.length)t.readonly.push(r.state.addresses[e]);else throw Error(`Failed to find address for index ${e} in address lookup table ${n.accountKey.toBase58()}`)}return t}static compile(t){let n=Vr.compile(t.instructions,t.payerKey),r=[],i={writable:[],readonly:[]},a=t.addressLookupTableAccounts||[];for(let e of a){let t=n.extractTableLookup(e);if(t!==void 0){let[e,{writable:n,readonly:a}]=t;r.push(e),i.writable.push(...n),i.readonly.push(...a)}}let[o,s]=n.getMessageComponents(),c=new Pr(s,i).compileInstructions(t.instructions);return new e({header:o,staticAccountKeys:s,recentBlockhash:t.recentBlockhash,compiledInstructions:c,addressTableLookups:r})}serialize(){let e=[];qn(e,this.staticAccountKeys.length);let t=this.serializeInstructions(),n=[];qn(n,this.compiledInstructions.length);let r=this.serializeAddressTableLookups(),i=[];qn(i,this.addressTableLookups.length);let a=q.struct([q.u8(`prefix`),q.struct([q.u8(`numRequiredSignatures`),q.u8(`numReadonlySignedAccounts`),q.u8(`numReadonlyUnsignedAccounts`)],`header`),q.blob(e.length,`staticAccountKeysLength`),q.seq(X(),this.staticAccountKeys.length,`staticAccountKeys`),X(`recentBlockhash`),q.blob(n.length,`instructionsLength`),q.blob(t.length,`serializedInstructions`),q.blob(i.length,`addressTableLookupsLength`),q.blob(r.length,`serializedAddressTableLookups`)]),o=new Uint8Array(Ar),s=a.encode({prefix:128,header:this.header,staticAccountKeysLength:new Uint8Array(e),staticAccountKeys:this.staticAccountKeys.map(e=>e.toBytes()),recentBlockhash:vr.default.decode(this.recentBlockhash),instructionsLength:new Uint8Array(n),serializedInstructions:t,addressTableLookupsLength:new Uint8Array(i),serializedAddressTableLookups:r},o);return o.slice(0,s)}serializeInstructions(){let e=0,t=new Uint8Array(Ar);for(let n of this.compiledInstructions){let r=[];qn(r,n.accountKeyIndexes.length);let i=[];qn(i,n.data.length);let a=q.struct([q.u8(`programIdIndex`),q.blob(r.length,`encodedAccountKeyIndexesLength`),q.seq(q.u8(),n.accountKeyIndexes.length,`accountKeyIndexes`),q.blob(i.length,`encodedDataLength`),q.blob(n.data.length,`data`)]);e+=a.encode({programIdIndex:n.programIdIndex,encodedAccountKeyIndexesLength:new Uint8Array(r),accountKeyIndexes:n.accountKeyIndexes,encodedDataLength:new Uint8Array(i),data:n.data},t,e)}return t.slice(0,e)}serializeAddressTableLookups(){let e=0,t=new Uint8Array(Ar);for(let n of this.addressTableLookups){let r=[];qn(r,n.writableIndexes.length);let i=[];qn(i,n.readonlyIndexes.length);let a=q.struct([X(`accountKey`),q.blob(r.length,`encodedWritableIndexesLength`),q.seq(q.u8(),n.writableIndexes.length,`writableIndexes`),q.blob(i.length,`encodedReadonlyIndexesLength`),q.seq(q.u8(),n.readonlyIndexes.length,`readonlyIndexes`)]);e+=a.encode({accountKey:n.accountKey.toBytes(),encodedWritableIndexesLength:new Uint8Array(r),writableIndexes:n.writableIndexes,encodedReadonlyIndexesLength:new Uint8Array(i),readonlyIndexes:n.readonlyIndexes},t,e)}return t.slice(0,e)}static deserialize(t){let n=[...t],r=Jn(n),i=r&127;U(r!==i,`Expected versioned message but received legacy message`);let a=i;U(a===0,`Expected versioned message with version 0 but found version ${a}`);let o={numRequiredSignatures:Jn(n),numReadonlySignedAccounts:Jn(n),numReadonlyUnsignedAccounts:Jn(n)},s=[],c=Kn(n);for(let e=0;e<c;e++)s.push(new Y(Yn(n,0,32)));let l=vr.default.encode(Yn(n,0,32)),u=Kn(n),d=[];for(let e=0;e<u;e++){let e=Jn(n),t=Yn(n,0,Kn(n)),r=Kn(n),i=new Uint8Array(Yn(n,0,r));d.push({programIdIndex:e,accountKeyIndexes:t,data:i})}let f=Kn(n),p=[];for(let e=0;e<f;e++){let e=new Y(Yn(n,0,32)),t=Yn(n,0,Kn(n)),r=Yn(n,0,Kn(n));p.push({accountKey:e,writableIndexes:t,readonlyIndexes:r})}return new e({header:o,staticAccountKeys:s,recentBlockhash:l,compiledInstructions:d,addressTableLookups:p})}},Gr=3,Kr=4,qr=8,Jr=16,Yr=class e{constructor(e){this.header=void 0,this.staticAccountKeys=void 0,this.recentBlockhash=void 0,this.compiledInstructions=void 0,this.transactionConfig=void 0,this.header=e.header,this.staticAccountKeys=e.staticAccountKeys,this.recentBlockhash=e.recentBlockhash,this.compiledInstructions=e.compiledInstructions,this.transactionConfig=e.transactionConfig??{computeUnitLimit:null,heapSize:null,loadedAccountsDataSizeLimit:null,priorityFee:null}}get version(){return 1}get addressTableLookups(){return[]}getAccountKeys(){return new Pr(this.staticAccountKeys)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){let t=this.header.numRequiredSignatures,n=this.staticAccountKeys.length;return e>=n?!1:e>=this.header.numRequiredSignatures?e-t<n-t-this.header.numReadonlyUnsignedAccounts:e<t-this.header.numReadonlySignedAccounts}serialize(){throw Error(`Serialization of version 1 transaction messages is not supported`)}static deserialize(t){let n=[...t],r=Jn(n),i=r&127;U(r!==i,`Expected versioned message but received legacy message`);let a=i;U(a===1,`Expected versioned message with version 1 but found version ${a}`);let o={numRequiredSignatures:Jn(n),numReadonlySignedAccounts:Jn(n),numReadonlyUnsignedAccounts:Jn(n)},s=Xn(n);U(!(s&-32),`Unexpected bits set in the transaction config mask`);let c=s&Gr;U(c===0||c===Gr,`Expected both or neither of the priority fee bits to be set in the transaction config mask`);let l=vr.default.encode(Yn(n,0,32)),u=Jn(n),d=Jn(n),f=[];for(let e=0;e<d;e++)f.push(new Y(Yn(n,0,32)));let p={computeUnitLimit:null,heapSize:null,loadedAccountsDataSizeLimit:null,priorityFee:null};c!==0&&(p.priorityFee=Zn(n)),s&Kr&&(p.computeUnitLimit=Xn(n)),s&qr&&(p.loadedAccountsDataSizeLimit=Xn(n)),s&Jr&&(p.heapSize=Xn(n));let m=[];for(let e=0;e<u;e++){let e=Jn(n),t=Jn(n),r=Jn(n)+Jn(n)*256;m.push({accountKeyIndexesLength:t,dataLength:r,programIdIndex:e})}let h=[];for(let e of m)h.push({programIdIndex:e.programIdIndex,accountKeyIndexes:Yn(n,0,e.accountKeyIndexesLength),data:new Uint8Array(Yn(n,0,e.dataLength))});return U(n.length===0,`Expected no bytes to remain after deserializing a version 1 message`),new e({header:o,staticAccountKeys:f,recentBlockhash:l,compiledInstructions:h,transactionConfig:p})}},Xr={deserializeMessageVersion(e){let t=e[0],n=t&127;return n===t?`legacy`:n},deserialize:e=>{let t=Xr.deserializeMessageVersion(e);if(t===`legacy`)return Ur.from(e);if(t===0)return Wr.deserialize(e);if(t===1)return Yr.deserialize(e);throw Error(`Transaction message version ${t} deserialization is not supported`)}},Zr=function(e){return e[e.BLOCKHEIGHT_EXCEEDED=0]=`BLOCKHEIGHT_EXCEEDED`,e[e.PROCESSED=1]=`PROCESSED`,e[e.TIMED_OUT=2]=`TIMED_OUT`,e[e.NONCE_INVALID=3]=`NONCE_INVALID`,e}({}),Qr=g.alloc(64).fill(0),Z=class{constructor(e){this.keys=void 0,this.programId=void 0,this.data=g.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:n})=>({pubkey:e.toJSON(),isSigner:t,isWritable:n})),programId:this.programId.toJSON(),data:[...this.data]}}},Q=class e{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:n}=e;this.minNonceContextSlot=t,this.nonceInfo=n}else if(Object.prototype.hasOwnProperty.call(e,`lastValidBlockHeight`)){let{blockhash:t,lastValidBlockHeight:n}=e;this.recentBlockhash=t,this.lastValidBlockHeight=n}else{let{recentBlockhash:t,nonceInfo:n}=e;n&&(this.nonceInfo=n),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 Error(`No instructions`);return e.forEach(e=>{`instructions`in e?this.instructions=this.instructions.concat(e.instructions):`data`in e&&`programId`in e&&`keys`in e?this.instructions.push(e):this.instructions.push(new Z(e))}),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,t=this.instructions[0]==this.nonceInfo.nonceInstruction?this.instructions:[this.nonceInfo.nonceInstruction,...this.instructions]):(e=this.recentBlockhash,t=this.instructions),!e)throw Error(`Transaction recentBlockhash required`);t.length;let n;if(this.feePayer)n=this.feePayer;else if(this.signatures.length>0&&this.signatures[0].publicKey)n=this.signatures[0].publicKey;else throw Error(`Transaction fee payer required`);for(let e=0;e<t.length;e++)if(t[e].programId===void 0)throw Error(`Transaction instruction index ${e} has undefined program id`);let r=[],i=[];t.forEach(e=>{e.keys.forEach(e=>{i.push({...e})});let t=e.programId.toString();r.includes(t)||r.push(t)}),r.forEach(e=>{i.push({pubkey:new Y(e),isSigner:!1,isWritable:!1})});let a=[];i.forEach(e=>{let t=e.pubkey.toString(),n=a.findIndex(e=>e.pubkey.toString()===t);n>-1?(a[n].isWritable=a[n].isWritable||e.isWritable,a[n].isSigner=a[n].isSigner||e.isSigner):a.push(e)}),a.sort(function(e,t){return e.isSigner===t.isSigner?e.isWritable===t.isWritable?e.pubkey.toBase58().localeCompare(t.pubkey.toBase58(),`en`,{localeMatcher:`best fit`,usage:`sort`,sensitivity:`variant`,ignorePunctuation:!1,numeric:!1,caseFirst:`lower`}):e.isWritable?-1:1:e.isSigner?-1:1});let o=a.findIndex(e=>e.pubkey.equals(n));if(o>-1){let[e]=a.splice(o,1);e.isSigner=!0,e.isWritable=!0,a.unshift(e)}else a.unshift({pubkey:n,isSigner:!0,isWritable:!0});for(let e of this.signatures){let t=a.findIndex(t=>t.pubkey.equals(e.publicKey));if(t>-1)a[t].isSigner||(a[t].isSigner=!0);else throw Error(`unknown signer: ${e.publicKey.toString()}`)}let s=0,c=0,l=0,u=[],d=[];a.forEach(({pubkey:e,isSigner:t,isWritable:n})=>{t?(u.push(e.toString()),s+=1,n||(c+=1)):(d.push(e.toString()),n||(l+=1))});let f=u.concat(d),p=t.map(e=>{let{data:t,programId:n}=e;return{programIdIndex:f.indexOf(n.toString()),accounts:e.keys.map(e=>f.indexOf(e.pubkey.toString())),data:vr.default.encode(t)}});return p.forEach(e=>{U(e.programIdIndex>=0),e.accounts.forEach(e=>U(e>=0))}),new Ur({header:{numRequiredSignatures:s,numReadonlySignedAccounts:c,numReadonlyUnsignedAccounts:l},accountKeys:f,recentBlockhash:e,instructions:p})}_compile(){let e=this.compileMessage(),t=e.accountKeys.slice(0,e.header.numRequiredSignatures);return this.signatures.length===t.length&&this.signatures.every((e,n)=>t[n].equals(e.publicKey))||(this.signatures=t.map(e=>({signature:null,publicKey:e}))),e}serializeMessage(){return this._compile().serialize()}async getEstimatedFee(e){return(await e.getFeeForMessage(this.compileMessage())).value}setSigners(...e){if(e.length===0)throw Error(`No signers`);let t=new Set;this.signatures=e.filter(e=>{let n=e.toString();return!t.has(n)&&(t.add(n),!0)}).map(e=>({signature:null,publicKey:e}))}sign(...e){if(e.length===0)throw Error(`No signers`);let t=new Set,n=[];for(let r of e){let e=r.publicKey.toString();t.has(e)||(t.add(e),n.push(r))}this.signatures=n.map(e=>({signature:null,publicKey:e.publicKey}));let r=this._compile();this._partialSign(r,...n)}partialSign(...e){if(e.length===0)throw Error(`No signers`);let t=new Set,n=[];for(let r of e){let e=r.publicKey.toString();t.has(e)||(t.add(e),n.push(r))}let r=this._compile();this._partialSign(r,...n)}_partialSign(e,...t){let n=e.serialize();t.forEach(e=>{let t=wr(n,e.secretKey);this._addSignature(e.publicKey,J(t))})}addSignature(e,t){this._compile(),this._addSignature(e,t)}_addSignature(e,t){U(t.length===64);let n=this.signatures.findIndex(t=>e.equals(t.publicKey));if(n<0)throw Error(`unknown signer: ${e.toString()}`);this.signatures[n].signature=g.from(t)}verifySignatures(e=!0){return!this._getMessageSignednessErrors(this.serializeMessage(),e)}_getMessageSignednessErrors(e,t){let n={};for(let{signature:r,publicKey:i}of this.signatures)r===null?t&&(n.missing||=[]).push(i):Tr(r,e,i.toBytes())||(n.invalid||=[]).push(i);return n.invalid||n.missing?n:void 0}serialize(e){let{requireAllSignatures:t,verifySignatures:n}=Object.assign({requireAllSignatures:!0,verifySignatures:!0},e),r=this.serializeMessage();if(n){let e=this._getMessageSignednessErrors(r,t);if(e){let t=`Signature verification failed.`;throw e.invalid&&(t+=`\nInvalid signature for public key${e.invalid.length===1?``:`(s)`} [\`${e.invalid.map(e=>e.toBase58()).join("`, `")}\`].`),e.missing&&(t+=`\nMissing signature for public key${e.missing.length===1?``:`(s)`} [\`${e.missing.map(e=>e.toBase58()).join("`, `")}\`].`),Error(t)}}return this._serialize(r)}_serialize(e){let{signatures:t}=this,n=[];qn(n,t.length);let r=n.length+t.length*64+e.length,i=g.alloc(r);return U(t.length<256),g.from(n).copy(i,0),t.forEach(({signature:e},t)=>{e!==null&&(U(e.length===64,`signature has invalid length`),g.from(e).copy(i,n.length+t*64))}),e.copy(i,n.length+t.length*64),U(i.length<=Ar,`Transaction too large: ${i.length} > ${Ar}`),i}get keys(){return U(this.instructions.length===1),this.instructions[0].keys.map(e=>e.pubkey)}get programId(){return U(this.instructions.length===1),this.instructions[0].programId}get data(){return U(this.instructions.length===1),this.instructions[0].data}static from(t){let n=[...t],r=Kn(n),i=[];for(let e=0;e<r;e++){let e=Yn(n,0,64);i.push(vr.default.encode(g.from(e)))}return e.populate(Ur.from(n),i)}static populate(t,n=[]){let r=new e;return r.recentBlockhash=t.recentBlockhash,t.header.numRequiredSignatures>0&&(r.feePayer=t.accountKeys[0]),n.forEach((e,n)=>{let i={signature:e==vr.default.encode(Qr)?null:vr.default.decode(e),publicKey:t.accountKeys[n]};r.signatures.push(i)}),t.instructions.forEach(e=>{let n=e.accounts.map(e=>{let n=t.accountKeys[e];return{pubkey:n,isSigner:r.signatures.some(e=>e.publicKey.toString()===n.toString())||t.isAccountSigner(e),isWritable:t.isAccountWritable(e)}});r.instructions.push(new Z({keys:n,programId:t.accountKeys[e.programIdIndex],data:vr.default.decode(e.data)}))}),r._message=t,r._json=r.toJSON(),r}},$r=class e{get version(){return this.message.version}constructor(e,t){if(this.signatures=void 0,this.message=void 0,t!==void 0)U(t.length===e.header.numRequiredSignatures,`Expected signatures length to be equal to the number of required signatures`),this.signatures=t;else{let t=[];for(let n=0;n<e.header.numRequiredSignatures;n++)t.push(new Uint8Array(64));this.signatures=t}this.message=e}serialize(){let e=this.message.serialize(),t=[];qn(t,this.signatures.length);let n=q.struct([q.blob(t.length,`encodedSignaturesLength`),q.seq(Fr(),this.signatures.length,`signatures`),q.blob(e.length,`serializedMessage`)]),r=new Uint8Array(2048),i=n.encode({encodedSignaturesLength:new Uint8Array(t),signatures:this.signatures,serializedMessage:e},r);return r.slice(0,i)}static deserialize(t){if(t[0]===129)return this.deserializeV1(t);let n=[...t],r=[],i=Kn(n);for(let e=0;e<i;e++)r.push(new Uint8Array(Yn(n,0,64)));let a=Xr.deserialize(new Uint8Array(n));return new e(a,r)}static deserializeV1(t){let n=t[1],r=n*64,i=t.length-r;U(i>0,`Expected transaction to have enough bytes for its signatures`);let a=Xr.deserialize(t.slice(0,i)),o=[];for(let e=0;e<n;e++){let n=i+e*64;o.push(t.slice(n,n+64))}return new e(a,o)}sign(e){let t=this.message.serialize(),n=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures);for(let r of e){let e=n.findIndex(e=>e.equals(r.publicKey));U(e>=0,`Cannot sign with non signer key ${r.publicKey.toBase58()}`),this.signatures[e]=wr(t,r.secretKey)}}addSignature(e,t){U(t.byteLength===64,`Signature must be 64 bytes long`);let n=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures).findIndex(t=>t.equals(e));U(n>=0,`Can not add signature; \`${e.toBase58()}\` is not required to sign this transaction`),this.signatures[n]=t}},ei=1e3/(160/64),ti=new Y(`SysvarC1ock11111111111111111111111111111111`),new Y(`SysvarEpochSchedu1e111111111111111111111111`),new Y(`Sysvar1nstructions1111111111111111111111111`),ni=new Y(`SysvarRecentB1ockHashes11111111111111111111`),ri=new Y(`SysvarRent111111111111111111111111111111111`),new Y(`SysvarRewards111111111111111111111111111111`),new Y(`SysvarS1otHashes111111111111111111111111111`),new Y(`SysvarS1otHistory11111111111111111111111111`),ii=new Y(`SysvarStakeHistory1111111111111111111111111`),ai=class extends Error{constructor({action:e,signature:t,transactionMessage:n,logs:r}){let i=r?`Logs: \n${JSON.stringify(r.slice(-10),null,2)}. `:``,a="\nCatch the `SendTransactionError` and call `getLogs()` on it for full details.",o;switch(e){case`send`:o=`Transaction ${t} resulted in an error. \n${n}. `+i+a;break;case`simulate`:o=`Simulation failed. \nMessage: ${n}. \n`+i+a;break;default:o=`Unknown action '${(e=>e)(e)}'`}super(o),this.signature=void 0,this.transactionMessage=void 0,this.transactionLogs=void 0,this.signature=t,this.transactionMessage=n,this.transactionLogs=r||void 0}get transactionError(){return{message:this.transactionMessage,logs:Array.isArray(this.transactionLogs)?this.transactionLogs:void 0}}get logs(){let e=this.transactionLogs;if(!(typeof e==`object`&&e&&`then`in e))return e}async getLogs(e){return Array.isArray(this.transactionLogs)||(this.transactionLogs=new Promise((t,n)=>{e.getTransaction(this.signature).then(e=>{if(e&&e.meta&&e.meta.logMessages){let n=e.meta.logMessages;this.transactionLogs=n,t(n)}else n(Error(`Log messages not found`))}).catch(n)})),await this.transactionLogs}},$=class extends Error{constructor({code:e,message:t,data:n},r){super(r==null?t:`${r}: ${t}`),this.code=void 0,this.data=void 0,this.code=e,this.data=n,this.name=`SolanaJSONRPCError`}},oi=q.nu64(`lamportsPerSignature`),si=q.struct([q.u32(`version`),q.u32(`state`),X(`authorizedPubkey`),X(`nonce`),q.struct([oi],`feeCalculator`)]),ci=si.span,li=class e{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(t){let n=si.decode(J(t),0);return new e({authorizedPubkey:new Y(n.authorizedPubkey),nonce:new Y(n.nonce).toString(),feeCalculator:n.feeCalculator})}},ui=Object.freeze({Create:{index:0,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`),q.ns64(`space`),X(`programId`)])},Assign:{index:1,layout:q.struct([q.u32(`instruction`),X(`programId`)])},Transfer:{index:2,layout:q.struct([q.u32(`instruction`),er(`lamports`)])},CreateWithSeed:{index:3,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),q.ns64(`lamports`),q.ns64(`space`),X(`programId`)])},AdvanceNonceAccount:{index:4,layout:q.struct([q.u32(`instruction`)])},WithdrawNonceAccount:{index:5,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},InitializeNonceAccount:{index:6,layout:q.struct([q.u32(`instruction`),X(`authorized`)])},AuthorizeNonceAccount:{index:7,layout:q.struct([q.u32(`instruction`),X(`authorized`)])},Allocate:{index:8,layout:q.struct([q.u32(`instruction`),q.ns64(`space`)])},AllocateWithSeed:{index:9,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),q.ns64(`space`),X(`programId`)])},AssignWithSeed:{index:10,layout:q.struct([q.u32(`instruction`),X(`base`),Ir(`seed`),X(`programId`)])},TransferWithSeed:{index:11,layout:q.struct([q.u32(`instruction`),er(`lamports`),Ir(`seed`),X(`programId`)])},UpgradeNonceAccount:{index:12,layout:q.struct([q.u32(`instruction`)])}}),di=class e{constructor(){}static createAccount(e){let t=ui.Create,n=W(t,{lamports:e.lamports,space:e.space,programId:J(e.programId.toBuffer())});return new Z({keys:[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!0,isWritable:!0}],programId:this.programId,data:n})}static transfer(e){let t,n;if(`basePubkey`in e){let r=ui.TransferWithSeed;t=W(r,{lamports:BigInt(e.lamports),seed:e.seed,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.fromPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}else{let r=ui.Transfer;t=W(r,{lamports:BigInt(e.lamports)}),n=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}static assign(e){let t,n;if(`basePubkey`in e){let r=ui.AssignWithSeed;t=W(r,{base:J(e.basePubkey.toBuffer()),seed:e.seed,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let r=ui.Assign;t=W(r,{programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}static createAccountWithSeed(e){let t=ui.CreateWithSeed,n=W(t,{base:J(e.basePubkey.toBuffer()),seed:e.seed,lamports:e.lamports,space:e.space,programId:J(e.programId.toBuffer())}),r=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!1,isWritable:!0}];return e.basePubkey.equals(e.fromPubkey)||r.push({pubkey:e.basePubkey,isSigner:!0,isWritable:!1}),new Z({keys:r,programId:this.programId,data:n})}static createNonceAccount(t){let n=new Q;`basePubkey`in t&&`seed`in t?n.add(e.createAccountWithSeed({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,basePubkey:t.basePubkey,seed:t.seed,lamports:t.lamports,space:ci,programId:this.programId})):n.add(e.createAccount({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,lamports:t.lamports,space:ci,programId:this.programId}));let r={noncePubkey:t.noncePubkey,authorizedPubkey:t.authorizedPubkey};return n.add(this.nonceInitialize(r)),n}static nonceInitialize(e){let t=ui.InitializeNonceAccount,n=W(t,{authorized:J(e.authorizedPubkey.toBuffer())}),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:this.programId,data:n};return new Z(r)}static nonceAdvance(e){let t=ui.AdvanceNonceAccount,n=W(t),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n};return new Z(r)}static nonceWithdraw(e){let t=ui.WithdrawNonceAccount,n=W(t,{lamports:e.lamports});return new Z({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0},{pubkey:ni,isSigner:!1,isWritable:!1},{pubkey:ri,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n})}static nonceAuthorize(e){let t=ui.AuthorizeNonceAccount,n=W(t,{authorized:J(e.newAuthorizedPubkey.toBuffer())});return new Z({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:n})}static allocate(e){let t,n;if(`basePubkey`in e){let r=ui.AllocateWithSeed;t=W(r,{base:J(e.basePubkey.toBuffer()),seed:e.seed,space:e.space,programId:J(e.programId.toBuffer())}),n=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{let r=ui.Allocate;t=W(r,{space:e.space}),n=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Z({keys:n,programId:this.programId,data:t})}},di.programId=new Y(`11111111111111111111111111111111`),fi=932,pi=class e{constructor(){}static getMinNumSignatures(t){return 2*(Math.ceil(t/e.chunkSize)+1+1)}static async load(t,n,r,i,a){{let e=await t.getMinimumBalanceForRentExemption(a.length),o=await t.getAccountInfo(r.publicKey,`confirmed`),s=null;if(o!==null){if(o.executable)return!1;o.data.length!==a.length&&(s||=new Q,s.add(di.allocate({accountPubkey:r.publicKey,space:a.length}))),o.owner.equals(i)||(s||=new Q,s.add(di.assign({accountPubkey:r.publicKey,programId:i}))),o.lamports<e&&(s||=new Q,s.add(di.transfer({fromPubkey:n.publicKey,toPubkey:r.publicKey,lamports:e-o.lamports})))}else s=new Q().add(di.createAccount({fromPubkey:n.publicKey,newAccountPubkey:r.publicKey,lamports:e>0?e:1,space:a.length,programId:i}));s!==null&&await Qn(t,s,[n,r],{commitment:`confirmed`})}let o=q.struct([q.u32(`instruction`),q.u32(`offset`),q.u32(`bytesLength`),q.u32(`bytesLengthPadding`),q.seq(q.u8(`byte`),q.offset(q.u32(),-8),`bytes`)]),s=e.chunkSize,c=0,l=a,u=[];for(;l.length>0;){let e=l.slice(0,s),a=g.alloc(s+16);o.encode({instruction:0,offset:c,bytes:e,bytesLength:0,bytesLengthPadding:0},a);let d=new Q().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0}],programId:i,data:a});u.push(Qn(t,d,[n,r],{commitment:`confirmed`})),t._rpcEndpoint.includes(`solana.com`)&&await $n(250),c+=s,l=l.slice(s)}await Promise.all(u);{let e=q.struct([q.u32(`instruction`)]),a=g.alloc(e.span);e.encode({instruction:1},a);let o=new Q().add({keys:[{pubkey:r.publicKey,isSigner:!0,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:i,data:a}),s=`processed`,c=await t.sendTransaction(o,[n,r],{preflightCommitment:s}),{context:l,value:u}=await t.confirmTransaction({signature:c,lastValidBlockHeight:o.lastValidBlockHeight,blockhash:o.recentBlockhash},s);if(u.err)throw Error(`Transaction ${c} failed (${JSON.stringify(u)})`);for(;;){try{if(await t.getSlot({commitment:s})>l.slot)break}catch{}await new Promise(e=>setTimeout(e,Math.round(ei/2)))}}return!0}},pi.chunkSize=fi,new Y(`BPFLoader2111111111111111111111111111111111`),gi=tr(nr()),_i=32,vi=class{constructor(e,t,n,r,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=n,this.firstNormalEpoch=r,this.firstNormalSlot=i}getEpoch(e){return this.getEpochAndSlotIndex(e)[0]}getEpochAndSlotIndex(e){if(e<this.firstNormalSlot){let t=rr(ir(e+_i+1))-rr(_i)-1;return[t,e-(this.getSlotsInEpoch(t)-_i)]}{let t=e-this.firstNormalSlot,n=Math.floor(t/this.slotsPerEpoch);return[this.firstNormalEpoch+n,t%this.slotsPerEpoch]}}getFirstSlotInEpoch(e){return e<=this.firstNormalEpoch?(2**e-1)*_i:(e-this.firstNormalEpoch)*this.slotsPerEpoch+this.firstNormalSlot}getLastSlotInEpoch(e){return this.getFirstSlotInEpoch(e)+this.getSlotsInEpoch(e)-1}getSlotsInEpoch(e){return e<this.firstNormalEpoch?2**(e+rr(_i)):this.slotsPerEpoch}},yi=globalThis.fetch,bi=class extends Vn{constructor(e,t,n){super(e=>{let n=Rn(e,{autoconnect:!0,max_reconnects:5,reconnect:!0,reconnect_interval:1e3,...t});return`socket`in n?this.underlyingSocket=n.socket:this.underlyingSocket=n,n},e,t,n),this.underlyingSocket=void 0}call(...e){let t=this.underlyingSocket?.readyState;return t===1?super.call(...e):Promise.reject(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(Error("Tried to send a JSON-RPC notification `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+`)`))}},xi=56,Si=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=ar(Ci,e),n=e.length-xi;U(n>=0,`lookup table is invalid`),U(n%32==0,`lookup table is invalid`);let r=n/32,{addresses:i}=q.struct([q.seq(X(),r,`addresses`)]).decode(e.slice(xi));return{deactivationSlot:t.deactivationSlot,lastExtendedSlot:t.lastExtendedSlot,lastExtendedSlotStartIndex:t.lastExtendedStartIndex,authority:t.authority.length===0?void 0:new Y(t.authority[0]),addresses:i.map(e=>new Y(e))}}},Ci={index:1,layout:q.struct([q.u32(`typeIndex`),er(`deactivationSlot`),q.nu64(`lastExtendedSlot`),q.u8(`lastExtendedStartIndex`),q.u8(),q.seq(X(),q.offset(q.u8(),-1),`authority`)])},wi=/^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i,Ti=jt(wt(Y),V(),e=>new Y(e)),Ei=Ot([V(),Tt(`base64`)]),Di=jt(wt(g),Ei,e=>g.from(e[0],`base64`)),Oi=3e4,ki=lr(At()),Ai=H({foundation:z(),foundationTerm:z(),initial:z(),taper:z(),terminal:z()}),ji=K(L(R(H({epoch:z(),effectiveSlot:z(),amount:z(),postBalance:z(),commission:B(R(z()))})))),Mi=L(H({slot:z(),prioritizationFee:z()})),Ni=H({total:z(),validator:z(),foundation:z(),epoch:z()}),Pi=H({epoch:z(),slotIndex:z(),slotsInEpoch:z(),absoluteSlot:z(),blockHeight:B(z()),transactionCount:B(z())}),Fi=H({slotsPerEpoch:z(),leaderScheduleSlotOffset:z(),warmup:Ct(),firstNormalEpoch:z(),firstNormalSlot:z()}),Ii=Dt(V(),L(z())),Li=R(kt([H({}),V()])),Ri=H({err:Li}),zi=Tt(`receivedSignature`),Bi=H({"solana-core":V(),"feature-set":B(z())}),Vi=H({program:V(),programId:Ti,parsed:At()}),Hi=H({programId:Ti,accounts:L(Ti),data:V()}),Ui=ur(H({err:R(kt([H({}),V()])),logs:R(L(V())),accounts:B(R(L(R(H({executable:Ct(),owner:V(),lamports:z(),data:L(V()),rentEpoch:B(z())}))))),unitsConsumed:B(z()),returnData:B(R(H({programId:V(),data:Ot([V(),Tt(`base64`)])}))),innerInstructions:B(R(L(H({index:z(),instructions:L(kt([Vi,Hi]))}))))})),Wi=ur(H({byIdentity:Dt(V(),L(z())),range:H({firstSlot:z(),lastSlot:z()})})),Gi=K(Ai),Ki=K(Ni),qi=K(Mi),Ji=K(Pi),Yi=K(Fi),Xi=K(Ii),Zi=K(z()),Qi=ur(H({total:z(),circulating:z(),nonCirculating:z(),nonCirculatingAccounts:L(Ti)})),$i=H({amount:V(),uiAmount:R(z()),decimals:z(),uiAmountString:B(V())}),ea=ur(L(H({address:Ti,amount:V(),uiAmount:R(z()),decimals:z(),uiAmountString:B(V())}))),ta=ur(L(H({pubkey:Ti,account:H({executable:Ct(),owner:Ti,lamports:z(),data:Di,rentEpoch:z()})}))),na=H({program:V(),parsed:At(),space:z()}),ra=ur(L(H({pubkey:Ti,account:H({executable:Ct(),owner:Ti,lamports:z(),data:na,rentEpoch:z()})}))),ia=ur(L(H({lamports:z(),address:Ti}))),aa=H({executable:Ct(),owner:Ti,lamports:z(),data:Di,rentEpoch:z()}),oa=H({pubkey:Ti,account:aa}),sa=jt(kt([wt(g),na]),kt([Ei,na]),e=>Array.isArray(e)?I(e,Di):e),ca=H({executable:Ct(),owner:Ti,lamports:z(),data:sa,rentEpoch:z()}),la=H({pubkey:Ti,account:ca}),ua=H({state:kt([Tt(`active`),Tt(`inactive`),Tt(`activating`),Tt(`deactivating`)]),active:z(),inactive:z()}),da=K(L(H({signature:V(),slot:z(),err:Li,memo:R(V()),blockTime:B(R(z()))}))),fa=K(L(H({signature:V(),slot:z(),err:Li,memo:R(V()),blockTime:B(R(z()))}))),pa=H({subscription:z(),result:dr(aa)}),ma=H({pubkey:Ti,account:aa}),ha=H({subscription:z(),result:dr(ma)}),ga=H({parent:z(),slot:z(),root:z()}),_a=H({subscription:z(),result:ga}),va=kt([H({type:kt([Tt(`firstShredReceived`),Tt(`completed`),Tt(`optimisticConfirmation`),Tt(`root`)]),slot:z(),timestamp:z()}),H({type:Tt(`createdBank`),parent:z(),slot:z(),timestamp:z()}),H({type:Tt(`frozen`),slot:z(),timestamp:z(),stats:H({numTransactionEntries:z(),numSuccessfulTransactions:z(),numFailedTransactions:z(),maxTransactionsPerEntry:z()})}),H({type:Tt(`dead`),slot:z(),timestamp:z(),err:V()})]),ya=H({subscription:z(),result:va}),ba=H({subscription:z(),result:dr(kt([Ri,zi]))}),xa=H({subscription:z(),result:z()}),Sa=H({pubkey:V(),gossip:R(V()),tpu:R(V()),rpc:R(V()),version:R(V())}),Ca=H({votePubkey:V(),nodePubkey:V(),activatedStake:z(),epochVoteAccount:Ct(),epochCredits:L(Ot([z(),z(),z()])),commission:z(),lastVote:z(),rootSlot:R(z())}),wa=K(H({current:L(Ca),delinquent:L(Ca)})),Ta=kt([Tt(`processed`),Tt(`confirmed`),Tt(`finalized`)]),Ea=H({slot:z(),confirmations:R(z()),err:Li,confirmationStatus:B(Ta)}),Da=ur(L(R(Ea))),Oa=K(z()),ka=H({accountKey:Ti,writableIndexes:L(z()),readonlyIndexes:L(z())}),Aa=H({computeUnitLimit:R(z()),heapSize:R(z()),loadedAccountsDataSizeLimit:R(z()),priorityFee:R(z())}),ja=H({signatures:L(V()),message:H({accountKeys:L(V()),header:H({numRequiredSignatures:z(),numReadonlySignedAccounts:z(),numReadonlyUnsignedAccounts:z()}),instructions:L(H({accounts:L(z()),data:V(),programIdIndex:z()})),recentBlockhash:V(),addressTableLookups:B(L(ka)),transactionConfig:B(R(Aa))})}),Ma=H({pubkey:Ti,signer:Ct(),writable:Ct(),source:B(kt([Tt(`transaction`),Tt(`lookupTable`)]))}),Na=H({accountKeys:L(Ma),signatures:L(V())}),Pa=H({parsed:At(),program:V(),programId:Ti}),Fa=H({accounts:L(Ti),data:V(),programId:Ti}),Ia=kt([Fa,Pa]),La=kt([H({parsed:At(),program:V(),programId:V()}),H({accounts:L(V()),data:V(),programId:V()})]),Ra=jt(Ia,La,e=>`accounts`in e?I(e,Fa):I(e,Pa)),za=H({signatures:L(V()),message:H({accountKeys:L(Ma),instructions:L(Ra),recentBlockhash:V(),addressTableLookups:B(R(L(ka))),transactionConfig:B(R(Aa))})}),Ba=H({accountIndex:z(),mint:V(),owner:B(V()),programId:B(V()),uiTokenAmount:$i}),Va=H({writable:L(Ti),readonly:L(Ti)}),Ha=H({err:Li,fee:z(),innerInstructions:B(R(L(H({index:z(),instructions:L(H({accounts:L(z()),data:V(),programIdIndex:z()}))})))),preBalances:L(z()),postBalances:L(z()),logMessages:B(R(L(V()))),preTokenBalances:B(R(L(Ba))),postTokenBalances:B(R(L(Ba))),loadedAddresses:B(Va),computeUnitsConsumed:B(z()),costUnits:B(z())}),Ua=H({err:Li,fee:z(),innerInstructions:B(R(L(H({index:z(),instructions:L(Ra)})))),preBalances:L(z()),postBalances:L(z()),logMessages:B(R(L(V()))),preTokenBalances:B(R(L(Ba))),postTokenBalances:B(R(L(Ba))),loadedAddresses:B(Va),computeUnitsConsumed:B(z()),costUnits:B(z())}),Wa=kt([Tt(0),Tt(1),Tt(`legacy`)]),Ga=H({pubkey:V(),lamports:z(),postBalance:R(z()),rewardType:R(V()),commission:B(R(z()))}),Ka=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:ja,meta:R(Ha),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),qa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Ja=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:Na,meta:R(Ha),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Ya=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:za,meta:R(Ua),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Xa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:Na,meta:R(Ua),version:B(Wa)})),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Za=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),rewards:B(L(Ga)),blockTime:R(z()),blockHeight:R(z())}))),Qa=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),transactions:L(H({transaction:ja,meta:R(Ha)})),rewards:B(L(Ga)),blockTime:R(z())}))),$a=K(R(H({blockhash:V(),previousBlockhash:V(),parentSlot:z(),signatures:L(V()),blockTime:R(z())}))),eo=K(R(H({slot:z(),meta:R(Ha),blockTime:B(R(z())),transaction:ja,version:B(Wa)}))),to=K(R(H({slot:z(),transaction:za,meta:R(Ua),blockTime:B(R(z())),version:B(Wa)}))),no=ur(H({blockhash:V(),lastValidBlockHeight:z()})),ro=ur(Ct()),io=H({slot:z(),numTransactions:z(),numSlots:z(),samplePeriodSecs:z()}),ao=K(L(io)),oo=ur(R(H({feeCalculator:H({lamportsPerSignature:z()})}))),so=K(V()),co=K(V()),lo=H({err:Li,logs:L(V()),signature:V()}),uo=H({result:dr(lo),subscription:z()}),fo={"solana-client":`js/1.99.0`},po=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 e={};return async t=>{let{commitment:n,config:r}=G(t),i=this._buildArgs([],n,void 0,r),a=gi(i);return e[a]=e[a]??(async()=>{try{let e=I(await this._rpcRequest(`getBlockHeight`,i),K(z()));if(`error`in e)throw new $(e.error,`failed to get block height information`);return e.result}finally{delete e[a]}})(),await e[a]}})();let n,r,i,a,o,s;t&&typeof t==`string`?this._commitment=t:t&&(this._commitment=t.commitment,this._confirmTransactionInitialTimeout=t.confirmTransactionInitialTimeout,n=t.wsEndpoint,r=t.httpHeaders,i=t.fetch,a=t.fetchMiddleware,o=t.disableRetryOnRateLimit,s=t.httpAgent),this._rpcEndpoint=sr(e),this._rpcWsEndpoint=n||or(e),this._rpcClient=pr(e,r,i,a,o,s),this._rpcRequest=mr(this._rpcClient),this._rpcBatchRequest=hr(this._rpcClient),this._rpcWebSocket=new bi(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:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,void 0,r),a=I(await this._rpcRequest(`getBalance`,i),ur(z()));if(`error`in a)throw new $(a.error,`failed to get balance for ${e.toBase58()}`);return a.result}async getBalance(e,t){return await this.getBalanceAndContext(e,t).then(e=>e.value).catch(t=>{throw Error(`failed to get balance of account `+e.toBase58()+`: `+t)})}async getBlockTime(e){let t=I(await this._rpcRequest(`getBlockTime`,[e]),K(R(z())));if(`error`in t)throw new $(t.error,`failed to get block time for slot ${e}`);return t.result}async getMinimumLedgerSlot(){let e=I(await this._rpcRequest(`minimumLedgerSlot`,[]),K(z()));if(`error`in e)throw new $(e.error,`failed to get minimum ledger slot`);return e.result}async getFirstAvailableBlock(){let e=I(await this._rpcRequest(`getFirstAvailableBlock`,[]),Zi);if(`error`in e)throw new $(e.error,`failed to get first available block`);return e.result}async getSupply(e){let t={};t=typeof e==`string`?{commitment:e}:e?{...e,commitment:e&&e.commitment||this.commitment}:{commitment:this.commitment};let n=I(await this._rpcRequest(`getSupply`,[t]),Qi);if(`error`in n)throw new $(n.error,`failed to get supply`);return n.result}async getTokenSupply(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenSupply`,n),ur($i));if(`error`in r)throw new $(r.error,`failed to get token supply`);return r.result}async getTokenAccountBalance(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenAccountBalance`,n),ur($i));if(`error`in r)throw new $(r.error,`failed to get token account balance`);return r.result}async getTokenAccountsByOwner(e,t,n){let{commitment:r,config:i}=G(n),a=[e.toBase58()];`mint`in t?a.push({mint:t.mint.toBase58()}):a.push({programId:t.programId.toBase58()});let o=this._buildArgs(a,r,`base64`,i),s=I(await this._rpcRequest(`getTokenAccountsByOwner`,o),ta);if(`error`in s)throw new $(s.error,`failed to get token accounts owned by account ${e.toBase58()}`);return s.result}async getParsedTokenAccountsByOwner(e,t,n){let r=[e.toBase58()];`mint`in t?r.push({mint:t.mint.toBase58()}):r.push({programId:t.programId.toBase58()});let i=this._buildArgs(r,n,`jsonParsed`),a=I(await this._rpcRequest(`getTokenAccountsByOwner`,i),ra);if(`error`in a)throw new $(a.error,`failed to get token accounts owned by account ${e.toBase58()}`);return a.result}async getLargestAccounts(e){let t={...e,commitment:e&&e.commitment||this.commitment},n=t.filter||t.commitment?[t]:[],r=I(await this._rpcRequest(`getLargestAccounts`,n),ia);if(`error`in r)throw new $(r.error,`failed to get largest accounts`);return r.result}async getTokenLargestAccounts(e,t){let n=this._buildArgs([e.toBase58()],t),r=I(await this._rpcRequest(`getTokenLargestAccounts`,n),ea);if(`error`in r)throw new $(r.error,`failed to get token largest accounts`);return r.result}async getAccountInfoAndContext(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`base64`,r),a=I(await this._rpcRequest(`getAccountInfo`,i),ur(R(aa)));if(`error`in a)throw new $(a.error,`failed to get info about account ${e.toBase58()}`);return a.result}async getParsedAccountInfo(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getAccountInfo`,i),ur(R(ca)));if(`error`in a)throw new $(a.error,`failed to get info about account ${e.toBase58()}`);return a.result}async getAccountInfo(e,t){try{return(await this.getAccountInfoAndContext(e,t)).value}catch(t){throw Error(`failed to get info about account `+e.toBase58()+`: `+t)}}async getMultipleParsedAccounts(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>e.toBase58()),a=this._buildArgs([i],n,`jsonParsed`,r),o=I(await this._rpcRequest(`getMultipleAccounts`,a),ur(L(R(ca))));if(`error`in o)throw new $(o.error,`failed to get info for accounts ${i}`);return o.result}async getMultipleAccountsInfoAndContext(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>e.toBase58()),a=this._buildArgs([i],n,`base64`,r),o=I(await this._rpcRequest(`getMultipleAccounts`,a),ur(L(R(aa))));if(`error`in o)throw new $(o.error,`failed to get info for accounts ${i}`);return o.result}async getMultipleAccountsInfo(e,t){return(await this.getMultipleAccountsInfoAndContext(e,t)).value}async getStakeActivation(e,t,n){let{commitment:r,config:i}=G(t),a=this._buildArgs([e.toBase58()],r,void 0,{...i,epoch:n??i?.epoch}),o=I(await this._rpcRequest(`getStakeActivation`,a),K(ua));if(`error`in o)throw new $(o.error,`failed to get Stake Activation ${e.toBase58()}`);return o.result}async getProgramAccounts(e,t){let{commitment:n,config:r}=G(t),{encoding:i,...a}=r||{},o=this._buildArgs([e.toBase58()],n,i||`base64`,{...a,...a.filters?{filters:cr(a.filters)}:null}),s=await this._rpcRequest(`getProgramAccounts`,o),c=L(oa),l=a.withContext===!0?I(s,ur(c)):I(s,K(c));if(`error`in l)throw new $(l.error,`failed to get accounts owned by program ${e.toBase58()}`);return l.result}async getParsedProgramAccounts(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e.toBase58()],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getProgramAccounts`,i),K(L(la)));if(`error`in a)throw new $(a.error,`failed to get accounts owned by program ${e.toBase58()}`);return a.result}async confirmTransaction(e,t){let n;if(typeof e==`string`)n=e;else{let t=e;if(t.abortSignal?.aborted)return Promise.reject(t.abortSignal.reason);n=t.signature}let r;try{r=vr.default.decode(n)}catch{throw Error(`signature must be base58 encoded: `+n)}return U(r.length===64,`signature has invalid length`),typeof e==`string`?await this.confirmTransactionUsingLegacyTimeoutStrategy({commitment:t||this.commitment,signature:n}):`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,n)=>{e!=null&&(e.aborted?n(e.reason):e.addEventListener(`abort`,()=>{n(e.reason)}))})}getTransactionConfirmationPromise({commitment:e,signature:t}){let n,r,i=!1;return{abortConfirmation:()=>{r&&=(r(),void 0),n!=null&&(this.removeSignatureListener(n),n=void 0)},confirmationPromise:new Promise((a,o)=>{try{n=this.onSignature(t,(e,t)=>{n=void 0;let r={context:t,value:e};a({__type:Zr.PROCESSED,response:r})},e);let s=new Promise(e=>{n==null?e():r=this._onSubscriptionStateChange(n,t=>{t===`subscribed`&&e()})});(async()=>{if(await s,i)return;let n=await this.getSignatureStatus(t);if(i||n==null)return;let{context:r,value:c}=n;if(c!=null){if(c?.err)o(c.err);else{switch(e){case`confirmed`:case`single`:case`singleGossip`:if(c.confirmationStatus===`processed`)return;break;case`finalized`:case`max`:case`root`:if(c.confirmationStatus===`processed`||c.confirmationStatus===`confirmed`)return}i=!0,a({__type:Zr.PROCESSED,response:{context:r,value:c}})}}})()}catch(e){o(e)}})}}async confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:e,strategy:{abortSignal:t,lastValidBlockHeight:n,signature:r}}){let i=!1,a=new Promise(t=>{let r=async()=>{try{return await this.getBlockHeight(e)}catch{return-1}};(async()=>{let e=await r();if(!i){for(;e<=n;)if(await $n(1e3),i||(e=await r(),i))return;t({__type:Zr.BLOCKHEIGHT_EXCEEDED})}})()}),{abortConfirmation:o,confirmationPromise:s}=this.getTransactionConfirmationPromise({commitment:e,signature:r}),c=this.getCancellationPromise(t),l;try{let e=await Promise.race([c,s,a]);if(e.__type===Zr.PROCESSED)l=e.response;else throw new jr(r)}finally{i=!0,o()}return l}async confirmTransactionUsingDurableNonceStrategy({commitment:e,strategy:{abortSignal:t,minContextSlot:n,nonceAccountPubkey:r,nonceValue:i,signature:a}}){let o=!1,s=new Promise(t=>{let a=i,s=null,c=async()=>{try{let{context:t,value:i}=await this.getNonceAndContext(r,{commitment:e,minContextSlot:n});return s=t.slot,i?.nonce}catch{return a}};(async()=>{if(a=await c(),!o)for(;;){if(i!==a){t({__type:Zr.NONCE_INVALID,slotInWhichNonceDidAdvance:s});return}if(await $n(2e3),o||(a=await c(),o))return}})()}),{abortConfirmation:c,confirmationPromise:l}=this.getTransactionConfirmationPromise({commitment:e,signature:a}),u=this.getCancellationPromise(t),d;try{let t=await Promise.race([u,l,s]);if(t.__type===Zr.PROCESSED)d=t.response;else{let r;for(;;){let e=await this.getSignatureStatus(a);if(e==null)break;if(e.context.slot<(t.slotInWhichNonceDidAdvance??n)){await $n(400);continue}r=e;break}if(r?.value){let t=e||`finalized`,{confirmationStatus:n}=r.value;switch(t){case`processed`:case`recent`:if(n!==`processed`&&n!==`confirmed`&&n!==`finalized`)throw new Nr(a);break;case`confirmed`:case`single`:case`singleGossip`:if(n!==`confirmed`&&n!==`finalized`)throw new Nr(a);break;case`finalized`:case`max`:case`root`:if(n!==`finalized`)throw new Nr(a)}d={context:r.context,value:{err:r.value.err}}}else throw new Nr(a)}}finally{o=!0,c()}return d}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:e,signature:t}){let n,r=new Promise(t=>{let r=this._confirmTransactionInitialTimeout||6e4;switch(e){case`processed`:case`recent`:case`single`:case`confirmed`:case`singleGossip`:r=this._confirmTransactionInitialTimeout||3e4}n=setTimeout(()=>t({__type:Zr.TIMED_OUT,timeoutMs:r}),r)}),{abortConfirmation:i,confirmationPromise:a}=this.getTransactionConfirmationPromise({commitment:e,signature:t}),o;try{let e=await Promise.race([a,r]);if(e.__type===Zr.PROCESSED)o=e.response;else throw new Mr(t,e.timeoutMs/1e3)}finally{clearTimeout(n),i()}return o}async getClusterNodes(){let e=I(await this._rpcRequest(`getClusterNodes`,[]),K(L(Sa)));if(`error`in e)throw new $(e.error,`failed to get cluster nodes`);return e.result}async getVoteAccounts(e){let t=this._buildArgs([],e),n=I(await this._rpcRequest(`getVoteAccounts`,t),wa);if(`error`in n)throw new $(n.error,`failed to get vote accounts`);return n.result}async getSlot(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getSlot`,r),K(z()));if(`error`in i)throw new $(i.error,`failed to get slot`);return i.result}async getSlotLeader(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getSlotLeader`,r),K(V()));if(`error`in i)throw new $(i.error,`failed to get slot leader`);return i.result}async getSlotLeaders(e,t){let n=[e,t],r=I(await this._rpcRequest(`getSlotLeaders`,n),K(L(Ti)));if(`error`in r)throw new $(r.error,`failed to get slot leaders`);return r.result}async getSignatureStatus(e,t){let{context:n,value:r}=await this.getSignatureStatuses([e],t);return U(r.length===1),{context:n,value:r[0]}}async getSignatureStatuses(e,t){let n=[e];t&&n.push(t);let r=I(await this._rpcRequest(`getSignatureStatuses`,n),Da);if(`error`in r)throw new $(r.error,`failed to get signature status`);return r.result}async getTransactionCount(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getTransactionCount`,r),K(z()));if(`error`in i)throw new $(i.error,`failed to get transaction count`);return i.result}async getTotalSupply(e){return(await this.getSupply({commitment:e,excludeNonCirculatingAccountsList:!0})).value.total}async getInflationGovernor(e){let t=this._buildArgs([],e),n=I(await this._rpcRequest(`getInflationGovernor`,t),Gi);if(`error`in n)throw new $(n.error,`failed to get inflation`);return n.result}async getInflationReward(e,t,n){let{commitment:r,config:i}=G(n),a=this._buildArgs([e.map(e=>e.toBase58())],r,void 0,{...i,epoch:t??i?.epoch}),o=I(await this._rpcRequest(`getInflationReward`,a),ji);if(`error`in o)throw new $(o.error,`failed to get inflation reward`);return o.result}async getInflationRate(){let e=I(await this._rpcRequest(`getInflationRate`,[]),Ki);if(`error`in e)throw new $(e.error,`failed to get inflation rate`);return e.result}async getEpochInfo(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getEpochInfo`,r),Ji);if(`error`in i)throw new $(i.error,`failed to get epoch info`);return i.result}async getEpochSchedule(){let e=I(await this._rpcRequest(`getEpochSchedule`,[]),Yi);if(`error`in e)throw new $(e.error,`failed to get epoch schedule`);let t=e.result;return new vi(t.slotsPerEpoch,t.leaderScheduleSlotOffset,t.warmup,t.firstNormalEpoch,t.firstNormalSlot)}async getLeaderSchedule(){let e=I(await this._rpcRequest(`getLeaderSchedule`,[]),Xi);if(`error`in e)throw new $(e.error,`failed to get leader schedule`);return e.result}async getMinimumBalanceForRentExemption(e,t){let n=this._buildArgs([e],t),r=I(await this._rpcRequest(`getMinimumBalanceForRentExemption`,n),Oa);return`error`in r?0:r.result}async getRecentBlockhashAndContext(e){let{context:t,value:{blockhash:n}}=await this.getLatestBlockhashAndContext(e);return{context:t,value:{blockhash:n,feeCalculator:{get lamportsPerSignature(){throw Error("The capability to fetch `lamportsPerSignature` using the `getRecentBlockhash` API is no longer offered by the network. Use the `getFeeForMessage` API to obtain the fee for a given message.")},toJSON(){return{}}}}}}async getRecentPerformanceSamples(e){let t=I(await this._rpcRequest(`getRecentPerformanceSamples`,e?[e]:[]),ao);if(`error`in t)throw new $(t.error,`failed to get recent performance samples`);return t.result}async getFeeCalculatorForBlockhash(e,t){let n=this._buildArgs([e],t),r=I(await this._rpcRequest(`getFeeCalculatorForBlockhash`,n),oo);if(`error`in r)throw new $(r.error,`failed to get fee calculator`);let{context:i,value:a}=r.result;return{context:i,value:a===null?null:a.feeCalculator}}async getFeeForMessage(e,t){let n=J(e.serialize()).toString(`base64`),r=this._buildArgs([n],t),i=I(await this._rpcRequest(`getFeeForMessage`,r),ur(R(z())));if(`error`in i)throw new $(i.error,`failed to get fee for message`);if(i.result===null)throw Error(`invalid blockhash`);return i.result}async getRecentPrioritizationFees(e){let t=e?.lockedWritableAccounts?.map(e=>e.toBase58()),n=t?.length?[t]:[],r=I(await this._rpcRequest(`getRecentPrioritizationFees`,n),qi);if(`error`in r)throw new $(r.error,`failed to get recent prioritization fees`);return r.result}async getRecentBlockhash(e){try{return(await this.getRecentBlockhashAndContext(e)).value}catch(e){throw Error(`failed to get recent blockhash: `+e)}}async getLatestBlockhash(e){try{return(await this.getLatestBlockhashAndContext(e)).value}catch(e){throw Error(`failed to get recent blockhash: `+e)}}async getLatestBlockhashAndContext(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,void 0,n),i=I(await this._rpcRequest(`getLatestBlockhash`,r),no);if(`error`in i)throw new $(i.error,`failed to get latest blockhash`);return i.result}async isBlockhashValid(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgs([e],n,void 0,r),a=I(await this._rpcRequest(`isBlockhashValid`,i),ro);if(`error`in a)throw new $(a.error,"failed to determine if the blockhash `"+e+"`is valid");return a.result}async getVersion(){let e=I(await this._rpcRequest(`getVersion`,[]),K(Bi));if(`error`in e)throw new $(e.error,`failed to get version`);return e.result}async getGenesisHash(){let e=I(await this._rpcRequest(`getGenesisHash`,[]),K(V()));if(`error`in e)throw new $(e.error,`failed to get genesis hash`);return e.result}async getBlock(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,void 0,r),a=await this._rpcRequest(`getBlock`,i);try{switch(r?.transactionDetails){case`accounts`:{let e=I(a,Ja);if(`error`in e)throw e.error;return e.result}case`none`:{let e=I(a,qa);if(`error`in e)throw e.error;return e.result}default:{let e=I(a,Ka);if(`error`in e)throw e.error;let{result:t}=e;return t?{...t,transactions:t.transactions.map(({transaction:e,meta:t,version:n})=>({meta:t,transaction:{...e,message:fr(n,e.message)},version:n}))}:null}}}catch(e){throw new $(e,`failed to get confirmed block`)}}async getParsedBlock(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r),a=await this._rpcRequest(`getBlock`,i);try{switch(r?.transactionDetails){case`accounts`:{let e=I(a,Xa);if(`error`in e)throw e.error;return e.result}case`none`:{let e=I(a,Za);if(`error`in e)throw e.error;return e.result}default:{let e=I(a,Ya);if(`error`in e)throw e.error;return e.result}}}catch(e){throw new $(e,`failed to get block`)}}async getBlockProduction(e){let t,n;if(typeof e==`string`)n=e;else if(e){let{commitment:r,...i}=e;n=r,t=i}let r=this._buildArgs([],n,`base64`,t),i=I(await this._rpcRequest(`getBlockProduction`,r),Wi);if(`error`in i)throw new $(i.error,`failed to get block production information`);return i.result}async getTransaction(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,void 0,r),a=I(await this._rpcRequest(`getTransaction`,i),eo);if(`error`in a)throw new $(a.error,`failed to get transaction`);let o=a.result;return o&&{...o,transaction:{...o.transaction,message:fr(o.version,o.transaction.message)}}}async getParsedTransaction(e,t){let{commitment:n,config:r}=G(t),i=this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r),a=I(await this._rpcRequest(`getTransaction`,i),to);if(`error`in a)throw new $(a.error,`failed to get transaction`);return a.result}async getParsedTransactions(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],n,`jsonParsed`,r)}));return(await this._rpcBatchRequest(i)).map(e=>{let t=I(e,to);if(`error`in t)throw new $(t.error,`failed to get transactions`);return t.result})}async getTransactions(e,t){let{commitment:n,config:r}=G(t),i=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],n,void 0,r)}));return(await this._rpcBatchRequest(i)).map(e=>{let t=I(e,eo);if(`error`in t)throw new $(t.error,`failed to get transactions`);let n=t.result;return n&&{...n,transaction:{...n.transaction,message:fr(n.version,n.transaction.message)}}})}async getConfirmedBlock(e,t){let n=this._buildArgsAtLeastConfirmed([e],t),r=I(await this._rpcRequest(`getBlock`,n),Qa);if(`error`in r)throw new $(r.error,`failed to get confirmed block`);let i=r.result;if(!i)throw Error(`Confirmed block `+e+` not found`);let a={...i,transactions:i.transactions.map(({transaction:e,meta:t})=>{let n=new Ur(e.message);return{meta:t,transaction:{...e,message:n}}})};return{...a,transactions:a.transactions.map(({transaction:e,meta:t})=>({meta:t,transaction:Q.populate(e.message,e.signatures)}))}}async getBlocks(e,t,n){let r=this._buildArgsAtLeastConfirmed(t===void 0?[e]:[e,t],n),i=I(await this._rpcRequest(`getBlocks`,r),K(L(z())));if(`error`in i)throw new $(i.error,`failed to get blocks`);return i.result}async getBlockSignatures(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:`signatures`,rewards:!1}),r=I(await this._rpcRequest(`getBlock`,n),$a);if(`error`in r)throw new $(r.error,`failed to get block`);let i=r.result;if(!i)throw Error(`Block `+e+` not found`);return i}async getConfirmedBlockSignatures(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,void 0,{transactionDetails:`signatures`,rewards:!1}),r=I(await this._rpcRequest(`getBlock`,n),$a);if(`error`in r)throw new $(r.error,`failed to get confirmed block`);let i=r.result;if(!i)throw Error(`Confirmed block `+e+` not found`);return i}async getConfirmedTransaction(e,t){let n=this._buildArgsAtLeastConfirmed([e],t),r=I(await this._rpcRequest(`getTransaction`,n),eo);if(`error`in r)throw new $(r.error,`failed to get transaction`);let i=r.result;if(!i)return i;let a=new Ur(i.transaction.message),o=i.transaction.signatures;return{...i,transaction:Q.populate(a,o)}}async getParsedConfirmedTransaction(e,t){let n=this._buildArgsAtLeastConfirmed([e],t,`jsonParsed`),r=I(await this._rpcRequest(`getTransaction`,n),to);if(`error`in r)throw new $(r.error,`failed to get confirmed transaction`);return r.result}async getParsedConfirmedTransactions(e,t){let n=e.map(e=>({methodName:`getTransaction`,args:this._buildArgsAtLeastConfirmed([e],t,`jsonParsed`)}));return(await this._rpcBatchRequest(n)).map(e=>{let t=I(e,to);if(`error`in t)throw new $(t.error,`failed to get confirmed transactions`);return t.result})}async getConfirmedSignaturesForAddress(e,t,n){let r={},i=await this.getFirstAvailableBlock();for(;!(`until`in r)&&(t--,!(t<=0||t<i));)try{let e=await this.getConfirmedBlockSignatures(t,`finalized`);e.signatures.length>0&&(r.until=e.signatures[e.signatures.length-1].toString())}catch(e){if(e instanceof Error&&e.message.includes(`skipped`))continue;throw e}let a=await this.getSlot(`finalized`);for(;!(`before`in r)&&(n++,!(n>a));)try{let e=await this.getConfirmedBlockSignatures(n);e.signatures.length>0&&(r.before=e.signatures[e.signatures.length-1].toString())}catch(e){if(e instanceof Error&&e.message.includes(`skipped`))continue;throw e}return(await this.getConfirmedSignaturesForAddress2(e,r)).map(e=>e.signature)}async getConfirmedSignaturesForAddress2(e,t,n){let r=this._buildArgsAtLeastConfirmed([e.toBase58()],n,void 0,t),i=I(await this._rpcRequest(`getConfirmedSignaturesForAddress2`,r),da);if(`error`in i)throw new $(i.error,`failed to get confirmed signatures for address`);return i.result}async getSignaturesForAddress(e,t,n){let r=this._buildArgsAtLeastConfirmed([e.toBase58()],n,void 0,t),i=I(await this._rpcRequest(`getSignaturesForAddress`,r),fa);if(`error`in i)throw new $(i.error,`failed to get signatures for address`);return i.result}async getAddressLookupTable(e,t){let{context:n,value:r}=await this.getAccountInfoAndContext(e,t),i=null;return r!==null&&(i=new Si({key:e,state:Si.deserialize(r.data)})),{context:n,value:i}}async getNonceAndContext(e,t){let{context:n,value:r}=await this.getAccountInfoAndContext(e,t),i=null;return r!==null&&(i=li.fromAccountData(r.data)),{context:n,value:i}}async getNonce(e,t){return await this.getNonceAndContext(e,t).then(e=>e.value).catch(t=>{throw Error(`failed to get nonce for account `+e.toBase58()+`: `+t)})}async requestAirdrop(e,t){let n=I(await this._rpcRequest(`requestAirdrop`,[e.toBase58(),t]),so);if(`error`in n)throw new $(n.error,`airdrop to ${e.toBase58()} failed`);return n.result}async _blockhashWithExpiryBlockHeight(e){if(!e){for(;this._pollingBlockhash;)await $n(100);let e=Date.now()-this._blockhashInfo.lastFetch>=Oi;if(this._blockhashInfo.latestBlockhash!==null&&!e)return this._blockhashInfo.latestBlockhash}return await this._pollNewBlockhash()}async _pollNewBlockhash(){this._pollingBlockhash=!0;try{let e=Date.now(),t=this._blockhashInfo.latestBlockhash,n=t?t.blockhash:null;for(let e=0;e<50;e++){let e=await this.getLatestBlockhash(`finalized`);if(n!==e.blockhash)return this._blockhashInfo={latestBlockhash:e,lastFetch:Date.now(),transactionSignatures:[],simulatedSignatures:[]},e;await $n(ei/2)}throw Error(`Unable to obtain a new blockhash after ${Date.now()-e}ms`)}finally{this._pollingBlockhash=!1}}async getStakeMinimumDelegation(e){let{commitment:t,config:n}=G(e),r=this._buildArgs([],t,`base64`,n),i=I(await this._rpcRequest(`getStakeMinimumDelegation`,r),ur(z()));if(`error`in i)throw new $(i.error,`failed to get stake minimum delegation`);return i.result}async simulateTransaction(e,t,n){if(`message`in e){let r=e.serialize(),i=g.from(r).toString(`base64`);if(Array.isArray(t)||n!==void 0)throw Error(`Invalid arguments`);let a=t||{};a.encoding=`base64`,`commitment`in a||(a.commitment=this.commitment),t&&typeof t==`object`&&`innerInstructions`in t&&(a.innerInstructions=t.innerInstructions);let o=[i,a],s=I(await this._rpcRequest(`simulateTransaction`,o),Ui);if(`error`in s)throw Error(`failed to simulate transaction: `+s.error.message);return s.result}let r;if(e instanceof Q){let t=e;r=new Q,r.feePayer=t.feePayer,r.instructions=e.instructions,r.nonceInfo=t.nonceInfo,r.signatures=t.signatures}else r=Q.populate(e),r._message=r._json=void 0;if(t!==void 0&&!Array.isArray(t))throw Error(`Invalid arguments`);let i=t;if(r.nonceInfo&&i)r.sign(...i);else{let e=this._disableBlockhashCaching;for(;;){let t=await this._blockhashWithExpiryBlockHeight(e);if(r.lastValidBlockHeight=t.lastValidBlockHeight,r.recentBlockhash=t.blockhash,!i)break;if(r.sign(...i),!r.signature)throw Error(`!signature`);let n=r.signature.toString(`base64`);if(!this._blockhashInfo.simulatedSignatures.includes(n)&&!this._blockhashInfo.transactionSignatures.includes(n)){this._blockhashInfo.simulatedSignatures.push(n);break}e=!0}}let a=r._compile(),o=a.serialize(),s=r._serialize(o).toString(`base64`),c={encoding:`base64`,commitment:this.commitment};n&&(c.accounts={encoding:`base64`,addresses:(Array.isArray(n)?n:a.nonProgramIds()).map(e=>e.toBase58())}),i&&(c.sigVerify=!0),t&&typeof t==`object`&&`innerInstructions`in t&&(c.innerInstructions=t.innerInstructions);let l=[s,c],u=I(await this._rpcRequest(`simulateTransaction`,l),Ui);if(`error`in u){let e;throw`data`in u.error&&(e=u.error.data.logs,e&&Array.isArray(e))&&``+e.join(`
|
|
2
|
+
`),new ai({action:`simulate`,signature:``,transactionMessage:u.error.message,logs:e})}return u.result}async sendTransaction(e,t,n){if(`version`in e){if(t&&Array.isArray(t))throw Error(`Invalid arguments`);let n=e.serialize();return await this.sendRawTransaction(n,t)}if(t===void 0||!Array.isArray(t))throw Error(`Invalid arguments`);let r=t;if(e.nonceInfo)e.sign(...r);else{let t=this._disableBlockhashCaching;for(;;){let n=await this._blockhashWithExpiryBlockHeight(t);if(e.lastValidBlockHeight=n.lastValidBlockHeight,e.recentBlockhash=n.blockhash,e.sign(...r),!e.signature)throw Error(`!signature`);let i=e.signature.toString(`base64`);if(this._blockhashInfo.transactionSignatures.includes(i))t=!0;else{this._blockhashInfo.transactionSignatures.push(i);break}}}let i=e.serialize();return await this.sendRawTransaction(i,n)}async sendRawTransaction(e,t){let n=J(e).toString(`base64`);return await this.sendEncodedTransaction(n,t)}async sendEncodedTransaction(e,t){let n={encoding:`base64`},r=t&&t.skipPreflight,i=r===!0?`processed`:t&&t.preflightCommitment||this.commitment;t&&t.maxRetries!=null&&(n.maxRetries=t.maxRetries),t&&t.minContextSlot!=null&&(n.minContextSlot=t.minContextSlot),r&&(n.skipPreflight=r),i&&(n.preflightCommitment=i);let a=[e,n],o=I(await this._rpcRequest(`sendTransaction`,a),co);if(`error`in o){let e;throw`data`in o.error&&(e=o.error.data.logs),new ai({action:r?`send`:`simulate`,signature:``,transactionMessage:o.error.message,logs:e})}return o.result}_wsOnOpen(){this._rpcWebSocketConnected=!0,this._rpcWebSocketHeartbeat=setInterval(()=>{(async()=>{try{await this._rpcWebSocket.notify(`ping`)}catch{}})()},5e3),this._updateSubscriptions()}_wsOnError(e){this._rpcWebSocketConnected=!1}_wsOnClose(e){if(this._rpcWebSocketConnected=!1,this._rpcWebSocketGeneration=(this._rpcWebSocketGeneration+1)%(2**53-1),this._rpcWebSocketIdleTimeout&&=(clearTimeout(this._rpcWebSocketIdleTimeout),null),this._rpcWebSocketHeartbeat&&=(clearInterval(this._rpcWebSocketHeartbeat),null),e===1e3){this._updateSubscriptions();return}this._subscriptionCallbacksByServerSubscriptionId={},Object.entries(this._subscriptionsByHash).forEach(([e,t])=>{this._setSubscription(e,{...t,state:`pending`})})}_setSubscription(e,t){let n=this._subscriptionsByHash[e]?.state;if(this._subscriptionsByHash[e]=t,n!==t.state){let n=this._subscriptionStateChangeCallbacksByHash[e];n&&n.forEach(e=>{try{e(t.state)}catch{}})}}_onSubscriptionStateChange(e,t){let n=this._subscriptionHashByClientSubscriptionId[e];if(n==null)return()=>{};let r=this._subscriptionStateChangeCallbacksByHash[n]||=new Set;return r.add(t),()=>{r.delete(t),r.size===0&&delete this._subscriptionStateChangeCallbacksByHash[n]}}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(e){e instanceof Error}},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 e=>{let n=this._subscriptionsByHash[e];if(n!==void 0)switch(n.state){case`pending`:case`unsubscribed`:if(n.callbacks.size===0){delete this._subscriptionsByHash[e],n.state===`unsubscribed`&&delete this._subscriptionCallbacksByServerSubscriptionId[n.serverSubscriptionId],await this._updateSubscriptions();return}await(async()=>{let{args:r,method:i}=n;try{this._setSubscription(e,{...n,state:`subscribing`});let t=await this._rpcWebSocket.call(i,r);this._setSubscription(e,{...n,serverSubscriptionId:t,state:`subscribed`}),this._subscriptionCallbacksByServerSubscriptionId[t]=n.callbacks,await this._updateSubscriptions()}catch{if(!t())return;this._setSubscription(e,{...n,state:`pending`}),await this._updateSubscriptions()}})();break;case`subscribed`:n.callbacks.size===0&&await(async()=>{let{serverSubscriptionId:r,unsubscribeMethod:i}=n;if(this._subscriptionsAutoDisposedByRpc.has(r))this._subscriptionsAutoDisposedByRpc.delete(r);else{this._setSubscription(e,{...n,state:`unsubscribing`}),this._setSubscription(e,{...n,state:`unsubscribing`});try{await this._rpcWebSocket.call(i,[r])}catch(r){if(r instanceof Error,!t())return;this._setSubscription(e,{...n,state:`subscribed`}),await this._updateSubscriptions();return}}this._setSubscription(e,{...n,state:`unsubscribed`}),await this._updateSubscriptions()})()}}))}_handleServerNotification(e,t){let n=this._subscriptionCallbacksByServerSubscriptionId[e];n!==void 0&&n.forEach(e=>{try{e(...t)}catch{}})}_wsOnAccountNotification(e){let{result:t,subscription:n}=I(e,pa);this._handleServerNotification(n,[t.value,t.context])}_makeSubscription(e,t){let n=this._nextClientSubscriptionId++,r=gi([e.method,t]),i=this._subscriptionsByHash[r];return i===void 0?this._subscriptionsByHash[r]={...e,args:t,callbacks:new Set([e.callback]),state:`pending`}:i.callbacks.add(e.callback),this._subscriptionHashByClientSubscriptionId[n]=r,this._subscriptionDisposeFunctionsByClientSubscriptionId[n]=async()=>{delete this._subscriptionDisposeFunctionsByClientSubscriptionId[n],delete this._subscriptionHashByClientSubscriptionId[n];let t=this._subscriptionsByHash[r];U(t!==void 0,`Could not find a \`Subscription\` when tearing down client subscription #${n}`),t.callbacks.delete(e.callback),await this._updateSubscriptions()},this._updateSubscriptions(),n}onAccountChange(e,t,n){let{commitment:r,config:i}=G(n),a=this._buildArgs([e.toBase58()],r||this._commitment||`finalized`,`base64`,i);return this._makeSubscription({callback:t,method:`accountSubscribe`,unsubscribeMethod:`accountUnsubscribe`},a)}async removeAccountChangeListener(e){await this._unsubscribeClientSubscription(e,`account change`)}_wsOnProgramAccountNotification(e){let{result:t,subscription:n}=I(e,ha);this._handleServerNotification(n,[{accountId:t.value.pubkey,accountInfo:t.value.account},t.context])}onProgramAccountChange(e,t,n,r){let{commitment:i,config:a}=G(n),o=this._buildArgs([e.toBase58()],i||this._commitment||`finalized`,`base64`,a||(r?{filters:cr(r)}:void 0));return this._makeSubscription({callback:t,method:`programSubscribe`,unsubscribeMethod:`programUnsubscribe`},o)}async removeProgramAccountChangeListener(e){await this._unsubscribeClientSubscription(e,`program account change`)}onLogs(e,t,n){let r=this._buildArgs([typeof e==`object`?{mentions:[e.toString()]}:e],n||this._commitment||`finalized`);return this._makeSubscription({callback:t,method:`logsSubscribe`,unsubscribeMethod:`logsUnsubscribe`},r)}async removeOnLogsListener(e){await this._unsubscribeClientSubscription(e,`logs`)}_wsOnLogsNotification(e){let{result:t,subscription:n}=I(e,uo);this._handleServerNotification(n,[t.value,t.context])}_wsOnSlotNotification(e){let{result:t,subscription:n}=I(e,_a);this._handleServerNotification(n,[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:n}=I(e,ya);this._handleServerNotification(n,[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 n=this._subscriptionDisposeFunctionsByClientSubscriptionId[e];n&&await n()}_buildArgs(e,t,n,r){let i=t||this._commitment;if(i||n||r){let t={};n&&(t.encoding=n),i&&(t.commitment=i),r&&(t=Object.assign(t,r)),e.push(t)}return e}_buildArgsAtLeastConfirmed(e,t,n,r){let i=t||this._commitment;if(i&&![`confirmed`,`finalized`].includes(i))throw Error("Using Connection with default commitment: `"+this._commitment+"`, but method requires at least `confirmed`");return this._buildArgs(e,t,n,r)}_wsOnSignatureNotification(e){let{result:t,subscription:n}=I(e,ba);t.value!==`receivedSignature`&&this._subscriptionsAutoDisposedByRpc.add(n),this._handleServerNotification(n,t.value===`receivedSignature`?[{type:`received`},t.context]:[{type:`status`,result:t.value},t.context])}onSignature(e,t,n){let r=this._buildArgs([e],n||this._commitment||`finalized`),i=this._makeSubscription({callback:(e,n)=>{if(e.type===`status`){t(e.result,n);try{this.removeSignatureListener(i)}catch{}}},method:`signatureSubscribe`,unsubscribeMethod:`signatureUnsubscribe`},r);return i}onSignatureWithOptions(e,t,n){let{commitment:r,...i}={...n,commitment:n&&n.commitment||this._commitment||`finalized`},a=this._buildArgs([e],r,void 0,i),o=this._makeSubscription({callback:(e,n)=>{t(e,n);try{this.removeSignatureListener(o)}catch{}},method:`signatureSubscribe`,unsubscribeMethod:`signatureUnsubscribe`},a);return o}async removeSignatureListener(e){await this._unsubscribeClientSubscription(e,`signature result`)}_wsOnRootNotification(e){let{result:t,subscription:n}=I(e,xa);this._handleServerNotification(n,[t])}onRootChange(e){return this._makeSubscription({callback:e,method:`rootSubscribe`,unsubscribeMethod:`rootUnsubscribe`},[])}async removeRootChangeListener(e){await this._unsubscribeClientSubscription(e,`root change`)}},mo=class e{constructor(e){this._keypair=void 0,this._keypair=e??Sr()}static generate(){return new e(Sr())}static fromSecretKey(t,n){if(t.byteLength!==64)throw Error(`bad secret key size`);let r=t.slice(32,64);if(!n||!n.skipValidation){let e=t.slice(0,32),n=Cr(e);for(let e=0;e<32;e++)if(r[e]!==n[e])throw Error(`provided secretKey is invalid`)}return new e({publicKey:r,secretKey:t})}static fromSeed(t){let n=Cr(t),r=new Uint8Array(64);return r.set(t),r.set(n,32),new e({publicKey:n,secretKey:r})}get publicKey(){return new Y(this._keypair.publicKey)}get secretKey(){return new Uint8Array(this._keypair.secretKey)}},ho=Object.freeze({CreateLookupTable:{index:0,layout:q.struct([q.u32(`instruction`),er(`recentSlot`),q.u8(`bumpSeed`)])},FreezeLookupTable:{index:1,layout:q.struct([q.u32(`instruction`)])},ExtendLookupTable:{index:2,layout:q.struct([q.u32(`instruction`),er(),q.seq(X(),q.offset(q.u32(),-8),`addresses`)])},DeactivateLookupTable:{index:3,layout:q.struct([q.u32(`instruction`)])},CloseLookupTable:{index:4,layout:q.struct([q.u32(`instruction`)])}}),go=class{constructor(){}static createLookupTable(e){let[t,n]=Y.findProgramAddressSync([e.authority.toBuffer(),at().encode(e.recentSlot)],this.programId),r=ho.CreateLookupTable,i=W(r,{recentSlot:BigInt(e.recentSlot),bumpSeed:n}),a=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:di.programId,isSigner:!1,isWritable:!1}];return[new Z({programId:this.programId,keys:a,data:i}),t]}static freezeLookupTable(e){let t=ho.FreezeLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new Z({programId:this.programId,keys:r,data:n})}static extendLookupTable(e){let t=ho.ExtendLookupTable,n=W(t,{addresses:e.addresses.map(e=>e.toBytes())}),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return e.payer&&r.push({pubkey:e.payer,isSigner:!0,isWritable:!0},{pubkey:di.programId,isSigner:!1,isWritable:!1}),new Z({programId:this.programId,keys:r,data:n})}static deactivateLookupTable(e){let t=ho.DeactivateLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1}];return new Z({programId:this.programId,keys:r,data:n})}static closeLookupTable(e){let t=ho.CloseLookupTable,n=W(t),r=[{pubkey:e.lookupTable,isSigner:!1,isWritable:!0},{pubkey:e.authority,isSigner:!0,isWritable:!1},{pubkey:e.recipient,isSigner:!1,isWritable:!0}];return new Z({programId:this.programId,keys:r,data:n})}},go.programId=new Y(`AddressLookupTab1e1111111111111111111111111`),_o=Object.freeze({RequestUnits:{index:0,layout:q.struct([q.u8(`instruction`),q.u32(`units`),q.u32(`additionalFee`)])},RequestHeapFrame:{index:1,layout:q.struct([q.u8(`instruction`),q.u32(`bytes`)])},SetComputeUnitLimit:{index:2,layout:q.struct([q.u8(`instruction`),q.u32(`units`)])},SetComputeUnitPrice:{index:3,layout:q.struct([q.u8(`instruction`),er(`microLamports`)])}}),vo=class{constructor(){}static requestUnits(e){let t=_o.RequestUnits,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static requestHeapFrame(e){let t=_o.RequestHeapFrame,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static setComputeUnitLimit(e){let t=_o.SetComputeUnitLimit,n=W(t,e);return new Z({keys:[],programId:this.programId,data:n})}static setComputeUnitPrice(e){let t=_o.SetComputeUnitPrice,n=W(t,{microLamports:BigInt(e.microLamports)});return new Z({keys:[],programId:this.programId,data:n})}},vo.programId=new Y(`ComputeBudget111111111111111111111111111111`),yo=64,bo=32,xo=64,So=q.struct([q.u8(`numSignatures`),q.u8(`padding`),q.u16(`signatureOffset`),q.u16(`signatureInstructionIndex`),q.u16(`publicKeyOffset`),q.u16(`publicKeyInstructionIndex`),q.u16(`messageDataOffset`),q.u16(`messageDataSize`),q.u16(`messageInstructionIndex`)]),Co=class e{constructor(){}static createInstructionWithPublicKey(t){let{publicKey:n,message:r,signature:i,instructionIndex:a}=t;U(n.length===bo,`Public Key must be ${bo} bytes but received ${n.length} bytes`),U(i.length===xo,`Signature must be ${xo} bytes but received ${i.length} bytes`);let o=So.span,s=o+n.length,c=s+i.length,l=g.alloc(c+r.length),u=a??65535;return So.encode({numSignatures:1,padding:0,signatureOffset:s,signatureInstructionIndex:u,publicKeyOffset:o,publicKeyInstructionIndex:u,messageDataOffset:c,messageDataSize:r.length,messageInstructionIndex:u},l),l.fill(n,o),l.fill(i,s),l.fill(r,c),new Z({keys:[],programId:e.programId,data:l})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:n,instructionIndex:r}=e;U(t.length===yo,`Private key must be ${yo} bytes but received ${t.length} bytes`);try{let e=mo.fromSecretKey(t),i=e.publicKey.toBytes(),a=wr(n,e.secretKey);return this.createInstructionWithPublicKey({publicKey:i,message:n,signature:a,instructionIndex:r})}catch(e){throw Error(`Error creating instruction; ${e}`)}}},Co.programId=new Y(`Ed25519SigVerify111111111111111111111111111`),wo=(e,t)=>{let n=w.sign(e,t);return[n.toCompactRawBytes(),n.recovery]},w.utils.isValidPrivateKey,To=w.getPublicKey,Eo=32,Do=20,Oo=64,ko=q.struct([q.u8(`numSignatures`),q.u16(`signatureOffset`),q.u8(`signatureInstructionIndex`),q.u16(`ethAddressOffset`),q.u8(`ethAddressInstructionIndex`),q.u16(`messageDataOffset`),q.u16(`messageDataSize`),q.u8(`messageInstructionIndex`),q.blob(20,`ethAddress`),q.blob(64,`signature`),q.u8(`recoveryId`)]),Ao=class e{constructor(){}static publicKeyToEthAddress(e){U(e.length===Oo,`Public key must be ${Oo} bytes but received ${e.length} bytes`);try{return g.from(m(J(e))).slice(-20)}catch(e){throw Error(`Error constructing Ethereum address: ${e}`)}}static createInstructionWithPublicKey(t){let{publicKey:n,message:r,signature:i,recoveryId:a,instructionIndex:o}=t;return e.createInstructionWithEthAddress({ethAddress:e.publicKeyToEthAddress(n),message:r,signature:i,recoveryId:a,instructionIndex:o})}static createInstructionWithEthAddress(t){let{ethAddress:n,message:r,signature:i,recoveryId:a,instructionIndex:o=0}=t,s;s=typeof n==`string`?n.startsWith(`0x`)?g.from(n.substr(2),`hex`):g.from(n,`hex`):n,U(s.length===Do,`Address must be ${Do} bytes but received ${s.length} bytes`);let c=12+s.length,l=c+i.length+1,u=g.alloc(ko.span+r.length);return ko.encode({numSignatures:1,signatureOffset:c,signatureInstructionIndex:o,ethAddressOffset:12,ethAddressInstructionIndex:o,messageDataOffset:l,messageDataSize:r.length,messageInstructionIndex:o,signature:J(i),ethAddress:J(s),recoveryId:a},u),u.fill(J(r),ko.span),new Z({keys:[],programId:e.programId,data:u})}static createInstructionWithPrivateKey(e){let{privateKey:t,message:n,instructionIndex:r}=e;U(t.length===Eo,`Private key must be ${Eo} bytes but received ${t.length} bytes`);try{let e=J(t),i=To(e,!1).slice(1),a=g.from(m(J(n))),[o,s]=wo(a,e);return this.createInstructionWithPublicKey({publicKey:i,message:n,signature:o,recoveryId:s,instructionIndex:r})}catch(e){throw Error(`Error creating instruction; ${e}`)}}},Ao.programId=new Y(`KeccakSecp256k11111111111111111111111111111`),Mo=new Y(`StakeConfig11111111111111111111111111111111`),No=class{constructor(e,t,n){this.unixTimestamp=void 0,this.epoch=void 0,this.custodian=void 0,this.unixTimestamp=e,this.epoch=t,this.custodian=n}},jo=No,No.default=new jo(0,0,Y.default),Po=Object.freeze({Initialize:{index:0,layout:q.struct([q.u32(`instruction`),Lr(),Rr()])},Authorize:{index:1,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`stakeAuthorizationType`)])},Delegate:{index:2,layout:q.struct([q.u32(`instruction`)])},Split:{index:3,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},Withdraw:{index:4,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},Deactivate:{index:5,layout:q.struct([q.u32(`instruction`)])},Merge:{index:7,layout:q.struct([q.u32(`instruction`)])},AuthorizeWithSeed:{index:8,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`stakeAuthorizationType`),Ir(`authoritySeed`),X(`authorityOwner`)])}}),Object.freeze({Staker:{index:0},Withdrawer:{index:1}}),Fo=class{constructor(){}static initialize(e){let{stakePubkey:t,authorized:n,lockup:r}=e,i=r||No.default,a=Po.Initialize,o=W(a,{authorized:{staker:J(n.staker.toBuffer()),withdrawer:J(n.withdrawer.toBuffer())},lockup:{unixTimestamp:i.unixTimestamp,epoch:i.epoch,custodian:J(i.custodian.toBuffer())}}),s={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1}],programId:this.programId,data:o};return new Z(s)}static createAccountWithSeed(e){let t=new Q;t.add(di.createAccountWithSeed({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,basePubkey:e.basePubkey,seed:e.seed,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:n,authorized:r,lockup:i}=e;return t.add(this.initialize({stakePubkey:n,authorized:r,lockup:i}))}static createAccount(e){let t=new Q;t.add(di.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.stakePubkey,lamports:e.lamports,space:this.space,programId:this.programId}));let{stakePubkey:n,authorized:r,lockup:i}=e;return t.add(this.initialize({stakePubkey:n,authorized:r,lockup:i}))}static delegate(e){let{stakePubkey:t,authorizedPubkey:n,votePubkey:r}=e,i=Po.Delegate,a=W(i);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:Mo,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:a})}static authorize(e){let{stakePubkey:t,authorizedPubkey:n,newAuthorizedPubkey:r,stakeAuthorizationType:i,custodianPubkey:a}=e,o=Po.Authorize,s=W(o,{newAuthorized:J(r.toBuffer()),stakeAuthorizationType:i.index}),c=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return a&&c.push({pubkey:a,isSigner:!0,isWritable:!1}),new Q().add({keys:c,programId:this.programId,data:s})}static authorizeWithSeed(e){let{stakePubkey:t,authorityBase:n,authoritySeed:r,authorityOwner:i,newAuthorizedPubkey:a,stakeAuthorizationType:o,custodianPubkey:s}=e,c=Po.AuthorizeWithSeed,l=W(c,{newAuthorized:J(a.toBuffer()),stakeAuthorizationType:o.index,authoritySeed:r,authorityOwner:J(i.toBuffer())}),u=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1}];return s&&u.push({pubkey:s,isSigner:!0,isWritable:!1}),new Q().add({keys:u,programId:this.programId,data:l})}static splitInstruction(e){let{stakePubkey:t,authorizedPubkey:n,splitStakePubkey:r,lamports:i}=e,a=Po.Split,o=W(a,{lamports:i});return new Z({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:o})}static split(e,t){let n=new Q;return n.add(di.createAccount({fromPubkey:e.authorizedPubkey,newAccountPubkey:e.splitStakePubkey,lamports:t,space:this.space,programId:this.programId})),n.add(this.splitInstruction(e))}static splitWithSeed(e,t){let{stakePubkey:n,authorizedPubkey:r,splitStakePubkey:i,basePubkey:a,seed:o,lamports:s}=e,c=new Q;return c.add(di.allocate({accountPubkey:i,basePubkey:a,seed:o,space:this.space,programId:this.programId})),t&&t>0&&c.add(di.transfer({fromPubkey:e.authorizedPubkey,toPubkey:i,lamports:t})),c.add(this.splitInstruction({stakePubkey:n,authorizedPubkey:r,splitStakePubkey:i,lamports:s}))}static merge(e){let{stakePubkey:t,sourceStakePubKey:n,authorizedPubkey:r}=e,i=Po.Merge,a=W(i);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:a})}static withdraw(e){let{stakePubkey:t,authorizedPubkey:n,toPubkey:r,lamports:i,custodianPubkey:a}=e,o=Po.Withdraw,s=W(o,{lamports:i}),c=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:ii,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return a&&c.push({pubkey:a,isSigner:!0,isWritable:!1}),new Q().add({keys:c,programId:this.programId,data:s})}static deactivate(e){let{stakePubkey:t,authorizedPubkey:n}=e,r=Po.Deactivate,i=W(r);return new Q().add({keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:i})}},Fo.programId=new Y(`Stake11111111111111111111111111111111111111`),Fo.space=200,Io=Object.freeze({InitializeAccount:{index:0,layout:q.struct([q.u32(`instruction`),zr()])},Authorize:{index:1,layout:q.struct([q.u32(`instruction`),X(`newAuthorized`),q.u32(`voteAuthorizationType`)])},Withdraw:{index:3,layout:q.struct([q.u32(`instruction`),q.ns64(`lamports`)])},UpdateValidatorIdentity:{index:4,layout:q.struct([q.u32(`instruction`)])},AuthorizeWithSeed:{index:10,layout:q.struct([q.u32(`instruction`),Br()])}}),Object.freeze({Voter:{index:0},Withdrawer:{index:1}}),Lo=class e{constructor(){}static initializeAccount(e){let{votePubkey:t,nodePubkey:n,voteInit:r}=e,i=Io.InitializeAccount,a=W(i,{voteInit:{nodePubkey:J(r.nodePubkey.toBuffer()),authorizedVoter:J(r.authorizedVoter.toBuffer()),authorizedWithdrawer:J(r.authorizedWithdrawer.toBuffer()),commission:r.commission}}),o={keys:[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ri,isSigner:!1,isWritable:!1},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:a};return new Z(o)}static createAccount(e){let t=new Q;return t.add(di.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:n,newAuthorizedPubkey:r,voteAuthorizationType:i}=e,a=Io.Authorize,o=W(a,{newAuthorized:J(r.toBuffer()),voteAuthorizationType:i.index}),s=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:s,programId:this.programId,data:o})}static authorizeWithSeed(e){let{currentAuthorityDerivedKeyBasePubkey:t,currentAuthorityDerivedKeyOwnerPubkey:n,currentAuthorityDerivedKeySeed:r,newAuthorizedPubkey:i,voteAuthorizationType:a,votePubkey:o}=e,s=Io.AuthorizeWithSeed,c=W(s,{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:J(n.toBuffer()),currentAuthorityDerivedKeySeed:r,newAuthorized:J(i.toBuffer()),voteAuthorizationType:a.index}}),l=[{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:ti,isSigner:!1,isWritable:!1},{pubkey:t,isSigner:!0,isWritable:!1}];return new Q().add({keys:l,programId:this.programId,data:c})}static withdraw(e){let{votePubkey:t,authorizedWithdrawerPubkey:n,lamports:r,toPubkey:i}=e,a=Io.Withdraw,o=W(a,{lamports:r}),s=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:s,programId:this.programId,data:o})}static safeWithdraw(t,n,r){if(t.lamports>n-r)throw Error(`Withdraw will leave vote account with insufficient funds.`);return e.withdraw(t)}static updateValidatorIdentity(e){let{votePubkey:t,authorizedWithdrawerPubkey:n,nodePubkey:r}=e,i=Io.UpdateValidatorIdentity,a=W(i),o=[{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}];return new Q().add({keys:o,programId:this.programId,data:a})}},Lo.programId=new Y(`Vote111111111111111111111111111111111111111`),Lo.space=3762,new Y(`Va1idator1nfo111111111111111111111111111111`),H({name:V(),website:B(V()),details:B(V()),iconUrl:B(V()),keybaseUsername:B(V())}),new Y(`Vote111111111111111111111111111111111111111`),q.struct([X(`nodePubkey`),X(`authorizedWithdrawer`),q.u8(`commission`),q.nu64(),q.seq(q.struct([q.nu64(`slot`),q.u32(`confirmationCount`)]),q.offset(q.u32(),-8),`votes`),q.u8(`rootSlotValid`),q.nu64(`rootSlot`),q.nu64(),q.seq(q.struct([q.nu64(`epoch`),X(`authorizedVoter`)]),q.offset(q.u32(),-8),`authorizedVoters`),q.struct([q.seq(q.struct([X(`authorizedPubkey`),q.nu64(`epochOfLastAuthorizedSwitch`),q.nu64(`targetEpoch`)]),32,`buf`),q.nu64(`idx`),q.u8(`isEmpty`)],`priorVoters`),q.nu64(),q.seq(q.struct([q.nu64(`epoch`),q.nu64(`credits`),q.nu64(`prevCredits`)]),q.offset(q.u32(),-8),`epochCredits`),q.struct([q.nu64(`slot`),q.nu64(`timestamp`)],`lastTimestamp`)]),Ro={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/`}}}));_(),zo();var Bo=l([o({transaction:s}),o({signature:s})]),Vo=o({signature:s}),Ho=o({transactions:c(s)}),Uo=[`solana_signTransaction`,`solana_signMessage`,`solana_signAllTransactions`,`solana_signAndSendTransaction`],Wo=e=>v.from(M(e)?e.serialize():e.serialize({requireAllSignatures:!1,verifySignatures:!1})).toString(`base64`),Go=(e,t)=>{let n=v.from(e,`base64`);return M(t)?$r.deserialize(n):Q.from(n)},Ko=class extends ge{options;name=`WalletConnect`;url=`https://walletconnect.org`;icon=`data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE4NSIgdmlld0JveD0iMCAwIDMwMCAxODUiIHdpZHRoPSIzMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTYxLjQzODU0MjkgMzYuMjU2MjYxMmM0OC45MTEyMjQxLTQ3Ljg4ODE2NjMgMTI4LjIxMTk4NzEtNDcuODg4MTY2MyAxNzcuMTIzMjA5MSAwbDUuODg2NTQ1IDUuNzYzNDE3NGMyLjQ0NTU2MSAyLjM5NDQwODEgMi40NDU1NjEgNi4yNzY1MTEyIDAgOC42NzA5MjA0bC0yMC4xMzY2OTUgMTkuNzE1NTAzYy0xLjIyMjc4MSAxLjE5NzIwNTEtMy4yMDUzIDEuMTk3MjA1MS00LjQyODA4MSAwbC04LjEwMDU4NC03LjkzMTE0NzljLTM0LjEyMTY5Mi0zMy40MDc5ODE3LTg5LjQ0Mzg4Ni0zMy40MDc5ODE3LTEyMy41NjU1Nzg4IDBsLTguNjc1MDU2MiA4LjQ5MzYwNTFjLTEuMjIyNzgxNiAxLjE5NzIwNDEtMy4yMDUzMDEgMS4xOTcyMDQxLTQuNDI4MDgwNiAwbC0yMC4xMzY2OTQ5LTE5LjcxNTUwMzFjLTIuNDQ1NTYxMi0yLjM5NDQwOTItMi40NDU1NjEyLTYuMjc2NTEyMiAwLTguNjcwOTIwNHptMjE4Ljc2Nzc5NjEgNDAuNzczNzQ0OSAxNy45MjE2OTcgMTcuNTQ2ODk3YzIuNDQ1NTQ5IDIuMzk0Mzk2OSAyLjQ0NTU2MyA2LjI3NjQ3NjkuMDAwMDMxIDguNjcwODg5OWwtODAuODEwMTcxIDc5LjEyMTEzNGMtMi40NDU1NDQgMi4zOTQ0MjYtNi40MTA1ODIgMi4zOTQ0NTMtOC44NTYxNi4wMDAwNjItLjAwMDAxLS4wMDAwMS0uMDAwMDIyLS4wMDAwMjItLjAwMDAzMi0uMDAwMDMybC01Ny4zNTQxNDMtNTYuMTU0NTcyYy0uNjExMzktLjU5ODYwMi0xLjYwMjY1LS41OTg2MDItMi4yMTQwNCAwLS4wMDAwMDQuMDAwMDA0LS4wMDAwMDcuMDAwMDA4LS4wMDAwMTEuMDAwMDExbC01Ny4zNTI5MjEyIDU2LjE1NDUzMWMtMi40NDU1MzY4IDIuMzk0NDMyLTYuNDEwNTc1NSAyLjM5NDQ3Mi04Ljg1NjE2MTIuMDAwMDg3LS4wMDAwMTQzLS4wMDAwMTQtLjAwMDAyOTYtLjAwMDAyOC0uMDAwMDQ0OS0uMDAwMDQ0bC04MC44MTI0MTk0My03OS4xMjIxODVjLTIuNDQ1NTYwMjEtMi4zOTQ0MDgtMi40NDU1NjAyMS02LjI3NjUxMTUgMC04LjY3MDkxOTdsMTcuOTIxNzI5NjMtMTcuNTQ2ODY3M2MyLjQ0NTU2MDItMi4zOTQ0MDgyIDYuNDEwNTk4OS0yLjM5NDQwODIgOC44NTYxNjAyIDBsNTcuMzU0OTc3NSA1Ni4xNTUzNTdjLjYxMTM5MDguNTk4NjAyIDEuNjAyNjQ5LjU5ODYwMiAyLjIxNDAzOTggMCAuMDAwMDA5Mi0uMDAwMDA5LjAwMDAxNzQtLjAwMDAxNy4wMDAwMjY1LS4wMDAwMjRsNTcuMzUyMTAzMS01Ni4xNTUzMzNjMi40NDU1MDUtMi4zOTQ0NjMzIDYuNDEwNTQ0LTIuMzk0NTUzMSA4Ljg1NjE2MS0uMDAwMi4wMDAwMzQuMDAwMDMzNi4wMDAwNjguMDAwMDY3My4wMDAxMDEuMDAwMTAxbDU3LjM1NDkwMiA1Ni4xNTU0MzJjLjYxMTM5LjU5ODYwMSAxLjYwMjY1LjU5ODYwMSAyLjIxNDA0IDBsNTcuMzUzOTc1LTU2LjE1NDMyNDljMi40NDU1NjEtMi4zOTQ0MDkyIDYuNDEwNTk5LTIuMzk0NDA5MiA4Ljg1NjE2IDB6IiBmaWxsPSIjM2I5OWZjIi8+PC9zdmc+`;supportedTransactionVersions=new Set([`legacy`,0]);readyState=typeof window>`u`?de.Unsupported:de.Loadable;key=null;session;chainId;connectingPromise;unsubscribeEnded;attempt=0;disposed=!1;endedListeners=new Set;constructor(e){super(),this.options=e}get publicKey(){return this.key}subscribeEnded(e){return this.endedListeners.add(e),()=>{this.endedListeners.delete(e)}}get connecting(){return this.connectingPromise!==void 0}get chains(){return this.options.network===ve.Mainnet?[`solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`,`solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ`]:[`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`,`solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K`]}account(e){for(let t of this.chains)for(let n of e.accounts){if(!n.startsWith(`${t}:`))continue;let e=E.decodeUnsafe(n.slice(t.length+1));if(e?.length===32)return{chainId:t,publicKey:new Y(e)}}}restoredSession(){return this.options.walletConnectProtocol.sessions(`solana`).pipe(d(e=>e.find(e=>this.account(e)!==void 0)))}release(){this.unsubscribeEnded?.(),this.unsubscribeEnded=void 0,this.session=void 0,this.chainId=void 0,this.key=null}connect(){if(this.disposed||this.readyState!==de.Loadable)return Promise.reject(new re);if(this.connected)return Promise.resolve();if(this.connectingPromise)return this.connectingPromise;let e=++this.attempt,t=this.options.walletConnectProtocol;return this.connectingPromise=this.options.runWalletEffect(this.restoredSession().pipe(u(a,()=>t.connect({namespace:`solana`,chains:this.chains,requiredMethods:[],optionalMethods:Uo})))).then(n=>{if(this.disposed||e!==this.attempt)throw new A;let r=this.account(n);if(!r)throw new k(`No Solana account approved`);this.release(),this.session=n,this.chainId=r.chainId,this.key=r.publicKey,this.unsubscribeEnded=t.subscribeEnded(n.topic,()=>{this.release(),this.emit(`disconnect`);for(let e of[...this.endedListeners])e()}),this.emit(`connect`,r.publicKey)}).finally(()=>{e===this.attempt&&(this.connectingPromise=void 0)}),this.connectingPromise}async autoConnect(){if(this.disposed)throw new re;await this.options.runWalletEffect(this.restoredSession())&&await this.connect()}async disconnect(){++this.attempt,this.connectingPromise=void 0;let e=this.session?.topic;this.release();try{e&&await this.options.runWalletEffect(this.options.walletConnectProtocol.disconnect(e))}catch(e){this.emit(`error`,new ae(e instanceof Error?e.message:void 0,e))}finally{this.emit(`disconnect`)}}supports(e){return this.session?.methods.includes(e)??!1}request(e,t,n){if(!this.session||!this.chainId||!this.key)throw new A;if(!this.supports(e))throw Error(`Wallet does not support ${e}`);return this.options.runWalletEffect(this.options.walletConnectProtocol.request({topic:this.session.topic,chainId:this.chainId,method:e,params:t,response:n}))}async signTransaction(e){try{let t=this.key;if(!t)throw new A;let n=await this.request(`solana_signTransaction`,{...M(e)?{}:e,transaction:Wo(e)},Bo);return`transaction`in n?Go(n.transaction,e):(e.addSignature(t,v.from(E.decode(n.signature))),e)}catch(e){return this.signingError(e)}}async signAllTransactions(e){if(!this.key)return this.signingError(new A);if(!this.supports(`solana_signAllTransactions`))return Promise.all(e.map(e=>this.signTransaction(e)));try{let t=await this.request(`solana_signAllTransactions`,{transactions:e.map(Wo)},Ho);if(t.transactions.length!==e.length)throw Error(`Wallet returned a different number of signed transactions`);return e.map((e,n)=>Go(t.transactions[n],e))}catch(e){return this.signingError(e)}}async signMessage(e){try{if(!this.key)throw new A;let t=await this.request(`solana_signMessage`,{pubkey:this.key.toBase58(),message:E.encode(e)},Vo);return E.decode(t.signature)}catch(e){let t=e instanceof A?e:new le(e instanceof Error?e.message:void 0,e);throw this.emit(`error`,t),t}}async signAndSendTransaction(e){try{return(await this.request(`solana_signAndSendTransaction`,{transaction:Wo(e)},Vo)).signature}catch(e){return this.signingError(e)}}signingError(e){let t=e instanceof A?e:new ce(e instanceof Error?e.message:void 0,e);throw this.emit(`error`,t),t}destroy(){this.disposed||(this.disposed=!0,++this.attempt,this.connectingPromise=void 0,this.release(),this.removeAllListeners(),this.endedListeners.clear())}},qo=`data:image/svg+xml,%3csvg%20width='66'%20height='56'%20viewBox='0%200%2066%2056'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20%3e%3cpath%20d='M46.6165%208.90197L33.0006%200L19.3872%208.90197L33.0006%2017.8066L46.6165%208.90197Z'%20fill='white'%20/%3e%3cpath%20d='M19.3872%2046.921L33.0006%2055.8256L46.6165%2046.921L33.0006%2038.019L19.3872%2046.921Z'%20fill='white'%20/%3e%3cpath%20d='M13.6159%2025.3516L0%2034.2535L13.6159%2043.1555L27.2293%2034.2535L13.6159%2025.3516Z'%20fill='white'%20/%3e%3cpath%20d='M52.3843%2025.3516L38.771%2034.2535L52.3843%2043.1555L66.0003%2034.2535L52.3843%2025.3516Z'%20fill='white'%20/%3e%3c/svg%3e`,Jo={Phantom:`https://chromewebstore.google.com/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa`,Trust:`https://chromewebstore.google.com/detail/trust-wallet/egjidjbpglichdcondbcbdnbeeppgdph`},Yo=e=>!!(`isSolanaConnector`in e&&e.isSolanaConnector);_();var Xo=s,Zo=/^[0-9a-fA-F]+$/u,Qo=e=>e.startsWith(`0x`)?e.slice(2):e,$o=e=>{let t=Qo(e.trim());return t.length>0&&t.length%2==0&&Zo.test(t)},es=e=>{let t=e.trim(),n=Qo(t);return $o(t)?{encoding:`hex`,buffer:v.from(n,`hex`)}:{encoding:`base64`,buffer:v.from(t,`base64`)}},ts=e=>es(e).buffer.toString(`hex`);export{re as A,oe as C,ae as D,ie as E,ce as F,j as M,ue as N,D as O,le as P,pe as S,k as T,_e as _,Yo as a,de as b,po as c,Xr as d,$r as f,ge as g,ve as h,Jo as i,se as j,A as k,Y as l,zo as m,ts as n,qo as o,gr as p,Xo as r,Ko as s,es as t,Q as u,M as v,O as w,me as x,fe as y};
|