1"use strict"; 2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f0f93a2e-5214-561d-8547-8a941161f653")}catch(e){}}(); 3(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[19541],{94758:function(t,e,r){r.d(e,{rV:function(){return g}});var n,i,o,s,a,c,u,l,d,h,f,p,y,m=r(48764),g=r(59917),v=r(13550),w=r.n(v),b=r(77191),_=r.n(b),A=r(79742),E=r(23204),I=r.n(E),x=r(72023),S=r(16681),P=r(27885),k=r(73148),L=r.n(k),T=r(69282),C=r(48764).Buffer;function B(t){return _().encode(t)}function D(t){let e=new Map;return t.errors&&t.errors.forEach(t=>{var r;let n=null!==(r=t.msg)&&void 0!==r?r:t.name;e.set(t.code,n)}),e}function O(t,e={}){t.forEach(t=>{if("accounts"in t)O(t.accounts,e[t.name]);else if(void 0===e[t.name])throw Error(`Invalid arguments: ${t.name} not provided.`)})}function R(t){return t instanceof g.PublicKey?t:new g.PublicKey(t)}class N extends TypeError{constructor(t,e){let r;let{message:n,...i}=t,{path:o}=t,s=0===o.length?n:"At path: "+o.join(".")+" -- "+n;super(s),this.value=void 0,this.key=void 0,this.type=void 0,this.refinement=void 0,this.path=void 0,this.branch=void 0,this.failures=void 0,Object.assign(this,i),this.name=this.constructor.name,this.failures=()=>{var n;return null!=(n=r)?n:r=[t,...e()]}}}function U(t){return"object"==typeof t&&null!=t}function M(t){return"string"==typeof t?JSON.stringify(t):""+t}function*V(t,e,r,n){var i;for(let o of(U(i=t)&&"function"==typeof i[Symbol.iterator]||(t=[t]),t)){let t=function(t,e,r,n){if(!0===t)return;!1===t?t={}:"string"==typeof t&&(t={message:t});let{path:i,branch:o}=e,{type:s}=r,{refinement:a,message:c="Expected a value of type `"+s+"`"+(a?" with refinement `"+a+"`":"")+", but received: `"+M(n)+"`"}=t;return{value:n,type:s,refinement:a,key:i[i.length-1],path:i,branch:o,...t,message:c}}(o,e,r,n);t&&(yield t)}}function*$(t,e,r){void 0===r&&(r={});let{path:n=[],branch:i=[t],coerce:o=!1,mask:s=!1}=r,a={path:n,branch:i};if(o&&(t=e.coercer(t,a),s&&"type"!==e.type&&U(e.schema)&&U(t)&&!Array.isArray(t)))for(let r in t)void 0===e.schema[r]&&delete t[r];let c=!0;for(let r of e.validator(t,a))c=!1,yield[r,void 0];for(let[r,u,l]of e.entries(t,a)){let e=$(u,l,{path:void 0===r?n:[...n,r],branch:void 0===r?i:[...i,u],coerce:o,mask:s});for(let n of e)n[0]?(c=!1,yield[n[0],void 0]):o&&(u=n[1],void 0===r?t=u:t instanceof Map?t.set(r,u):t instanceof Set?t.add(u):U(t)&&(t[r]=u))}if(c)for(let r of e.refiner(t,a))c=!1,yield[r,void 0];c&&(yield[void 0,t])}class j{constructor(t){this.TYPE=void 0,this.type=void 0,this.schema=void 0,this.coercer=void 0,this.validator=void 0,this.refiner=void 0,this.entries=void 0;let{type:e,schema:r,validator:n,refiner:i,coercer:o=t=>t,entries:s=function*(){}}=t;this.type=e,this.schema=r,this.entries=s,this.coercer=o,n?this.validator=(t,e)=>{let r=n(t,e);return V(r,e,this,t)}:this.validator=()=>[],i?this.refiner=(t,e)=>{let r=i(t,e);return V(r,e,this,t)}:this.refiner=()=>[]}assert(t){return function(t,e){let r=z(t,e);if(r[0])throw r[0]}(t,this)}create(t){return q(t,this)}is(t){return K(t,this)}mask(t){return function(t,e){let r=z(t,e,{coerce:!0,mask:!0});if(!r[0])return r[1];throw r[0]}(t,this)}validate(t,e){return void 0===e&&(e={}),z(t,this,e)}}function q(t,e){let r=z(t,e,{coerce:!0});if(!r[0])return r[1];throw r[0]}function K(t,e){let r=z(t,e);return!r[0]}function z(t,e,r){void 0===r&&(r={});let n=$(t,e,r),i=function(t){let{done:e,value:r}=t.next();return e?void 0:r}(n);if(i[0]){let t=new N(i[0],function*(){for(let t of n)t[0]&&(yield t[0])});return[t,void 0]}{let t=i[1];return[void 0,t]}}function F(t,e){return new j({type:t,schema:null,validator:e})}function W(t){return new j({type:"array",schema:t,*entries(e){if(t&&Array.isArray(e))for(let[r,n]of e.entries())yield[r,n,t]},coercer:t=>Array.isArray(t)?t.slice():t,validator:t=>Array.isArray(t)||"Expected an array value, but received: "+M(t)})}function H(t){let e=M(t),r=typeof t;return new j({type:"literal",schema:"string"===r||"number"===r||"boolean"===r?t:null,validator:r=>r===t||"Expected the literal `"+e+"`, but received: "+M(r)})}function G(t){return new j({...t,validator:(e,r)=>null===e||t.validator(e,r),refiner:(e,r)=>null===e||t.refiner(e,r)})}function J(){return F("number",t=>"number"==typeof t&&!isNaN(t)||"Expected a number, but received: "+M(t))}function Z(t){return new j({...t,validator:(e,r)=>void 0===e||t.validator(e,r),refiner:(e,r)=>void 0===e||t.refiner(e,r)})}function Y(){return F("string",t=>"string"==typeof t||"Expected a string, but received: "+M(t))}function X(t){let e=Object.keys(t);return new j({type:"type",schema:t,*entries(r){if(U(r))for(let n of e)yield[n,r[n],t[n]]},validator:t=>U(t)||"Expected an object, but received: "+M(t)})}function Q(t){let e=t.map(t=>t.type).join(" | ");return new j({type:"union",schema:null,coercer(e,r){let n=t.find(t=>{let[r]=t.validate(e,{coerce:!0});return!r})||tt();return n.coercer(e,r)},validator(r,n){let i=[];for(let e of t){let[...t]=$(r,e,n),[o]=t;if(!o[0])return[];for(let[e]of t)e&&i.push(e)}return["Expected the value to satisfy a union of `"+e+"`, but received: "+M(r),...i]}})}function tt(){return F("unknown",()=>!0)}async function te(t,e,r){if(e.length<=99)return await tr(t,e,r);{let n=Array.apply(0,Array(Math.ceil(e.length/99))).map((t,r)=>e.slice(99*r,(r+1)*99)),i=await Promise.all(n.map(e=>tr(t,e,r)));return i.flat()}}async function tr(t,e,r){let n=null!=r?r:t.commitment,{value:i,context:o}=await t.getMultipleAccountsInfoAndContext(e,n),s=i.map((t,r)=>null===t?null:{publicKey:e[r],account:t,context:o});return s}async function tn(t,e,r,n,i){r&&r.length>0&&e.sign(...r);let o=e._compile(),s=o.serialize(),a=e._serialize(s),c=a.toString("base64"),u={encoding:"base64",commitment:null!=n?n:t.commitment};if(i){let t=(Array.isArray(i)?i:o.nonProgramIds()).map(t=>
3t.toBase58());u.accounts={encoding:"base64",addresses:t}}r&&(u.sigVerify=!0);let l=[c,u],d=await t._rpcRequest("simulateTransaction",l),h=q(d,ts);if("error"in h){let t;if("data"in h.error&&(t=h.error.data.logs)&&Array.isArray(t)){let e="\n ",r=e+t.join(e);console.error(h.error.message,r)}throw new g.SendTransactionError("failed to simulate transaction: "+h.error.message,t)}return h.result}let ti=to(tt());function to(t){return Q([X({jsonrpc:H("2.0"),id:Y(),result:t}),X({jsonrpc:H("2.0"),id:Y(),error:X({code:tt(),message:Y(),data:Z(F("any",()=>!0))})})])}let ts=(n=X({err:G(Q([X({}),Y()])),logs:G(W(Y())),accounts:Z(G(W(G(X({executable:F("boolean",t=>"boolean"==typeof t),owner:Y(),lamports:J(),data:W(Y()),rentEpoch:Z(J())}))))),unitsConsumed:Z(J())}),o=to(i=X({context:X({slot:J()}),value:n})),s=t=>"error"in t?t:{...t,result:q(t.result,i)},new j({...o,coercer:(t,e)=>K(t,ti)?o.coercer(s(t,e),e):o.coercer(t,e)}));class ta{constructor(t,e,r){this.connection=t,this.wallet=e,this.opts=r,this.publicKey=null==e?void 0:e.publicKey}static defaultOptions(){return{preflightCommitment:"processed",commitment:"processed"}}static local(t,e){throw Error("Provider local is not available on browser.")}static env(){throw Error("Provider env is not available on browser.")}async sendAndConfirm(t,e,r){var n;void 0===r&&(r=this.opts),t.feePayer=t.feePayer||this.wallet.publicKey,t.recentBlockhash=(await this.connection.getLatestBlockhash(r.preflightCommitment)).blockhash,t=await this.wallet.signTransaction(t),(null!=e?e:[]).forEac
3h(e=>{t.partialSign(e)});let i=t.serialize();try{return await tu(this.connection,i,r)}catch(e){if(e instanceof tl){let r=await this.connection.getTransaction(B(t.signature),{commitment:"confirmed"});if(r){let t=null===(n=r.meta)||void 0===n?void 0:n.logMessages;throw t?new g.SendTransactionError(e.message,t):e}}throw e}}async sendAll(t,e){var r;void 0===e&&(e=this.opts);let n=await this.connection.getLatestBlockhash(e.preflightCommitment),i=t.map(t=>{var e;let r=t.tx,i=null!==(e=t.signers)&&void 0!==e?e:[];return r.feePayer=r.feePayer||this.wallet.publicKey,r.recentBlockhash=n.blockhash,i.forEach(t=>{r.partialSign(t)}),r}),o=await this.wallet.signAllTransactions(i),s=[];for(let t=0;t<i.length;t+=1){let n=o[t],i=n.serialize();try{s.push(await tu(this.connection,i,e))}catch(t){if(t instanceof tl){let e=await this.connection.getTransaction(B(n.signature),{commitment:"confirmed"});if(e){let n=null===(r=e.meta)||void 0===r?void 0:r.logMessages;throw n?new g.SendTransactionError(t.message,n):t}}throw t}}return s}async simulate(t,e,r,n){t.feePayer=t.feePayer||this.wallet.publicKey,t.recentBlockhash=(await this.connection.getLatestBlockhash(null!=r?r:this.connection.commitment)).blockhash,t=await this.wallet.signTransaction(t);let i=await tn(this.connection,t,e,r,n);if(i.value.err)throw new tc(i.value);return i.value}}class tc extends Error{constructor(t,e){super(e),this.simulationResponse=t}}async function tu(t,e,r){let n=r&&{skipPreflight:r.skipPreflight,preflightCommitment:r.preflightCommitment||r.commitment},i=await t.sendRawTransaction(e,n),o=(await t.confirmTransaction(i,r&&r.commitment)).value;if(o.err)throw new tl(`Raw transaction ${i} failed (${JSON.stringify(o)})`);return i}class tl extends Error{constructor(t){super(t)}}function td(){return null===th?ta.local():th}let th=null,tf=new Map;function tp(t){return void 0!==tf.get(t)}class ty extends Error{constructor(t){super(t),this.name="IdlError"}}class tm{constructor(t){this.stack=t}static parse(t){var e;
3let r=/^Program (\w*) invoke/,n=/^Program \w* success/,i=[];for(let o=0;o<t.length;o++){if(n.exec(t[o])){i.pop();continue}let s=null===(e=r.exec(t[o]))||void 0===e?void 0:e[1];s&&i.push(new g.PublicKey(s))}return new tm(i)}}class tg extends Error{constructor(t,e,r,n,i,o){super(r.join("\n").replace("Program log: ","")),this.errorLogs=r,this.logs=n,this.error={errorCode:t,errorMessage:e,comparedValues:o,origin:i},this._programErrorStack=tm.parse(n)}static parse(t){let e;if(!t)return null;let r=t.findIndex(t=>t.startsWith("Program log: AnchorError"));if(-1===r)return null;let n=t[r],i=[n];if(r+1<t.length){if("Program log: Left:"===t[r+1]){let n=/^Program log: (.*)$/,o=n.exec(t[r+2])[1],s=n.exec(t[r+4])[1];e=[new g.PublicKey(o),new g.PublicKey(s)],i.push(...t.slice(r+1,r+5))}else if(t[r+1].startsWith("Program log: Left:")){let n=/^Program log: (Left|Right): (.*)$/,o=n.exec(t[r+1])[2],s=n.exec(t[r+2])[2];i.push(...t.slice(r+1,r+3)),e=[o,s]}}let o=/^Program log: AnchorError occurred\. Error Code: (.*)\. Error Number: (\d*)\. Error Message: (.*)\./.exec(n),s=/^Program log: AnchorError thrown in (.*):(\d*)\. Error Code: (.*)\. Error Number: (\d*)\. Error Message: (.*)\./.exec(n),a=/^Program log: AnchorError caused by account: (.*)\. Error Code: (.*)\. Error Number: (\d*)\. Error Message: (.*)\./.exec(n);if(o){let[r,n,s]=o.slice(1,4),a={code:r,number:parseInt(n)};return new tg(a,s,i,t,void 0,e)}if(s){let[r,n,o,a,c]=s.slice(1,6),u={code:o,number:parseInt(a)},l={file:r,line:parseInt(n)};return new tg(u,c,i,t,l,e)}if(!a)return null;{let[r,n,o,s]=a.slice(1,5),c={code:n,number:parseInt(o)};return new tg(c,s,i,t,r,e)}}get program(){return this._programErrorStack.stack[this._programErrorStack.stack.length-1]}get programErrorStack(){return this._programErrorStack.stack}toString(){return this.message}}class tv extends Error{constructor(t,e,r){super(),this.code=t,this.msg=e,this.logs=r,r&&(this._programErrorStack=tm.parse(r))}static parse(t,e){let r,n;let i=t.toString();if(i.includes("custom program error:")){let t=i.split("custom program error: ");if(2!==t.length)return null;r=t[1]}else{let t=i.match(/"Custom":([0-9]+)}/g);if(!t||t.length>1)return null;r=t[0].match(/([0-9]+)/g)[0]}try{n=parseInt(r)}catch(t){return null}let o=e.get(n);return void 0!==o||void 0!==(o=t_.get(n))?new tv(n,o,t.logs):null}get program(){var t;return null===(t=this._programErrorStack)||void 0===t?void 0:t.stack[this._programErrorStack.stack.length-1]}get programErrorStack(){var t;return null===(t=this._programErrorStack)||void 0===t?void 0:t.stack}toString(){return this.msg}}function tw(t,e){tp("debug-logs")&&console.log("Translating error:",t);let r=tg.parse(t.logs);if(r)return r;let n=tv.parse(t,e);return n||(t.logs?(t.programErrorStack=tm.parse(t.logs),new Proxy(t,{get:function(e,r){return"programErrorStack"===r?e.programErrorStack.stack:"program"===r?e.programErrorStack.stack[t.programErrorStack.stack.length-1]:Reflect.get(...arguments)}})):t)}let tb={InstructionMissing:100,InstructionFallbackNotFound:101,InstructionDidNotDeserialize:102,InstructionDidNotSerialize:103,IdlInstructionStub:1e3,IdlInstructionInvalidProgram:1001,ConstraintMut:2e3,ConstraintHasOne:2001,ConstraintSigner:2002,ConstraintRaw:2003,ConstraintOwner:2004,ConstraintRentExempt:2005,ConstraintSeeds:2006,ConstraintExecutable:2007,ConstraintState:2008,ConstraintAssociated:2009,ConstraintAssociatedInit:2010,ConstraintClose:2011,ConstraintAddress:2012,ConstraintZero:2013,ConstraintTokenMint:2014,ConstraintTokenOwner:2015,ConstraintMintMintAuthority:2016,ConstraintMintFreezeAuthority:2017,ConstraintMintDecimals:2018,ConstraintSpace:2019,ConstraintAccountIsNone:2020,RequireViolated:2500,RequireEqViolated:2501,RequireKeysEqViolated:2502,RequireNeqViolated:2503,RequireKeysNeqViolated:2504,RequireGtViolated:2505,RequireGteViolated:2506,AccountDiscriminatorAlreadySet:3e3,AccountDiscriminatorNotFound:3001,AccountDiscriminatorMismatch:3002,AccountDidNotDeserialize:3003,AccountDidNotSerialize:3004,AccountNotEnoughKeys:3005,AccountNotMutable:3006,AccountOwnedByWrongProgram:3007,InvalidProgramId:3008,InvalidProgramExecutable:3009,AccountNotSigner:3010,AccountNotSystemOwned:3011,AccountNotInitialized:3012,AccountNotProgramData:3013,AccountNotAssociatedTokenAccount:3014,AccountSysvarMismatch:3015,AccountReallocExceedsLimit:3016,AccountDuplicateReallocs:3017,StateInvalidAddress:4e3,DeclaredProgramIdMismatch:4100,Deprecated:5e3},t_=new Map([[tb.InstructionMissing,"8 byte instruction identifier not provided"],[tb.InstructionFallbackNotFound,"Fallback functions are not supported"],[tb.InstructionDidNotDeserialize,"The program could not deserialize the given instruction"],[tb.InstructionDidNotSerialize,"The program could not serialize the given instruction"],[tb.IdlInstructionStub,"The program was compiled without idl instructions"],[tb.IdlInstructionInvalidProgram,"The transaction was given an invali
3d program for the IDL instruction"],[tb.ConstraintMut,"A mut constraint was violated"],[tb.ConstraintHasOne,"A has one constraint was violated"],[tb.ConstraintSigner,"A signer constraint was violated"],[tb.ConstraintRaw,"A raw constraint was violated"],[tb.ConstraintOwner,"An owner constraint was violated"],[tb.ConstraintRentExempt,"A rent exemption constraint was violated"],[tb.ConstraintSeeds,"A seeds constraint was violated"],[tb.ConstraintExecutable,"An executable constraint was violated"],[tb.ConstraintState,"A state constraint was violated"],[tb.ConstraintAssociated,"An associated constraint was violated"],[tb.ConstraintAssociatedInit,"An associated init constraint was violated"],[tb.ConstraintClose,"A close constraint was violated"],[tb.ConstraintAddress,"An address constraint was violated"],[tb.ConstraintZero,"Expected zero account discriminant"],[tb.ConstraintTokenMint,"A token mint constraint was violated"],[tb.ConstraintTokenOwner,"A token owner constraint was violated"],[tb.ConstraintMintMintAuthority,"A mint mint authority constraint was violated"],[tb.ConstraintMintFreezeAuthority,"A mint freeze authority constraint was violated"],[tb.ConstraintMintDecimals,"A mint decimals constraint was violated"],[tb.ConstraintSpace,"A space constraint was violated"],[tb.ConstraintAccountIsNone,"A required account for the constraint is None"],[tb.RequireViolated,"A require expression was violated"],[tb.RequireEqViolated,"A require_eq expression was violated"],[tb.RequireKeysEqViolated,"A require_keys_eq expression was violated"],[tb.RequireNeqViolated,"A require_neq expression was violated"],[tb.RequireKeysNeqViolated,"A require_keys_neq expression was violated"],[tb.RequireGtViolated,"A require_gt expression was violated"],[tb.RequireGteViolated,"A require_gte expression was violated"],[tb.AccountDiscriminatorAlreadySet,"The account discriminator was already set on this account"],[tb.AccountDiscriminatorNotFound,"No 8 byte discriminator was found on the account"],[tb.AccountDiscriminatorMismatch,"8 byte discriminator did not match what was expected"],[tb.AccountDidNotDeserialize,"Failed to deserialize the account"],[tb.AccountDidNotSerialize,"Failed to serialize the account"],[tb.AccountNotEnoughKeys,"Not enough account keys given to the instruction"],[tb.AccountNotMutable,"The given account is not mutable"],[tb.AccountOwnedByWrongProgram,"The given account is owned by a different program than expected"],[tb.InvalidProgramId,"Program ID was not as expected"],[tb.InvalidProgramExecutable,"Program account is not executable"],[tb.AccountNotSigner,"The given account did not sign"],[tb.AccountNotSystemOwned,"The given account is not owned by the system program"],[tb.AccountNotInitialized,"The program expected this account to be already initialized"],[tb.AccountNotProgramData,"The given account is not a program data account"],[tb.AccountNotAssociatedTokenAccount,"The given account is not the associated token account"],[tb.AccountSysvarMismatch,"The given public key does not match the required sysvar"],[tb.AccountReallocExceedsLimit,"The account reallocation exceeds the MAX_PERMITTED_DATA_INCREASE limit"],[tb.AccountDuplicateReallocs,"The account was duplicated for more than one reallocation"],[tb.StateInvalidAddress,"The given state account does not have the correct address"],[tb.DeclaredProgramIdMismatch,"The declared program id does not match the actual program id"],[tb.Deprecated,"The API being used is deprecated and should no longer be used"]]);var tA=function(){return(tA=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},tE=function(){return(tE=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function tI(t){return t.toLowerCase()}var tx=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],tS=/[^A-Z0-9]+/gi;function tP(t,e,r){return e instanceof RegExp?t.replace(e,r):e.reduce(function(t,e){return t.replace(e,r)},t)}class tk{static fieldLayout(t,e){let r=void 0!==t.name?I()(t.name):void 0;switch(t.type){case"bool":return S.bool(r);case"u8":return S.u8(r);case"i8":return S.i8(r);case"u16":return S.u16(r);case"i16":return S.i16(r);case"u32":return S.u32(r);case"i32":return S.i32(r);case"f32":return S.f32(r);case"u64":return S.u64(r);case"i64":return S.i64(r);case"f64":return S.f64(r);case"u128":return S.u128(r);case"i128":return S.i128(r);case"u256":return S.u256(r);case"i256":return S.i256(r);case"bytes":return S.vecU8(r);case"string":return S.str(r);case"publicKey":return S.publicKey(r);default:if("vec"in t.type)return S.vec(tk.fieldLayout({name:void 0,type:t.type.vec},e),r);
3if("option"in t.type)return S.option(tk.fieldLayout({name:void 0,type:t.type.option},e),r);if("defined"in t.type){let n=t.type.defined;if(void 0===e)throw new ty("User defined types not provided");let i=e.filter(t=>t.name===n);if(1!==i.length)throw new ty(`Type not found: ${JSON.stringify(t)}`);return tk.typeDefLayout(i[0],e,r)}if("array"in t.type){let n=t.type.array[0],i=t.type.array[1],o=tk.fieldLayout({name:void 0,type:n},e);return S.array(o,i,r)}else throw Error(`Not yet implemented: ${t}`)}}static typeDefLayout(t,e=[],r){if("struct"===t.type.kind){let n=t.type.fields.map(t=>{let r=tk.fieldLayout(t,e);return r});return S.struct(n,r)}if("enum"===t.type.kind){let n=t.type.variants.map(t=>{let r=I()(t.name);if(void 0===t.fields)return S.struct([],r);let n=t.fields.map((t,r)=>t.hasOwnProperty("name")?tk.fieldLayout(t,e):tk.fieldLayout({type:t,name:r.toString()},e));return S.struct(n,r)});return void 0!==r?S.rustEnum(n).replicate(r):S.rustEnum(n,r)}throw Error(`Unknown type kint: ${t}`)}}let tL="state",tT="global";class tC{constructor(t){this.idl=t,this.ixLayout=tC.parseIxLayout(t);let e=new Map;t.instructions.forEach(t=>{let r=tD(tT,t.name);e.set(_().encode(r),{layout:this.ixLayout.get(t.name),name:t.name})}),t.state&&t.state.methods.map(t=>{let r=tD(tL,t.name);e.set(_().encode(r),{layout:this.ixLayout.get(t.name),name:t.name})}),this.sighashLayouts=e}encode(t,e){return this._encode(tT,t,e)}encodeState(t,e){return this._encode(tL,t,e)}_encode(t,e,r){let n=m.Buffer.alloc(1e3),i=I()(e),o=this.ixLayout.get(i);if(!o)throw Error(`Unknown method: ${i}`);let s=o.encode(r,n),a=n.slice(0,s);return m.Buffer.concat([tD(t,e),a])}static parseIxLayout(t){let e=t.state?t.state.methods:[],r=e.map(e=>{let r=e.args.map(e=>{var r,n;return tk.fieldLayout(e,Array.from([...null!==(r=t.accounts)&&void 0!==r?r:[],...null!==(n=t.types)&&void 0!==n?n:[]]))}),n=I()(e.name);return[n,S.struct(r,n)]}).concat(t.instructions.map(e=>{let r=e.args.map(e=>{var r,n;return tk.fieldLayout(e,Array.from([...null!==(r=t.accounts)&&void 0!==r?r:[],...null!==(n=t.types)&&void 0!==n?n:[]]))}),n=I()(e.name);return[n,S.struct(r,n)]}));return new Map(r)}decode(t,e="hex"){"string"==typeof t&&(t="hex"===e?m.Buffer.from(t,"hex"):_().decode(t));let r=_().encode(t.slice(0,8)),n=t.slice(8),i=this.sighashLayouts.get(r);return i?{data:i.layout.decode(n),name:i.name}:null}format(t,e){return tB.format(t,e,this.idl)}}class tB{static format(t,e,r){let n=r.instructions.filter(e=>t.name===e.name)[0];if(void 0===n)return console.error("Invalid instruction given"),null;let i=n.args.map(e=>({name:e.name,type:tB.formatIdlType(e.type),data:tB.formatIdlData(e,t.data[e.name],r.types)})),o=tB.flattenIdlAccounts(n.accounts),s=e.map((t,e)=>e<o.length?{name:o[e].name,...t}:{name:void 0,...t});return{args:i,accounts:s}}static formatIdlType(t){if("string"==typeof t)return t;if("vec"in t)return`Vec<${this.formatIdlType(t.vec)}>`;if("option"in t)return`Option<${this.formatIdlType(t.option)}>`;if("defined"in t)return t.defined;if("array"in t)return`Array<${t.array[0]}; ${t.array[1]}>`;throw Error(`Unknown IDL type: ${t}`)}static formatIdlData(t,e,r){if("string"==typeof t.type)return e.toString();if(t.type.hasOwnProperty("vec"))return"["+e.map(e=>this.formatIdlData({name:"",type:t.type.vec},e)).join(", ")+"]";if(t.type.hasOwnProperty("option"))return null===e?"null":this.formatIdlData({name:"",type:t.type.option},e,r);if(t.type.hasOwnProperty("defined")){if(void 0===r)throw Error("User defined types not provided");let n=r.filter(e=>e.name===t.type.defined);if(1!==n.length)throw Error(`Type not found: ${t.type.defined}`);return tB.formatIdlDataDefined(n[0],e,r)}return"unknown"}static formatIdlDataDefined(t,e,r){if("struct"===t.type.kind){let n=t.type,i=Object.keys(e).map(t=>{let i=n.fields.filter(e=>e.name===t)[0];if(void 0===i)throw Error("Unable to find type");return t+": "+tB.formatIdlData(i,e[t],r)}).join(", ");return"{ "+i+" }"}if(0===t.type.variants.length)return"{}";if(!t.type.variants[0].name)return"Tuple formatting not yet implemented";{let n=t.type.variants,i=Object.keys(e)[0],o=e[i],s=Object.keys(o).map(t=>{var e;let s=o[t],a=null===(e=n[i])||void 0===e?void 0:e.filter(e=>e.name===t)[0];if(void 0===a)throw Error("Unable to find variant");return t+": "+tB.formatIdlData(a,s,r)}).join(", "),a=I()(i,{pascalCase:!0});return 0===s.length?a:`${a} { ${s} }`}}static flattenIdlAccounts(t,e){return t.map(t=>{let r=function(t){let e=t.replace(/([A-Z])/g," $1");return e.charAt(0).toUpperCase()+e.slice(1)}(t.name);if(!t.hasOwnProperty("accounts"))return{...t,name:e?`${e} > ${r}`:r};{let n=e?`${e} > ${r}`:r;return tB.flattenIdlAccounts(t.accounts,n)}}).flat()}}function tD(t,e){var r,n;let i=`${t}:${(void 0===r&&(r={}),void 0===(n=tA({delimiter:"_"},r))&&(n={}),function(t,e){void 0===e&&(e={});for(var r=e.splitRegexp,n=e.stripRegexp,i=e.transform,o=e.delimiter,s=tP(tP(t,void 0===r?tx:r,"$1\x00$2"),void 0===n?tS:n,"\x00"),a=0,c=s.length;"\x00"===s.charAt(a);)a++;for(;"\x00"===s.charAt(c-1);)c--;return s.slice(a,c).split("\x00").map(void 0===i?tI:i).join(void 0===o?" ":o)}(e,tE({delimiter:"."},n)))}`;return m.Buffer.from(x.sha256.digest(i)).slice(0,8)}function tO(t,e){return"enum"===e.type.kind?Math.max(...e.type.variants.map(e=>void 0===e.fields?0:e.fields.map(e=>{if(!("object"==typeof e&&"name"in e))throw Error("Tuple enum variants not yet implemented.");return tR(t,e.type)}).reduce((t,e)=>t+e)))+1:void 0===e.type.fields?0:e.type.fields.map(e=>tR(t,e.type)).reduce((t,e)=>t+e,0)}function tR(t,e){var r,n;switch(e){case"bool":case"u8":case"i8":case"bytes":case"string":return 1;case"i16":case"u16":return 2;case"u32":case"i32":case"f32":return 4;case"u64":case"i64":case"f64":return 8;case"u128":case"i128":return 16;case"u256":case"i256":case"publicKey":return 32;default:if("vec"in e)return 1;if("option"in e)return 1+tR(t,e.option);if("coption"in e)return 4+tR(t,e.coption);if("defined"in e){let i=null!==(n=null===(r=t.types)||void 0===r?void 0:r.filter(t=>t.name===e.defined))&&void 0!==n?n:[];if(1!==i.length)throw new ty(`Type not found: ${JSON.stringify(e)}`);return tO(t,i[0])}if("array"in e){let r=e.array[0],n=e.array[1];return tR(t,r)*n}throw Error(`Invalid type ${JSON.stringify(e)}`)}}class tN{constructor(t){if(void 0===t.accounts){this.accountLayouts=new Map;return}let e=t.accounts.map(e=>[e.name,tk.typeDefLayout(e,t.types)]);this.accountLayouts=new Map(e),this.idl=t}async encode(t,e){let r=m.Buffer.alloc(1e3),n=this.accountLayouts.get(t);if(!n)throw Error(`Unknown account: ${t}`);let i=n.encode(e,r),o=r.slice(0,i),s=tN.accountDiscriminator(t);return m.Buffer.concat([s,o])}decode(t,e){let r=tN.accountDiscriminator(t);if(r.compare(e.slice(0,8)))throw Error("Invalid account discriminator");return this.decodeUnchecked(t,e)}decodeAny(t){let e=t.slice(0,8),r=Array.from(this.accountLayouts.keys()).find(t=>tN.accountDiscriminator(t).equals(e));if(!r)throw Error("Account descriminator not found");return this.decodeUnchecked(r,t)}decodeUnchecked(t,e){let r=e.slice(8),n=this.accountLayouts.get(t);if(!n)throw Error(`Unknown account: ${t}`);return n.decode(r)}memcmp(t,e){let r=tN.accountDiscriminator(t);return{offset:0,bytes:_().encode(e?m.Buffer.concat([r,e]):r)}}size(t){var e;return 8+(null!==(e=tO(this.idl,t))&&void 0!==e?e:0)}static accountDiscriminator(t){return m.Buffer.from(x.sha256.digest(`account:${I()(t,{pascalCase:!0,preserveConsecutiveUppercase:!0})}`)).slice(0,8)}}class tU{constructor(t){if(void 0===t.events){this.layouts=new Map;return}let e=t.events.map(e=>{let r={name:e.name,type:{kind:"struct",fields:e.fields.map(t=>({name:t.name,type:t.type}))}};return[e.name,tk.typeDefLayout(r,t.types)]});this.layouts=new Map(e),this.discriminators=new Map(void 0===t.events?[]:t.events.map(t=>{var e;return[A.fromByteArray((e=t.name,m.Buffer.from(x.sha256.digest(`event:${e}`)).slice(0,8))),t.name]}))}decode(t){let e;try{e=m.Buffer.from(A.toByteArray(t))}catch(t){return null}let r=A.fromByteArray(e.slice(0,8)),n=this.discriminators.get(r);if(void 0===n)return null;let i=this.layouts.get(n);if(!i)throw Error(`Unknown event: ${n}`);let o=i.decode(e.slice(8));return{data:o,name:n}}}class tM{constructor(t){if(void 0===t.state)throw Error("Idl state not defined.");this.layout=tk.typeDefLayout(t.state.struct,t.types)}async encode(t,e){let r=m.Buffer.alloc(1e3),n=this.layout.encode(e,r),i=await tV(t),o=r.slice(0,n);return m.Buffer.concat([i,o])}decode(t){let e=t.slice(8);return this.layout.decode(e)}}async function tV(t){let e=tp("anchor-deprecated-state")?"account":"state";return m.Buffer.from(x.sha256.digest(`${e}:${t}`)).slice(0,8)}class t${constructor(t){if(void 0===t.types){this.typeLayouts=new Map;return}let e=t.types.map(e=>[e.name,tk.typeDefLayout(e,t.types)]);this.typeLayouts=new Map(e),this.idl=t}
3encode(t,e){let r=m.Buffer.alloc(1e3),n=this.typeLayouts.get(t);if(!n)throw Error(`Unknown type: ${t}`);let i=n.encode(e,r);return r.slice(0,i)}decode(t,e){let r=this.typeLayouts.get(t);if(!r)throw Error(`Unknown type: ${t}`);return r.decode(e)}}class tj{constructor(t){this.instruction=new tC(t),this.accounts=new tN(t),this.events=new tU(t),t.state&&(this.state=new tM(t)),this.types=new t$(t)}}var tq="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==r.g?r.g:"undefined"!=typeof self?self:{};class tK{constructor(t,e){if(!Number.isInteger(t))throw TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}decode(t,e){throw Error("Layout is abstract")}encode(t,e,r){throw Error("Layout is abstract")}getSpan(t,e){if(0>this.span)throw RangeError("indeterminate span");return this.span}replicate(t){let e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}var tz=tK;class tF extends tK{isCount(){throw Error("ExternalLayout is abstract")}}class tW extends tF{constructor(t,e,r){if(!(t instanceof tK))throw TypeError("layout must be a Layout");if(void 0===e)e=0;else if(!Number.isInteger(e))throw TypeError("offset must be integer or undefined");super(t.span,r||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof tH||this.layout instanceof tG}decode(t,e){return void 0===e&&(e=0),this.layout.decode(t,e+this.offset)}encode(t,e,r){return void 0===r&&(r=0),this.layout.encode(t,e,r+this.offset)}}class tH extends tK{constructor(t,e){if(super(t,e),6<this.span)throw RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readUIntLE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeUIntLE(t,r,this.span),this.span}}class tG extends tK{constructor(t,e){if(super(t,e),6<this.span)throw RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readUIntBE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeUIntBE(t,r,this.span),this.span}}function tJ(t){let e=Math.floor(t/4294967296);return{hi32:e,lo32:t-4294967296*e}}
3function tZ(t,e){return 4294967296*t+e}class tY extends tK{constructor(t){super(8,t)}decode(t,e){void 0===e&&(e=0);let r=t.readUInt32LE(e),n=t.readInt32LE(e+4);return tZ(n,r)}encode(t,e,r){void 0===r&&(r=0);let n=tJ(t);return e.writeUInt32LE(n.lo32,r),e.writeInt32LE(n.hi32,r+4),8}}class tX extends tK{constructor(t,e,r){if(!(Array.isArray(t)&&t.reduce((t,e)=>t&&e instanceof tK,!0)))throw TypeError("fields must be array of Layout instances");for(let n of("boolean"==typeof e&&void 0===r&&(r=e,e=void 0),t))if(0>n.span&&void 0===n.property)throw Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=t.reduce((t,e)=>t+e.getSpan(),0)}catch(t){}super(n,e),this.fields=t,this.decodePrefixes=!!r}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=0;try{r=this.fields.reduce((r,n)=>{let i=n.getSpan(t,e);return e+=i,r+i},0)}catch(t){throw RangeError("indeterminate span")}return r}decode(t,e){void 0===e&&(e=0);let r=this.makeDestinationObject();for(let n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(t,e)),e+=n.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return r}encode(t,e,r){void 0===r&&(r=0);let n=r,i=0,o=0;for(let n of this.fields){let s=n.span;if(o=0<s?s:0,void 0!==n.property){let i=t[n.property];void 0!==i&&(o=n.encode(i,e,r),0>s&&(s=n.getSpan(e,r)))}i=r,r+=s}return i+o-n}fromArray(t){let e=this.makeDestinationObject();for(let r of this.fields)void 0!==r.property&&0<t.length&&(e[r.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw TypeError("property must be string");for(let e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw TypeError("property must be string");let e=0;for(let r of this.fields){if(r.property===t)return e;0>r.span?e=-1:0<=e&&(e+=r.span)}}}class tQ{constructor(t){this.property=t}decode(){throw Error("UnionDiscriminator is abstract")}encode(){throw Error("UnionDiscriminator is abstract")}}class t0 extends tQ{constructor(t,e){if(!(t instanceof tF&&t.isCount()))throw TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,r){return this.layout.encode(t,e,r)}}class t1 extends tK{constructor(t,e,r){let n=t instanceof tH||t instanceof tG;if(n)t=new t0(new tW(t));else if(t instanceof tF&&t.isCount())t=new t0(t);else if(!(t instanceof tQ))throw TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===e&&(e=null),!(null===e||e instanceof tK))throw TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let i=-1;e&&0<=(i=e.span)&&n&&(i+=t.layout.span),super(i,r),this.discriminator=t,this.usesPrefixDiscriminator=n,this.defaultLayout=e,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return o(t)},this.configGetSourceVariant=function(t){o=t.bind(this)}}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=this.getVariant(t,e);if(!r)throw Error("unable to determine span for unrecognized variant");return r.getSpan(t,e)}defaultGetSourceVariant(t){if(t.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&t.hasOwnProperty(this.defaultLayout.property))return;let e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||t.hasOwnProperty(e.property)))return e}else for(let e in this.registry){let r=this.registry[e];if(t.hasOwnProperty(r.property))return r}throw Error("unable to infer src variant")}decode(t,e){let r;void 0===e&&(e=0);let n=this.discriminator,i=n.decode(t,e),o=this.registry[i];if(void 0===o){let s=0;o=this.defaultLayout,this.usesPrefixDiscriminator&&(s=n.layout.span),(r=this.makeDestinationObject())[n.property]=i,r[o.property]=this.defaultLayout.decode(t,e+s)}else r=o.decode(t,e);return r}encode(t,e,r){void 0===r&&(r=0);let n=this.getSourceVariant(t);if(void 0===n){let n=this.discriminator,i=this.defaultLayout,o=0;return this.usesPrefixDiscriminator&&(o=n.layout.span),n.encode(t[n.property],e,r),o+i.encode(t[i.property],e,r+o)}return n.encode(t,e,r)}addVariant(t,e,r){let n=new t2(this,t,e,r);return this.registry[t]=n,n}getVariant(t,e){let r=t;return C.isBuffer(t)&&(void 0===e&&(e=0),r=this.discriminator.decode(t,e)),this.registry[r]}}class t2 extends tK{constructor(t,e,r,n){if(!(t instanceof t1))throw TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof tK))throw TypeError("layout must be a Layout");
3if(null!==t.defaultLayout&&0<=r.span&&r.span>t.defaultLayout.span)throw Error("variant span exceeds span of containing union");if("string"!=typeof n)throw TypeError("variant must have a String property")}let i=t.span;0>t.span&&0<=(i=r?r.span:0)&&t.usesPrefixDiscriminator&&(i+=t.discriminator.layout.span),super(i,n),this.union=t,this.variant=e,this.layout=r||null}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(t,e+r)}decode(t,e){let r=this.makeDestinationObject();if(void 0===e&&(e=0),this!==this.union.getVariant(t,e))throw Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(t,e+n):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(t,e,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!t.hasOwnProperty(this.property))throw TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,r);let i=n;if(this.layout&&(this.layout.encode(t[this.property],e,r+n),i+=this.layout.getSpan(e,r+n),0<=this.union.span&&i>this.union.span))throw Error("encoded variant overruns containing union");return i}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}class t3 extends tK{constructor(t,e){if(!(t instanceof tF&&t.isCount()||Number.isInteger(t)&&0<=t))throw TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;t instanceof tF||(r=t),super(r,e),this.length=t}getSpan(t,e){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),r}decode(t,e){void 0===e&&(e=0);let r=this.span;return 0>r&&(r=this.length.decode(t,e)),t.slice(e,e+r)}encode(t,e,r){let n=this.length;if(this.length instanceof tF&&(n=t.length),!(C.isBuffer(t)&&n===t.length)){var i;throw TypeError((i="Blob.encode",(this.property?i+"["+this.property+"]":i)+" requires (length "+n+") Buffer as src"))}if(r+n>e.length)throw RangeError("encoding overruns Buffer");return e.write(t.toString("hex"),r,n,"hex"),this.length instanceof tF&&this.length.encode(n,e,r),n}}var t8=(t,e,r)=>new tW(t,e,r),t6=t=>new tH(1,t),t4=t=>new tH(4,t),t5=t=>new tY(t),t9=(t,e,r)=>new tX(t,e,r),t7=(t,e,r)=>new t1(t,e,r),et=(t,e)=>new t3(t,e);class ee extends tz{constructor(t){super(-1,t),this.property=t,this.layout=t9([t4("length"),t4("lengthPadding"),et(t8(t4(),-8),"chars")],this.property)}encode(t,e,r=0){if(null==t)return this.layout.span;let n={chars:C.from(t,"utf8")};return this.layout.encode(n,e,r)}decode(t,e=0){let r=this.layout.decode(t,e);return r.chars.toString()}getSpan(t,e=0){return t4().span+t4().span+new(w())(new Uint8Array(t).slice(e,e+4),10,"le").toNumber()}}function er(t){return new ee(t)}function en(t){return et(32,t)}let ei=t7(t4("instruction"));ei.addVariant(0,t9([t5("lamports"),t5("space"),en("owner")]),"createAccount"),ei.addVariant(1,t9([en("owner")]),"assign"),ei.addVariant(2,t9([t5("lamports")]),"transfer"),ei.addVariant(3,t9([en("base"),er("seed"),t5("lamports"),t5("space"),en("owner")]),"createAccountWithSeed"),ei.addVariant(4,t9([en("authorized")]),"advanceNonceAccount"),ei.addVariant(5,t9([t5("lamports")]),"withdrawNonceAccount"),ei.addVariant(6,t9([en("authorized")]),"initializeNonceAccount"),ei.addVariant(7,t9([en("authorized")]),"authorizeNonceAccount"),ei.addVariant(8,t9([t5("space")]),"allocate"),ei.addVariant(9,t9([en("base"),er("seed"),t5("space"),en("owner")]),"allocateWithSeed"),ei.addVariant(10,t9([en("base"),er("seed"),en("owner")]),"assignWithSeed"),ei.addVariant(11,t9([t5("lamports"),er("seed"),en("owner")]),"transferWithSeed"),Object.values(ei.registry).map(t=>t.span);class eo extends tz{constructor(t,e,r,n){super(t.span,n),this.layout=t,this.decoder=e,this.encoder=r}decode(t,e){return this.decoder(this.layout.decode(t,e))}encode(t,e,r){return this.layout.encode(this.encoder(t),e,r)}getSpan(t,e){return this.layout.getSpan(t,e)}}function es(t){return new eo(et(32),t=>new g.PublicKey(t),t=>t.toBuffer(),t)}function ea(t,e){let r,n=255;for(;0!=n;){try{let i=t.concat(m.Buffer.from([n]));r=function(t,e){let r=m.Buffer.alloc(0);t.forEach(function(t){if(t.length>32)throw TypeError("Max seed length exceeded");r=m.Buffer.concat([r,ec(t)])}),r=m.Buffer.concat([r,e.toBuffer(),m.Buffer.from("ProgramDerivedAddress")]);let n=(0,x.sha256)(new Uint8Array(r)),i=new(w())(n,16).toArray(void 0,32);if(g.PublicKey.isOnCurve(new Uint8Array(i)))throw Error("Invalid seeds, address must fall off the curve");return new g.PublicKey(i)}(i,e)}catch(t){if(t instanceof TypeError)throw t;n--;continue}return[r,n]}throw Error("Unable to find a viable program address nonce")}t9([t4("version"),t4("state"),es("authorizedPubkey"),es("nonce"),t9([new class extends tK{constructor(t){super(8,t)}decode(t,e){void 0===e&&(e=0);let r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return tZ(n,r)}encode(t,e,r){void 0===r&&(r=0);let n=tJ(t);return e.writeUInt32LE(n.lo32,r),e.writeUInt32LE(n.hi32,r+4),8}}
3("lamportsPerSignature")],"feeCalculator")]);let ec=t=>t instanceof m.Buffer?t:t instanceof Uint8Array?m.Buffer.from(t.buffer,t.byteOffset,t.byteLength):m.Buffer.from(t);async function eu(t,...e){let r=[m.Buffer.from([97,110,99,104,111,114])];e.forEach(t=>{r.push(t instanceof m.Buffer?t:R(t).toBuffer())});let[n]=await g.PublicKey.findProgramAddress(r,R(t));return n}let el=new g.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),ed=new g.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");var eh={exports:{}};a=eh,c=eh.exports,u="undefined"!=typeof self?self:tq,d=l=function(){function t(){this.fetch=!1,this.DOMException=u.DOMException}return t.prototype=u,new t}(),function(t){var e={searchParams:"URLSearchParams"in d,iterable:"Symbol"in d&&"iterator"in Symbol,blob:"FileReader"in d&&"Blob"in d&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in d,arrayBuffer:"ArrayBuffer"in d};if(e.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&r.indexOf(Object.prototype.toString.call(t))>-1};function i(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function s(t){var r={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return e.iterable&&(r[Symbol.iterator]=function(){return r}),r}function a(t){this.map={},t instanceof a?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function c(t){if(t.bodyUsed)return Promise.reject(TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function l(t){var e=new FileReader,r=u(e);return e.readAsArrayBuffer(t),r}function h(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function f(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t){if("string"==typeof t)this._bodyText=t;else if(e.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(e.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else{var r;e.arrayBuffer&&e.blob&&(r=t)&&DataView.prototype.isPrototypeOf(r)?(this._bodyArrayBuffer=h(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):e.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=h(t):this._bodyText=t=Object.prototype.toString.call(t)}}else this._bodyText="";!this.headers.get("content-type")&&("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(!this._bodyFormData)return Promise.resolve(new Blob([this._bodyText]));throw Error("could not read FormData body as blob")},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,e,r,n=c(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=u(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(!this._bodyFormData)return Promise.resolve(this._bodyText);throw Error("could not read FormData body as text")},e.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}a.prototype.append=function(t,e){t=i(t),e=o(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},a.prototype.delete=function(t){delete this.map[i(t)]},a.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},a.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},a.prototype.set=function(t,e){this.map[i(t)]=o(e)},a.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},a.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),s(t)},a.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),s(t)},a.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),s(t)},e.iterable&&(a.prototype[Symbol.iterator]=a.prototype.entries);
3var p=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var r,n,i=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new a(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",(e.headers||!this.headers)&&(this.headers=new a(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),p.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function m(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}}),e}function g(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new a(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},f.call(y.prototype),f.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new a(this.headers),url:this.url})},g.error=function(){var t=new g(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];g.redirect=function(t,e){if(-1===v.indexOf(e))throw RangeError("Invalid status code");return new g(null,{status:e,headers:{location:t}})},t.DOMException=d.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function w(r,n){return new Promise(function(i,o){var s=new y(r,n);if(s.signal&&s.signal.aborted)return o(new t.DOMException("Aborted","AbortError"));var c=new XMLHttpRequest;function u(){c.abort()}c.onload=function(){var t,e,r={status:c.status,statusText:c.statusText,headers:(t=c.getAllResponseHeaders()||"",e=new a,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}}),e)};r.url="responseURL"in c?c.responseURL:r.headers.get("X-Request-URL");var n="response"in c?c.response:c.responseText;i(new g(n,r))},c.onerror=function(){o(TypeError("Network request failed"))},c.ontimeout=function(){o(TypeError("Network request failed"))},c.onabort=function(){o(new t.DOMException("Aborted","AbortError"))},c.open(s.method,s.url,!0),"include"===s.credentials?c.withCredentials=!0:"omit"===s.credentials&&(c.withCredentials=!1),"responseType"in c&&e.blob&&(c.responseType="blob"),s.headers.forEach(function(t,e){c.setRequestHeader(e,t)}),s.signal&&(s.signal.addEventListener("abort",u),c.onreadystatechange=function(){4===c.readyState&&s.signal.removeEventListener("abort",u)}),c.send(void 0===s._bodyInit?null:s._bodyInit)})}w.polyfill=!0,d.fetch||(d.fetch=w,d.Headers=a,d.Request=y,d.Response=g),t.Headers=a,t.Request=y,t.Response=g,t.fetch=w,Object.defineProperty(t,"__esModule",{value:!0})}({}),l.fetch.ponyfill=!0,delete l.fetch.polyfill,(c=l.fetch).default=l.fetch,c.fetch=l.fetch,c.Headers=l.Headers,c.Request=l.Request,c.Response=l.Response,a.exports=c,(h=eh.exports)&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")&&h.default;let ef=S.rustEnum([S.struct([],"uninitialized"),S.struct([S.option(S.publicKey(),"authorityAddress")],"buffer"),S.struct([S.publicKey("programdataAddress")],"program"),S.struct([S.u64("slot"),S.option(S.publicKey(),"upgradeAuthorityAddress")],"programData")],void 0,S.u32());async function ep(t){let e=(await g.PublicKey.findProgramAddress([],t))[0];return await g.PublicKey.createWithSeed(e,"anchor:idl",t)}let ey=S.struct([S.publicKey("authority"),S.vecU8("data")]);function em(t,e){var r,n;let i={},o=t.args?t.args.length:0;if(e.length>
3o){if(e.length!==o+1)throw Error(`provided too many arguments ${e} to instruction ${null==t?void 0:t.name} expecting: ${null!==(n=null===(r=t.args)||void 0===r?void 0:r.map(t=>t.name))&&void 0!==n?n:[]}`);i=e.pop()}return[e,i]}class eg{static build(t,e,r){if("_inner"===t.name)throw new ty("the _inner name is reserved");let n=(...i)=>{let[o,s]=em(t,[...i]);O(t.accounts,s.accounts),[...i];let a=n.accounts(s.accounts);return void 0!==s.remainingAccounts&&a.push(...s.remainingAccounts),tp("debug-logs")&&console.log("Outgoing account metas:",a),new g.TransactionInstruction({keys:a,programId:r,data:e(t.name,function(t,...e){if(t.args.length!=e.length)throw Error("Invalid argument length");let r={},n=0;return t.args.forEach(t=>{r[t.name]=e[n],n+=1}),r}(t,...o))})};return n.accounts=e=>eg.accountsArray(e,t.accounts,r,t.name),n}static accountsArray(t,e,r,n){return t?e.map(e=>{let i="accounts"in e?e.accounts:void 0;if(void 0!==i){let i=t[e.name];return eg.accountsArray(i,e.accounts,r,n).flat()}{let i;try{i=R(t[e.name])}catch(t){throw Error(`Wrong input type for account "${e.name}" in the instruction accounts object${void 0!==n?' for instruction "'+n+'"':""}. Expected PublicKey or string.`)}let o=e.isOptional&&i.equals(r),s=e.isMut&&!o,a=e.isSigner&&!o;return{pubkey:i,isWritable:s,isSigner:a}}}).flat():[]}}class ev{static build(t,e,r,n){let i=async(...i)=>{var o;let s=e(...i),[,a]=em(t,[...i]);if(void 0===n.sendAndConfirm)throw Error("This function requires 'Provider.sendAndConfirm' to be implemented.");try{return await n.sendAndConfirm(s,null!==(o=a.signers)&&void 0!==o?o:[],a.options)}catch(t){throw tw(t,r)}};return i}}class ew{static build(t,e){let r=(...r)=>{var n,i,o;let[,s]=em(t,[...r]),a=new g.Transaction;if(s.preInstructions&&s.instructions)throw Error("instructions is deprecated, use preInstructions");return null===(n=s.preInstructions)||void 0===n||n.forEach(t=>a.add(t)),null===(i=s.instructions)||void 0===i||i.forEach(t=>a.add(t)),a.add(e(...r)),null===(o=s.postInstructions)||void 0===o||o.forEach(t=>a.add(t)),a};return r}}class eb{static build(t,e,r,n){if(void 0!==t.state)return new e_(t,r,n,e)}}class e_{get programId(){return this._programId}constructor(t,e,r=td(),n=new tj(t)){var i;let o,s,a;
3this.provider=r,this.coder=n,this._idl=t,this._programId=e,this._address=eA(e),this._sub=null;let[c,u,l]=(o={},s={},a={},null===(i=t.state)||void 0===i||i.methods.forEach(i=>{let c=eg.build(i,(t,e)=>n.instruction.encodeState(t,e),e);c.accounts=t=>{let n=function(t,e,r,n){if("new"!==r.name)return O(r.accounts,n),[{pubkey:eA(t),isWritable:!0,isSigner:!1}];{let[r]=ea([],t);if(void 0===e.wallet)throw Error("This function requires the Provider interface implementor to have a 'wallet' field.");return[{pubkey:e.wallet.publicKey,isWritable:!1,isSigner:!0},{pubkey:eA(t),isWritable:!0,isSigner:!1},{pubkey:r,isWritable:!1,isSigner:!1},{pubkey:g.SystemProgram.programId,isWritable:!1,isSigner:!1},{pubkey:t,isWritable:!1,isSigner:!1}]}}(e,r,i,t);return n.concat(eg.accountsArray(t,i.accounts,e,i.name))};let u=ew.build(i,c),l=ev.build(i,u,D(t),r),d=I()(i.name);o[d]=c,s[d]=u,a[d]=l}),[o,s,a]);this.instruction=c,this.transaction=u,this.rpc=l}async fetch(){let t=this.address(),e=await this.provider.connection.getAccountInfo(t);if(null===e)throw Error(`Account does not exist ${t.toString()}`);let r=this._idl.state;if(!r)throw Error("State is not specified in IDL.");let n=await tV(r.struct.name);if(n.compare(e.data.slice(0,8)))throw Error("Invalid account discriminator");return this.coder.state.decode(e.data)}address(){return this._address}subscribe(t){if(null!==this._sub)return this._sub.ee;let e=new(L()),r=this.provider.connection.onAccountChange(this.address(),t=>{let r=this.coder.state.decode(t.data);e.emit("change",r)},t);return this._sub={ee:e,listener:r},e}
3unsubscribe(){null!==this._sub&&this.provider.connection.removeAccountChangeListener(this._sub.listener).then(async()=>{this._sub=null}).catch(console.error)}}function eA(t){let[e]=ea([],t);return function(t,e,r){let n=m.Buffer.concat([t.toBuffer(),m.Buffer.from(e),r.toBuffer()]),i=x.sha256.digest(n);return new g.PublicKey(m.Buffer.from(i))}(e,"unversioned",t)}class eE{static build(t,e,r,n){var i;let o={};return null===(i=t.accounts)||void 0===i||i.forEach(i=>{let s=I()(i.name);o[s]=new eI(t,i,r,n,e)}),o}}class eI{get size(){return this._size}get programId(){return this._programId}get provider(){return this._provider}get coder(){return this._coder}constructor(t,e,r,n,i){this._idlAccount=e,this._programId=r,this._provider=null!=n?n:td(),this._coder=null!=i?i:new tj(t),this._size=this._coder.accounts.size(e)}async fetchNullable(t,e){let{data:r}=await this.fetchNullableAndContext(t,e);return r}async fetchNullableAndContext(t,e){let r=await this.getAccountInfoAndContext(t,e),{value:n,context:i}=r;return{data:n&&0!==n.data.length?this._coder.accounts.decode(this._idlAccount.name,n.data):null,context:i}}async fetch(t,e){let{data:r}=await this.fetchNullableAndContext(t,e);if(null===r)throw Error(`Account does not exist or has no data ${t.toString()}`);return r}async fetchAndContext(t,e){let{data:r,context:n}=await this.fetchNullableAndContext(t,e);if(null===r)throw Error(`Account does not exist ${t.toString()}`);return{data:r,context:n}}async fetchMultiple(t,e){let r=await this.fetchMultipleAndContext(t,e);return r.map(t=>t?t.data:null)}async fetchMultipleAndContext(t,e){let r=await te(this._provider.connection,t.map(t=>R(t)),e);return r.map(t=>{if(null==t)return null;let{account:e,context:r}=t;return{data:this._coder.accounts.decode(this._idlAccount.name,e.data),context:r}})}async all(t){let e=this.coder.accounts.memcmp(this._idlAccount.name,t instanceof C?t:void 0),r=[];return(null==e?void 0:e.offset)!=void 0&&(null==e?void 0:e.bytes)!=void 0&&r.push({memcmp:{offset:e.offset,bytes:e.bytes}}),(null==e?void 0:e.dataSize)!=void 0&&r.push({dataSize:e.dataSize}),(await this._provider.connection.getProgramAccounts(this._programId,{commitment:this._provider.connection.commitment,filters:[...r,...Array.isArray(t)?t:[]]})).map(({pubkey:t,account:e})=>({publicKey:t,account:this._coder.accounts.decode(this._idlAccount.name,e.data)}))}subscribe(t,e){let r=ex.get(t.toString());if(r)return r.ee;let n=new(L());t=R(t);let i=this._provider.connection.onAccountChange(t,t=>{let e=this._coder.accounts.decode(this._idlAccount.name,t.data);n.emit("change",e)},e);return ex.set(t.toString(),{ee:n,listener:i}),n}async unsubscribe(t){let e=ex.get(t.toString());if(!e){console.warn("Address is not subscribed");return}ex&&await this._provider.connection.removeAccountChangeListener(e.listener).then(()=>{ex.delete(t.toString())}).catch(console.error)}async createInstruction(t,e){let r=this.size;if(void 0===this._provider.publicKey)throw Error("This function requires the Provider interface implementor to have a 'publicKey' field.");return g.SystemProgram.createAccount({fromPubkey:this._provider.publicKey,newAccountPubkey:t.publicKey,space:null!=e?e:r,lamports:await this._provider.connection.getMinimumBalanceForRentExemption(null!=e?e:r),programId:this._programId})}async associated(...t){let e=await this.associatedAddress(...t);return await this.fetch(e)}async associatedAddress(...t){return await eu(this._programId,...t)}async getAccountInfo(t,e){return await this._provider.connection.getAccountInfo(R(t),e)}async getAccountInfoAndContext(t,e){return await this._provider.connection.getAccountInfoAndContext(R(t),e)}}let ex=new Map,eS="Program log: ",eP="Program data: ",ek=eS.length,eL=eP.length;class eT{constructor(t,e,r){this._programId=t,this._provider=e,this._eventParser=new eC(t,r),this._eventCallbacks=new Map,this._eventListeners=new Map,this._listenerIdCount=0}addEventListener(t,e){var r;let n=this._listenerIdCount;return this._listenerIdCount+=1,this._eventListeners.has(t)||this._eventListeners.set(t,[]),this._eventListeners.set(t,(null!==(r=this._eventListeners.get(t))&&void 0!==r?r:[]).concat(n)),this._eventCallbacks.set(n,[t,e]),void 0!==this._onLogsSubscriptionId||(this._onLogsSubscriptionId=this._provider.connection.onLogs(this._programId,(t,e)=>{if(!t.err)for(let r of this._eventParser.parseLogs(t.logs)){let n=this._eventListeners.get(r.name);
3n&&n.forEach(n=>{let i=this._eventCallbacks.get(n);if(i){let[,n]=i;n(r.data,e.slot,t.signature)}})}})),n}async removeEventListener(t){let e=this._eventCallbacks.get(t);if(!e)throw Error(`Event listener ${t} doesn't exist!`);let[r]=e,n=this._eventListeners.get(r);if(!n)throw Error(`Event listeners don't exist for ${r}!`);this._eventCallbacks.delete(t),n=n.filter(e=>e!==t),this._eventListeners.set(r,n),0===n.length&&this._eventListeners.delete(r),0==this._eventCallbacks.size&&(T.ok(0===this._eventListeners.size),void 0!==this._onLogsSubscriptionId&&(await this._provider.connection.removeOnLogsListener(this._onLogsSubscriptionId),this._onLogsSubscriptionId=void 0))}}class eC{constructor(t,e){this.coder=e,this.programId=t}*parseLogs(t,e=!1){let r=new eD(t),n=new eB,i=r.next();for(;null!==i;){let[t,o,s]=this.handleLog(n,i,e);t&&(yield t),o&&n.push(o),s&&n.pop(),i=r.next()}}handleLog(t,e,r){return t.stack.length>0&&t.program()===this.programId.toString()?this.handleProgramLog(e,r):[null,...this.handleSystemLog(e)]}handleProgramLog(t,e){if(!(t.startsWith(eS)||t.startsWith(eP)))return[null,...this.handleSystemLog(t)];{let r=t.startsWith(eS)?t.slice(ek):t.slice(eL),n=this.coder.events.decode(r);if(e&&null===n)throw Error(`Unable to decode event ${r}`);return[n,null,!1]}}handleSystemLog(t){let e=t.split(":")[0];return null!==e.match(/^Program (.*) success/g)?[null,!0]:e.startsWith(`Program ${this.programId.toString()} invoke`)?[this.programId.toString(),!1]:e.includes("invoke")?["cpi",!1]:[null,!1]}}class eB{constructor(){this.stack=[]}program(){return T.ok(this.stack.length>0),this.stack[this.stack.length-1]}push(t){this.stack.push(t)}pop(){T.ok(this.stack.length>0),this.stack.pop()}}class eD{constructor(t){this.logs=t}next(){if(0===this.logs.length)return null;let t=this.logs[0];return this.logs=this.logs.slice(1),t}}class eO{static build(t,e,r,n,i,o,s){let a=async(...a)=>{var c;let u;let l=e(...a),[,d]=em(t,[...a]);if(void 0===n.simulate)throw Error("This function requires 'Provider.simulate' to be implemented.");try{u=await n.simulate(l,d.signers,null===(c=d.options)||void 0===c?void 0:c.commitment)}catch(t){throw tw(t,r)}if(void 0===u)throw Error("Unable to simulate transaction");let h=u.logs;if(!h)throw Error("Simulated logs not found");let f=[];if(s.events)for(let t of new eC(o,i).parseLogs(h))f.push(t);return{events:f,raw:h}};return a}}function eR(t){return new eU(et(8),t=>eV.fromBuffer(t),t=>t.toBuffer(),t)}function eN(t){return new eU(et(32),t=>new g.PublicKey(t),t=>t.toBuffer(),t)}class eU extends tz{constructor(t,e,r,n){super(t.span,n),this.layout=t,this.decoder=e,this.encoder=r}decode(t,e){return this.decoder(this.layout.decode(t,e))}encode(t,e,r){return this.layout.encode(this.encoder(t),e,r)}getSpan(t,e){return this.layout.getSpan(t,e)}}class eM extends tz{constructor(t,e){super(-1,e),this.layout=t,this.discriminator=t4()}encode(t,e,r=0){return null==t?this.layout.span+this.discriminator.encode(0,e,r):(this.discriminator.encode(1,e,r),this.layout.encode(t,e,r+4)+4)}decode(t,e=0){let r=this.discriminator.decode(t,e);if(0===r)return null;if(1===r)return this.layout.decode(t,e+4);throw Error("Invalid coption "+this.layout.property)}getSpan(t,e=0){return this.layout.getSpan(t,e+4)+4}}class eV extends w(){toBuffer(){let t=super.toArray().reverse(),e=C.from(t);if(8===e.length)return e;if(e.length>=8)throw Error("u64 too large");let r=C.alloc(8);return e.copy(r),r}static fromBuffer(t){if(8!==t.length)throw Error(`Invalid buffer length: ${t.length}`);return new eV([...t].reverse().map(t=>`00${t.toString(16)}`.slice(-2)).join(""),16)}}let e$=t9([eN("mint"),eN("owner"),eR("amount"),(f=eN(),new eM(f,"delegate")),(t=>{let e=t7(t6("discriminator"),null,t);return e.addVariant(0,t9([]),"uninitialized"),e.addVariant(1,t9([]),"initialized"),e.addVariant(2,t9([]),"frozen"),e})("state"),(p=eR(),new eM(p,"isNative")),eR("delegatedAmount"),(y=eN(),new eM(y,"closeAuthority"))]);class ej{constructor(t,e,r,n,i,o,s,a){this._accounts=e,this._provider=r,this._programId=n,this._idlIx=i,this._idlTypes=s,this._customResolver=a,this._args=t,this._accountStore=new eq(r,o,this._programId)}args(t){this._args=t}async resolve(){for(await this.resolveConst(this._idlIx.accounts);await this.resolvePdas(this._idlIx.accounts)+await this.resolveRelations(this._idlIx.accounts)+await this.resolveCustom()>0;);}
3async resolveCustom(){if(this._customResolver){let{accounts:t,resolved:e}=await this._customResolver({args:this._args,accounts:this._accounts,provider:this._provider,programId:this._programId,idlIx:this._idlIx});return this._accounts=t,e}return 0}resolveOptionalsHelper(t,e){let r={};for(let n of e){let e=n.name,i=t[e];void 0!==i&&(ez(i)?"accounts"in n?r[e]=this.resolveOptionalsHelper(i,n.accounts):r[e]=function t(e,r){let n={};for(let i in e){let o=e[i];if(null===o){if(r)throw Error("Failed to resolve optionals due to IDL type mismatch with input accounts!");continue}n[i]=ez(o)?t(o,!0):R(o)}return n}(i,!0):null!==i?r[e]=R(i):n.isOptional&&(r[e]=this._programId))}return r}resolveOptionals(t){Object.assign(this._accounts,this.resolveOptionalsHelper(t,this._idlIx.accounts))}get(t){let e=t.reduce((t,e)=>t&&t[e],this._accounts);if(e&&e.toBase58)return e}set(t,e){let r=this._accounts;t.forEach((n,i)=>{let o=i==t.length-1;o&&(r[n]=e),r[n]=r[n]||{},r=r[n]})}async resolveConst(t,e=[]){for(let r=0;r<t.length;r+=1){let n=t[r],i=n.accounts;i&&await this.resolveConst(i,[...e,I()(n.name)]);let o=I()(n.name);if(n.isSigner&&!this.get([...e,o])){if(void 0===this._provider.wallet)throw Error("This function requires the Provider interface implementor to have a 'wallet' field.");this.set([...e,o],this._provider.wallet.publicKey)}Reflect.has(ej.CONST_ACCOUNTS,o)&&!this.get([...e,o])&&this.set([...e,o],ej.CONST_ACCOUNTS[o])}}async resolvePdas(t,e=[]){let r=0;for(let n=0;n<t.length;n+=1){let i=t[n],o=i.accounts;o&&(r+=await this.resolvePdas(o,[...e,I()(i.name)]));let s=I()(i.name);i.pda&&i.pda.seeds.length>0&&!this.get([...e,s])&&await this.autoPopulatePda(i,e)&&(r+=1)}return r}async resolveRelations(t,e=[]){let r=0;for(let n=0;n<t.length;n+=1){let i=t[n],o=i.accounts;o&&(r+=await this.resolveRelations(o,[...e,I()(i.name)]));let s=i.relations||[],a=I()(i.name),c=[...e,a],u=this.get(c);if(u){let t=s.filter(t=>!this.get([...e,I()(t)]));if(r+=t.length,t.length>0){let r=await this._accountStore.fetchAccount({publicKey:u});await Promise.all(t.map(async t=>{let n=I()(t);return this.set([...e,n],r[n]),r[n]}))}}}return r}async autoPopulatePda(t,e=[]){if(!t.pda||!t.pda.seeds)throw Error("Must have seeds");let r=await Promise.all(t.pda.seeds.map(t=>this.toBuffer(t,e)));if(r.some(t=>void 0===t))return;let n=await this.parseProgramId(t,e);if(!n)return;let[i]=await g.PublicKey.findProgramAddress(r,n);this.set([...e,I()(t.name)],i)}async parseProgramId(t,e=[]){var r;if(!(null===(r=t.pda)||void 0===r?void 0:r.programId))return this._programId;switch(t.pda.programId.kind){case"const":return new g.PublicKey(this.toBufferConst(t.pda.programId.value));case"arg":return this.argValue(t.pda.programId);case"account":return await this.accountValue(t.pda.programId,e);default:throw Error(`Unexpected program seed kind: ${t.pda.programId.kind}`)}}async toBuffer(t,e=[]){switch(t.kind){case"const":return this.toBufferConst(t);case"arg":return await this.toBufferArg(t);case"account":return await this.toBufferAccount(t,e);default:throw Error(`Unexpected seed kind: ${t.kind}`)}}getType(t,e=[]){if(e.length>0&&t.defined){let r=this._idlTypes.find(e=>e.name===t.defined);if(!r)throw Error(`Cannot find type ${t.defined}`);let n=r.type,i=n.fields.find(t=>t.name===e[0]);return this.getType(i.type,e.slice(1))}return t}toBufferConst(t){return this.toBufferValue(this.getType(t.type,(t.path||"").split(".").slice(1)),t.value)}async toBufferArg(t){let e=this.argValue(t);if(void 0!==e)return this.toBufferValue(this.getType(t.type,(t.path||"").split(".").slice(1)),e)}argValue(t){let e=t.path.split("."),r=I()(e[0]),n=this._idlIx.args.findIndex(t=>t.name===r);if(-1===n)throw Error(`Unable to find argument for seed: ${r}`);return e.slice(1).reduce((t,e)=>(t||{})[e],this._args[n])}async toBufferAccount(t,e=[]){let r=await this.accountValue(t,e);if(r)return this.toBufferValue(t.type,r)}async accountValue(t,e=[]){let r=t.path.split("."),n=r[0],i=this.get([...e,I()(n)]);if(null===i)throw Error("fieldPubkey is null");if(1===r.length)return i;let o=await this._accountStore.fetchAccount({publicKey:i,name:t.account}),s=this.parseAccountValue(o,r.slice(1));return s}parseAccountValue(t,e){let r;for(;e.length>0;)r=t[I()(e[0])],e=e.slice(1);return r}toBufferValue(t,e){switch(t){case"u8":return C.from([e]);case"u16":let r=C.alloc(2);return r.writeUInt16LE(e),r;case"u32":let n=C.alloc(4);return n.writeUInt32LE(e),n;case"u64":let i=C.alloc(8);return i.writeBigUInt64LE(BigInt(e)),i;case"string":return C.from(function(t){let e=new TextEncoder;return e.encode(t)}(e));case"publicKey":return e.toBuffer();default:if(t.array)return C.from(e);throw Error(`Unexpected seed type: ${t}`)}}}ej.CONST_ACCOUNTS={associatedTokenProgram:ed,rent:g.SYSVAR_RENT_PUBKEY,systemProgram:g.SystemProgram.programId,tokenProgram:el,clock:g.SYSVAR_CLOCK_PUBKEY};class eq{constructor(t,e,r){this._provider=t,this._programId=r,this._cache=new Map,this._idls={},this._idls[r.toBase58()]=e}async ensureIdl(t){if(!this._idls[t.toBase58()]){let e=await eG.fetchIdl(t,this._provider);if(e){let r=new eG(e,t,this._provider);this._idls[t.toBase58()]=r.account}}return this._idls[t.toBase58()]}async fetchAccount({publicKey:t,name:e,programId:r=this._programId}){let n=t.toString();if(!this._cache.has(n)){if("TokenAccount"===e){var i;let e=await this._provider.connection.getAccountInfo(t);if(null===e)throw Error(`invalid account info for ${n}`);let r=(i=e.data,e$.decode(i));this._cache.set(n,r)}else if(e){let i=await this.ensureIdl(r);if(i){let r=i[I()(e)];if(r){let e=await r.fetch(t);this._cache.set(n,e)}}}else{let e=await this._provider.connection.getAccountInfo(t);if(null===e)throw Error(`invalid account info for ${n}`);let r=e.data,i=await this.ensureIdl(e.owner);if(i){let t=Object.values(i)[0];if(!t)throw Error("No accounts for this program");let e=t.coder.accounts.decodeAny(r);this._cache.set(n,e)}}}return this._cache.get(n)}}class eK{static build(t,e,r,n,i,o,s,a,c,u,l){return(...d)=>new eF(d,n,i,o,s,a,t,e,r,c,u,l)}}function ez(t){return"object"==typeof t&&null!==t&&!("_bn"in t)}class eF{constructor(t,e,r,n,i,o,s,a,c,u,l,d){this._ixFn=e,this._txFn=r,this._rpcFn=n,this._simulateFn=i,this._viewFn=o,this._programId=a,this._accounts={},this._remainingAccounts=[],this._signers=[],this._preInstructions=[],this._postInstructions=[],this._autoResolveAccounts=!0,this._args=t,this._accountsResolver=new ej(t,this._accounts,s,a,c,u,l,d)}args(t){this._args=t,this._accountsResolver.args(t)}async pubkeys(){return this._autoResolveAccounts&&await this._accountsResolver.resolve(),this._accounts}accounts(t){return this._autoResolveAccounts=!0,this._accountsResolver.resolveOptionals(t),this}accountsStrict(t){return this._autoResolveAccounts=!1,this._accountsResolver.resolveOptionals(t),this}signers(t){return this._signers=this._signers.concat(t),this}remainingAccounts(t){return this._remainingAccounts=this._remainingAccounts.concat(t),this}preInstructions(t){return this._preInstructions=this._preInstructions.concat(t),this}postInstructions(t){return this._postInstructions=this._postInstructions.concat(t),this}async rpc(t){return this._autoResolveAccounts&&await this._accountsResolver.resolve(),this._rpcFn(...this._args,{accounts:this._accounts,signers:this._signers,remainingAccounts:this._remainingAccounts,preInstructions:this._preInstructions,postInstructions:this._postInstructions,options:t})}async rpcAndKeys(t){let e=await this.pubkeys();return{pubkeys:e,signature:await this.rpc(t)}}async view(t){if(this._autoResolveAccounts&&await this._accountsResolver.resolve(),!this._viewFn)throw Error("Method does not support views");return this._viewFn(...this._args,{accounts:this._accounts,signers:this._signers,remainingAccounts:this._remainingAccounts,preInstructions:this._preInstructions,postInstructions:this._postInstructions,options:t})}async simulate(t){return this._autoResolveAccounts&&await this._accountsResolver.resolve(),this._simulateFn(...this._args,{accounts:this._accounts,signers:this._signers,remainingAccounts:this._remainingAccounts,preInstructions:this._preInstructions,postInstructions:this._postInstructions,options:t})}async instruction(){return this._autoResolveAccounts&&await this._accountsResolver.resolve(),this._ixFn(...this._args,{accounts:this._accounts,signers:this._signers,remainingAccounts:this._remainingAccounts,preInstructions:this._preInstructions,postInstructions:this._postInstructions})}async prepare(){return{instruction:await this.instruction(),pubkeys:await this.pubkeys(),signers:await this._signers}}async transaction(){return this._autoResolveAccounts&&await this._accountsResolver.resolve(),this._txFn(...this._args,{accounts:this._accounts,signers:this._signers,remainingAccounts:this._remainingAccounts,preInstructions:this._preInstructions,postInstructions:this._postInstructions})}}class eW{static build(t,e,r,n){let i=e.accounts.find(t=>t.isMut),o=!!e.returns;if(i||!o)return;let s=async(...i)=>{var o,s,a;let c=await r(...i),u=`Program return: ${t} `,l=c.raw.find(t=>t.startsWith(u));if(!l)throw Error("View expected return log");let d=(a=l.slice(u.length),m.Buffer.from(A.toByteArray(a))),h=e.returns;if(!h)throw Error("View expected return type");let f=tk.fieldLayout({type:h},Array.from([...null!==(o=n.accounts)&&void 0!==o?o:[],...null!==(s=n.types)&&void 0!==s?s:[]]));return f.decode(d)};return s}}class eH{static build(t,e,r,n,i){let o={},s={},a={},c={},u={},l={},d=D(t),h=t.accounts?eE.build(t,e,r,n):{},f=eb.build(t,e,r,n);return t.instructions.forEach(f=>{let p=eg.build(f,(t,r)=>e.instruction.encode(t,r),r),y=ew.build(f,p),m=ev.build(f,y,d,n),g=eO.build(f,y,d,n,e,r,t),v=eW.build(r,f,g,t),w=eK.build(n,r,f,p,y,m,g,v,h,t.types||[],i&&i(f)),b=I()(f.name);s[b]=p,a[b]=y,o[b]=m,c[b]=g,u[b]=w,v&&(l[b]=v)}),[o,s,a,h,c,u,f,l]}}class eG{get programId(){return this._programId}get idl(){return this._idl}get coder(){return this._coder}get provider(){return this._provider}constructor(t,e,r,n,i){e=R(e),r||(r=td()),this._idl=t,this._provider=r,this._programId=e,this._coder=null!=n?n:new tj(t),this._events=new eT(this._programId,r,this._coder);let[o,s,a,c,u,l,d,h]=eH.build(t,this._coder,e,r,null!=i?i:()=>void 0);this.rpc=o,this.instruction=s,this.transaction=a,this.account=c,this.simulate=u,this.methods=l,this.state=d,this.views=h}static async at(t,e){let r=R(t),n=await eG.fetchIdl(r,e);if(!n)throw Error(`IDL not found for program: ${t.toString()}`);return new eG(n,r,e)}static async fetchIdl(t,e){var r;e=null!=e?e:td();let n=R(t),i=await ep(n),o=await e.connection.getAccountInfo(i);if(!o)return null;let s=(r=o.data.slice(8),ey.decode(r)),a=(0,P.rr)(s.data);return JSON.parse(function(t){let e=new TextDecoder("utf-8");return e.decode(t)}(a))}addEventListener(t,e){return this._events.addEventListener(t,e)}async removeEventListener(t){return await this._events.removeEventListener(t)}}new g.PublicKey("11111111111111111111111111111111")}}]); 4//# debugId=f0f93a2e-5214-561d-8547-8a941161f653
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.