@lightprotocol/compressed-token 0.22.1-alpha.2 → 0.22.1-alpha.4
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/README.md +5 -1
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/types-CJcjpvYl.cjs +2 -0
- package/dist/cjs/browser/types-CJcjpvYl.cjs.map +1 -0
- package/dist/cjs/browser/unified/index.cjs +2 -0
- package/dist/cjs/browser/unified/index.cjs.map +1 -0
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/types-BPweZlnn.cjs +2 -0
- package/dist/cjs/node/types-BPweZlnn.cjs.map +1 -0
- package/dist/cjs/node/unified/index.cjs +2 -0
- package/dist/cjs/node/unified/index.cjs.map +1 -0
- package/dist/es/browser/index.js +1 -1
- package/dist/es/browser/index.js.map +1 -1
- package/dist/es/browser/types-CUGXWKP-.js +2 -0
- package/dist/es/browser/types-CUGXWKP-.js.map +1 -0
- package/dist/es/browser/unified/index.js +2 -0
- package/dist/es/browser/unified/index.js.map +1 -0
- package/dist/types/index.d.ts +2235 -130
- package/dist/types/unified/index.d.ts +5392 -0
- package/package.json +41 -8
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e,t=require("@lightprotocol/stateless.js"),n=require("@solana/web3.js"),r=require("@solana/spl-token"),o=require("buffer"),i=require("@coral-xyz/borsh");exports.TokenDataVersion=void 0,(e=exports.TokenDataVersion||(exports.TokenDataVersion={}))[e.V1=1]="V1",e[e.V2=2]="V2",e[e.ShaFlat=3]="ShaFlat";const s=o.Buffer.from("pool"),a=o.Buffer.from("cpi_authority"),u=o.Buffer.from([23,169,27,122,147,169,209,152]),c=o.Buffer.from([241,34,48,186,37,179,123,192]),d=o.Buffer.from([65,206,101,37,147,42,221,144]),l=o.Buffer.from([163,52,200,231,140,3,69,186]),p=o.Buffer.from([112,230,105,101,145,202,157,97]),m=o.Buffer.from([69,74,217,36,115,117,97,76]),h=o.Buffer.from([170,23,31,34,133,173,93,242]),f=o.Buffer.from([114,143,210,73,96,115,1,228]),g=o.Buffer.from([107]);function y(e){return{mint:e.mint,tokenPoolPda:e.splInterfacePda,splInterfacePda:e.splInterfacePda,tokenProgram:e.tokenProgram,activity:e.activity,isInitialized:e.isInitialized,balance:e.balance,poolIndex:e.poolIndex,bump:e.bump}}function b(e){var t;return{mint:e.mint,splInterfacePda:null!==(t=e.tokenPoolPda)&&void 0!==t?t:e.splInterfacePda,tokenProgram:e.tokenProgram,activity:e.activity,isInitialized:e.isInitialized,balance:e.balance,poolIndex:e.poolIndex,bump:e.bump}}function I(e,n,r=0){const[o,i]=me.deriveSplInterfacePdaWithIndex(e,r);return{mint:e,splInterfacePda:o,tokenProgram:n,activity:void 0,balance:t.bn(0),isInitialized:1,poolIndex:r,bump:i}}function w(e,t){const n="tokenPoolPda"in e?b(e):e;if(!n.mint.equals(t))throw new Error("SplInterface mint does not match the provided mint.");if(!n.isInitialized)throw new Error(`SplInterface is not initialized. Please create an SPL interface for mint: ${t.toBase58()} via createSplInterface().`);return 1}async function k(e,n,o){const i=Array.from({length:5},((e,t)=>me.deriveSplInterfacePdaWithIndex(n,t))),s=await e.getMultipleAccountsInfo(i.map((e=>e[0])),o);if(null===s[0])throw new Error(`SplInterface not found. Please create an SPL interface for mint: ${n.toBase58()} via createSplInterface().`);const a=i.map(((e,t)=>s[t]?r.unpackAccount(e[0],s[t],s[t].owner):null)),u=s[0].owner;return a.map(((e,r)=>e?{mint:n,splInterfacePda:e.address,tokenProgram:u,activity:void 0,balance:t.bn(e.amount.toString()),isInitialized:1,poolIndex:r,bump:i[r][1]}:{mint:n,splInterfacePda:i[r][0],tokenProgram:u,activity:void 0,balance:t.bn(0),isInitialized:0,poolIndex:r,bump:i[r][1]}))}var A;exports.Action=void 0,(A=exports.Action||(exports.Action={}))[A.Compress=1]="Compress",A[A.Decompress=2]="Decompress",A[A.Transfer=3]="Transfer";const M=e=>{for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e};function v(e){const t=M(e).filter((e=>e.isInitialized));if(0===t.length)throw new Error("Please pass at least one initialized SPL interface info.");return t[0]}function P(e,n){if(0===e.length)throw new Error("Please pass at least one SPL interface info.");const r=(e=M(e)).find((e=>e.balance.gte(t.bn(n).mul(t.bn(10)))));if((e=e.filter((e=>e.isInitialized)).sort(((e,t)=>e.poolIndex-t.poolIndex))).every((e=>e.balance.isZero())))throw new Error("All provided SPL interface balances are zero. Please pass recent SPL interface infos.");return r?[r]:e}const x="Could not find accounts to select for transfer.";function T(e,t,n=4){const r=e.find((e=>e.parsed.amount.eq(t)));return r?[[r],r.parsed.amount,r.compressedAccount.lamports,r.parsed.amount]:S(e,t,n)}function S(e,n,r=4){const[o,i,s,a]=C(e,n,r);if(i.lt(t.bn(n))){const i=e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw o.length>=r?new Error(`Account limit exceeded: max ${a.toString()} (${r} accounts) per transaction. Total balance: ${i.toString()} (${e.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${i.toString()}.`)}if(0===o.length)throw new Error(x);return[o,i,s,a]}function C(e,n,r=4){if(0===e.length)throw new Error(x);let o=t.bn(0),i=t.bn(0),s=t.bn(0);const a=[];e.sort(((e,t)=>t.parsed.amount.cmp(e.parsed.amount)));for(const s of e){if(a.length>=r)break;if(o.gte(t.bn(n)))break;s.parsed.amount.isZero()&&s.compressedAccount.lamports.isZero()||(o=o.add(s.parsed.amount),i=i.add(s.compressedAccount.lamports),a.push(s))}if(s=e.slice(0,r).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),o.lt(t.bn(n))&&console.log(`Insufficient balance for transfer. Requested: ${n.toString()}, Returns max available: ${s.toString()}.`),0===a.length)throw new Error(x);return[a,o,i,s]}function O(e,n,r=4){if(0===e.length)throw new Error(x);let o=t.bn(0),i=t.bn(0);const s=[],a=e.filter((e=>!e.parsed.amount.isZero()||!e.compressedAccount.lamports.isZero()));a.sort(((e,t)=>t.parsed.amount.cmp(e.parsed.amount)));for(const e of a){if(s.length>=r)break;if(o=o.add(e.parsed.amount),i=i.add(e.compressedAccount.lamports),s.push(e),o.gte(t.bn(n))){const e=a.slice(s.length);if(e.length>0){const t=e.reduce(((e,t)=>t.parsed.amount.lt(e.parsed.amount)?t:e));s.length<r&&(s.push(t),o=o.add(t.parsed.amount),i=i.add(t.compressedAccount.lamports))}break}}const u=a.slice(0,r).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));if(0===s.length)throw new Error(x);return[s,o,i,u]}function _(e){const{inputCompressedTokenAccounts:n,outputStateTreeInfo:r,remainingAccounts:o=[],rootIndices:i,tokenTransferOutputs:s}=e,a=o.slice();let u=null;n.length>0&&n[0].parsed.delegate&&(u=t.getIndexOrAdd(a,n[0].parsed.delegate));const c=[];if(n.forEach(((e,n)=>{const r=t.getIndexOrAdd(a,e.compressedAccount.treeInfo.tree),o=t.getIndexOrAdd(a,e.compressedAccount.treeInfo.queue);c.push({amount:e.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:r,queuePubkeyIndex:o,leafIndex:e.compressedAccount.leafIndex,proveByIndex:e.compressedAccount.proveByIndex},rootIndex:i[n],lamports:e.compressedAccount.lamports.eq(t.bn(0))?null:e.compressedAccount.lamports,tlv:null})})),n.length>0&&r)throw new Error("Cannot specify both input accounts and outputStateTreeInfo");let d;if(n.length>0)d=n[0].compressedAccount.treeInfo;else{if(!r)throw new Error("Neither input accounts nor outputStateTreeInfo are available");d=r}const l=d.nextTreeInfo||d;let p=l.tree;if(l.treeType===t.TreeType.StateV2){if(!t.featureFlags.isV2())throw new Error("V2 trees are not supported yet");p=l.queue}const m=t.padOutputStateMerkleTrees(p,s.length),h=[];m.forEach(((e,n)=>{var r;const o=t.getIndexOrAdd(a,e);h.push({owner:s[n].owner,amount:s[n].amount,lamports:(null===(r=s[n].lamports)||void 0===r?void 0:r.eq(t.bn(0)))?null:s[n].lamports,merkleTreeIndex:o,tlv:null})}));const f=a.map((e=>({pubkey:e,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:f,packedOutputTokenData:h}}function E(e,t){if(!e.every((e=>e.parsed.mint.equals(t))))throw new Error("All input accounts must belong to the same mint");return 1}const B=i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")]),D=i.struct([i.publicKey("owner"),i.u64("amount"),i.option(i.u64(),"lamports"),i.u8("merkleTreeIndex"),i.option(i.vecU8(),"tlv")]),R=i.struct([i.u64("amount"),i.option(i.u8(),"delegateIndex"),i.struct([i.u8("merkleTreePubkeyIndex"),i.u8("queuePubkeyIndex"),i.u32("leafIndex"),i.bool("proveByIndex")],"merkleContext"),i.u16("rootIndex"),i.option(i.u64(),"lamports"),i.option(i.vecU8(),"tlv")]),K=i.struct([i.publicKey("owner"),i.option(i.u8(),"delegateChangeAccountIndex")]),L=i.struct([i.bool("setContext"),i.bool("firstSetContext"),i.u8("cpiContextAccountIndex")]),N=i.struct([i.option(B,"proof"),i.publicKey("mint"),i.option(K,"delegatedTransfer"),i.vec(R,"inputTokenDataWithContext"),i.vec(D,"outputCompressedAccounts"),i.bool("isCompress"),i.option(i.u64(),"compressOrDecompressAmount"),i.option(L,"cpiContext"),i.option(i.u8(),"lamportsChangeAccountMerkleTreeIndex")]),W=i.struct([i.vec(i.publicKey(),"recipients"),i.vec(i.u64(),"amounts"),i.option(i.u64(),"lamports")]),U=i.struct([i.vec(i.publicKey(),"pubkeys"),i.option(i.vec(i.u64(),"amounts"),"amounts"),i.option(i.u64(),"lamports"),i.option(i.u64(),"amount"),i.u8("index"),i.u8("bump")]),q=i.struct([i.publicKey("owner"),i.option(i.u64(),"remainingAmount"),i.option(L,"cpiContext")]);function G(e){const t=o.Buffer.alloc(1e3),n=W.encode({recipients:e.recipients,amounts:e.amounts,lamports:e.lamports},t);return o.Buffer.concat([new Uint8Array(c),new Uint8Array(t.subarray(0,n))])}function V(e){const t=o.Buffer.alloc(1e3),n=U.encode(e,t),r=o.Buffer.alloc(4);r.writeUInt32LE(n,0);const i=t.subarray(0,n);return o.Buffer.concat([new Uint8Array(d),new Uint8Array(r),new Uint8Array(i)])}function F(e){const t=o.Buffer.alloc(1e3),n=q.encode({owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext},t);return o.Buffer.concat([new Uint8Array(p),new Uint8Array(t.subarray(0,n))])}function z(e){const t=o.Buffer.alloc(1e3),n=N.encode(e,t),r=o.Buffer.alloc(4);r.writeUInt32LE(n,0);const i=t.subarray(0,n);return o.Buffer.concat([new Uint8Array(l),new Uint8Array(r),new Uint8Array(i)])}const j=e=>{const{feePayer:t,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},$=e=>{const{feePayer:t,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s,existingTokenPoolPda:a}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},Z=e=>{const t=me.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,mint:i,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:c,noopProgram:d,accountCompressionAuthority:l,accountCompressionProgram:p,merkleTree:m,selfProgram:h,systemProgram:f,solPoolPda:g}=e;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:null!=g?g:t,isSigner:0,isWritable:1}]},H=e=>{const t=me.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,lightSystemProgram:i,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:c,selfProgram:d,tokenPoolPda:l,compressOrDecompressTokenAccount:p,tokenProgram:m,systemProgram:h}=e;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:null!=l?l:t,isSigner:0,isWritable:1},{pubkey:null!=p?p:t,isSigner:0,isWritable:1},{pubkey:null!=m?m:t,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0}]},Q=e=>{const{feePayer:t,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:d}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0}]},J=Q,X=e=>{const{feePayer:t,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:d,mint:l}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0}]},Y=X,ee=i.struct([i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")],"proof"),i.publicKey("mint"),i.vec(R,"inputTokenDataWithContext"),i.option(L,"cpiContext"),i.publicKey("delegate"),i.u64("delegatedAmount"),i.u8("delegateMerkleTreeIndex"),i.u8("changeAccountMerkleTreeIndex"),i.option(i.u64(),"delegateLamports")]),te=i.struct([i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")],"proof"),i.publicKey("mint"),i.vec(R,"inputTokenDataWithContext"),i.option(L,"cpiContext"),i.u8("outputAccountMerkleTreeIndex")]),ne={a:new Array(32).fill(0),b:new Array(64).fill(0),c:new Array(32).fill(0)};function re(e){return e.a.every((e=>0===e))&&e.b.every((e=>0===e))&&e.c.every((e=>0===e))}function oe(e){var t;const n=o.Buffer.alloc(1e3),r=null!==(t=e.proof)&&void 0!==t?t:ne,i=ee.encode(Object.assign(Object.assign({},e),{proof:r}),n),s=o.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return o.Buffer.concat([new Uint8Array(m),new Uint8Array(s),new Uint8Array(a)])}function ie(e){var t;const n=o.Buffer.alloc(1e3),r=null!==(t=e.proof)&&void 0!==t?t:ne,i=te.encode(Object.assign(Object.assign({},e),{proof:r}),n),s=o.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return o.Buffer.concat([new Uint8Array(h),new Uint8Array(s),new Uint8Array(a)])}function se(e){var t;return"tokenPoolPda"in e&&null!==(t=e.tokenPoolPda)&&void 0!==t?t:e.splInterfacePda}const ae=e=>e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),ue=e=>{const t=e[0].parsed.owner;e.forEach((e=>{if(!e.parsed.owner.equals(t))throw new Error("Token accounts must be owned by the same owner")}))},ce=e=>({mint:e[0].parsed.mint,currentOwner:e[0].parsed.owner,delegate:e[0].parsed.delegate}),de=(e,t)=>{if(e.length<1)throw new Error("Must supply at least one input token account.");const n=e[0].parsed.owner,r=e.findIndex((e=>e.parsed.delegate));if(-1===r)return{delegatedTransfer:null,authority:n};const o=e[r].parsed.delegate;return{delegatedTransfer:{owner:n,delegateChangeAccountIndex:t.length<=1?null:0},authority:o}};function le(e,n,r){r=t.bn(r);const o=ae(e),i=t.sumUpLamports(e.map((e=>e.compressedAccount))),s=o.sub(r);return t.validateSufficientBalance(s),s.eq(t.bn(0))&&i.eq(t.bn(0))?[{owner:n,amount:r,lamports:i,tlv:null}]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),ue(e),[{owner:e[0].parsed.owner,amount:s,lamports:i,tlv:null},{owner:n,amount:r,lamports:t.bn(0),tlv:null}])}function pe(e,n){n=t.bn(n);const r=t.sumUpLamports(e.map((e=>e.compressedAccount))),o=ae(e).sub(n);return t.validateSufficientBalance(o),o.eq(t.bn(0))&&r.eq(t.bn(0))?[]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),ue(e),[{owner:e[0].parsed.owner,amount:o,lamports:r,tlv:null}])}class me{constructor(){}static setProgramId(e){this.programId="string"==typeof e?new n.PublicKey(e):e}static deriveSplInterfacePda(e){const t=[s,e.toBuffer()],[r,o]=n.PublicKey.findProgramAddressSync(t,this.programId);return r}static deriveTokenPoolPda(e){return this.deriveSplInterfacePda(e)}static findSplInterfaceIndexAndBump(e,t){for(let n=0;n<5;n++){const r=me.deriveSplInterfacePdaWithIndex(t,n);if(r[0].equals(e))return[n,r[1]]}throw new Error("SPL interface not found")}static findTokenPoolIndexAndBump(e,t){return this.findSplInterfaceIndexAndBump(e,t)}static deriveSplInterfacePdaWithIndex(e,t){let r=[];r=0===t?[o.Buffer.from("pool"),e.toBuffer(),o.Buffer.from([])]:[o.Buffer.from("pool"),e.toBuffer(),o.Buffer.from([t])];const[i,s]=n.PublicKey.findProgramAddressSync(r,this.programId);return[i,s]}static deriveTokenPoolPdaWithIndex(e,t){return this.deriveSplInterfacePdaWithIndex(e,t)}static get deriveCpiAuthorityPda(){const[e,t]=n.PublicKey.findProgramAddressSync([a],this.programId);return e}static async createMint({feePayer:e,mint:t,authority:o,freezeAuthority:i,decimals:s,rentExemptBalance:a,tokenProgramId:u,mintSize:c}){const d=null!=u?u:r.TOKEN_PROGRAM_ID;return[n.SystemProgram.createAccount({fromPubkey:e,lamports:a,newAccountPubkey:t,programId:d,space:null!=c?c:r.MINT_SIZE}),r.createInitializeMint2Instruction(t,s,o,i,d),await this.createTokenPool({feePayer:e,mint:t,tokenProgramId:d})]}static async createTokenPool({feePayer:e,mint:t,tokenProgramId:o}){const i=null!=o?o:r.TOKEN_PROGRAM_ID,s=this.deriveSplInterfacePdaWithIndex(t,0),a=j({mint:t,feePayer:e,tokenPoolPda:s[0],tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:n.SystemProgram.programId});return new n.TransactionInstruction({programId:this.programId,keys:a,data:u})}static async addTokenPool({feePayer:e,mint:t,poolIndex:i,tokenProgramId:s}){if(i<=0)throw new Error("Pool index must be greater than 0. For 0, use CreateTokenPool instead.");if(i>3)throw new Error(`Invalid poolIndex ${i}. Max 4 pools per mint.`);const a=null!=s?s:r.TOKEN_PROGRAM_ID,u=this.deriveSplInterfacePdaWithIndex(t,i-1),c=this.deriveSplInterfacePdaWithIndex(t,i),d=$({mint:t,feePayer:e,tokenPoolPda:c[0],existingTokenPoolPda:u[0],tokenProgram:a,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:n.SystemProgram.programId});return new n.TransactionInstruction({programId:this.programId,keys:d,data:o.Buffer.concat([new Uint8Array(f),new Uint8Array(o.Buffer.from([i]))])})}static async mintTo({feePayer:e,mint:r,authority:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=t.defaultStaticAccountsStruct(),d=u.tokenProgram;w(u,r);const l=t.toArray(s).map((e=>t.bn(e))),p=t.toArray(i);if(l.length!==p.length)throw new Error("Amount and toPubkey arrays must have the same length");const m=Z({mint:r,feePayer:e,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:d,tokenPoolPda:se(u),lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:c.registeredProgramPda,noopProgram:c.noopProgram,accountCompressionAuthority:c.accountCompressionAuthority,accountCompressionProgram:c.accountCompressionProgram,merkleTree:a.treeType===t.TreeType.StateV2?a.queue:a.tree,selfProgram:this.programId,systemProgram:n.SystemProgram.programId,solPoolPda:null}),h=G({recipients:p,amounts:l,lamports:null});return new n.TransactionInstruction({programId:this.programId,keys:m,data:h})}static async approveAndMintTo({feePayer:e,mint:t,authority:n,authorityTokenAccount:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=BigInt(s.toString());return[r.createMintToInstruction(t,o,n,c,[],u.tokenProgram),await this.compress({payer:e,owner:n,source:o,toAddress:i,mint:t,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u})]}static async transfer({payer:e,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const u=le(r,o,i),{inputTokenDataWithContext:c,packedOutputTokenData:d,remainingAccountMetas:l}=_({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:u}),{mint:p}=ce(r),{delegatedTransfer:m,authority:h}=de(r,u),f=z({proof:s,mint:p,delegatedTransfer:m,inputTokenDataWithContext:c,outputCompressedAccounts:d,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:g,noopProgram:y,registeredProgramPda:b,accountCompressionProgram:I}=t.defaultStaticAccountsStruct(),w=H({feePayer:e,authority:h,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:b,noopProgram:y,accountCompressionAuthority:g,accountCompressionProgram:I,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:n.SystemProgram.programId});return w.push(...l),new n.TransactionInstruction({programId:this.programId,keys:w,data:f})}static async createTokenProgramLookupTable({payer:e,authority:o,mints:i,recentSlot:s,remainingAccounts:a}){const[u,c]=n.AddressLookupTableProgram.createLookupTable({authority:o,payer:o,recentSlot:s});let d=[];i&&(d=[...i,...i.map((e=>this.deriveSplInterfacePda(e)))]);const l=[u,n.AddressLookupTableProgram.extendLookupTable({payer:e,authority:o,lookupTable:c,addresses:[n.SystemProgram.programId,n.ComputeBudgetProgram.programId,this.deriveCpiAuthorityPda,t.LightSystemProgram.programId,me.programId,t.defaultStaticAccountsStruct().registeredProgramPda,t.defaultStaticAccountsStruct().noopProgram,t.defaultStaticAccountsStruct().accountCompressionAuthority,t.defaultStaticAccountsStruct().accountCompressionProgram,t.defaultTestStateTreeAccounts().merkleTree,t.defaultTestStateTreeAccounts().nullifierQueue,t.defaultTestStateTreeAccounts().addressTree,t.defaultTestStateTreeAccounts().addressQueue,this.programId,r.TOKEN_PROGRAM_ID,r.TOKEN_2022_PROGRAM_ID,o,...d]})];if(a&&a.length>0)for(let t=0;t<a.length;t+=25){const r=a.slice(t,t+25),i=n.AddressLookupTableProgram.extendLookupTable({payer:e,authority:o,lookupTable:c,addresses:r});l.push(i)}return{instructions:l,address:c}}static async compress({payer:e,owner:r,source:o,toAddress:i,amount:s,mint:a,outputStateTreeInfo:u,tokenPoolInfo:c}){let d;const l=t.toArray(s),p=t.toArray(i);if(w(c,a),l.length!==p.length)throw new Error("Amount and toAddress arrays must have the same length");if(t.featureFlags.isV2()){const[i,s]=this.findSplInterfaceIndexAndBump(se(c),a),d=V({pubkeys:p,amounts:l.length>1?l.map((e=>t.bn(e))):null,lamports:null,amount:1===l.length?t.bn(l[0]):null,index:i,bump:s}),m=Z(Object.assign(Object.assign({mint:a,feePayer:e,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:c.tokenProgram,tokenPoolPda:se(c),lightSystemProgram:t.LightSystemProgram.programId},t.defaultStaticAccountsStruct()),{merkleTree:u.queue,selfProgram:this.programId,systemProgram:n.SystemProgram.programId,solPoolPda:null}));return m.push({pubkey:o,isWritable:1,isSigner:0}),new n.TransactionInstruction({programId:this.programId,keys:m,data:d})}{d=l.map(((e,n)=>{const r=t.bn(e);return{owner:p[n],amount:r,lamports:null,tlv:null}}));const{inputTokenDataWithContext:i,packedOutputTokenData:m,remainingAccountMetas:h}=_({inputCompressedTokenAccounts:[],outputStateTreeInfo:u,rootIndices:[],tokenTransferOutputs:d}),f=z({proof:null,mint:a,delegatedTransfer:null,inputTokenDataWithContext:i,outputCompressedAccounts:m,compressOrDecompressAmount:Array.isArray(s)?s.map((e=>t.bn(e))).reduce(((e,t)=>e.add(t)),t.bn(0)):t.bn(s),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),g=H(Object.assign(Object.assign({},t.defaultStaticAccountsStruct()),{feePayer:e,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:n.SystemProgram.programId,tokenPoolPda:se(c),compressOrDecompressTokenAccount:o,tokenProgram:c.tokenProgram}));return g.push(...h),new n.TransactionInstruction({programId:this.programId,keys:g,data:f})}}static async decompress({payer:e,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a,tokenPoolInfos:u}){const c=t.bn(i),d=t.toArray(u),l=pe(r,c),{inputTokenDataWithContext:p,packedOutputTokenData:m,remainingAccountMetas:h}=_({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:l,remainingAccounts:d.slice(1).map((e=>se(e)))}),{mint:f}=ce(r),{delegatedTransfer:g,authority:y}=de(r,l),b=z({proof:s,mint:f,delegatedTransfer:g,inputTokenDataWithContext:p,outputCompressedAccounts:m,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),I=d[0].tokenProgram,{accountCompressionAuthority:w,noopProgram:k,registeredProgramPda:A,accountCompressionProgram:M}=t.defaultStaticAccountsStruct(),v=H({feePayer:e,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:A,noopProgram:k,accountCompressionAuthority:w,accountCompressionProgram:M,selfProgram:this.programId,tokenPoolPda:se(d[0]),compressOrDecompressTokenAccount:o,tokenProgram:I,systemProgram:n.SystemProgram.programId});return v.push(...h),new n.TransactionInstruction({programId:this.programId,keys:v,data:b})}static async mergeTokenAccounts({payer:e,owner:n,inputCompressedTokenAccounts:r,mint:o,recentValidityProof:i,recentInputStateRootIndices:s}){const a=t.featureFlags.isV2()?8:4;if(r.length>a)throw new Error(`Cannot merge more than ${a} token accounts at once`);return E(r,o),[await this.transfer({payer:e,inputCompressedTokenAccounts:r,toAddress:n,amount:r.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),recentInputStateRootIndices:s,recentValidityProof:i})]}static async compressSplTokenAccount({feePayer:e,authority:r,tokenAccount:o,mint:i,remainingAmount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){w(u,i);const c=[{pubkey:a.treeType===t.TreeType.StateV2?a.queue:a.tree,isSigner:0,isWritable:1}],d=F({owner:r,remainingAmount:null!=s?s:null,cpiContext:null}),{accountCompressionAuthority:l,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=t.defaultStaticAccountsStruct(),f=H({feePayer:e,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:l,accountCompressionProgram:h,selfProgram:this.programId,tokenPoolPda:se(u),compressOrDecompressTokenAccount:o,tokenProgram:u.tokenProgram,systemProgram:n.SystemProgram.programId});return f.push(...c),new n.TransactionInstruction({programId:this.programId,keys:f,data:d})}static async getMintProgramId(e,t){var n;return null===(n=await t.getAccountInfo(e))||void 0===n?void 0:n.owner}static async approve({payer:e,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const{inputTokenDataWithContext:u,remainingAccountMetas:c}=_({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:[]}),{mint:d,currentOwner:l}=ce(r),p=r[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?1:0,m=oe({proof:s,mint:d,inputTokenDataWithContext:u,cpiContext:null,delegate:o,delegatedAmount:t.bn(i),delegateMerkleTreeIndex:p,changeAccountMerkleTreeIndex:p,delegateLamports:null}),{accountCompressionAuthority:h,noopProgram:f,registeredProgramPda:g,accountCompressionProgram:y}=t.defaultStaticAccountsStruct(),b=Q({feePayer:e,authority:l,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:g,noopProgram:f,accountCompressionAuthority:h,accountCompressionProgram:y,selfProgram:this.programId,systemProgram:n.SystemProgram.programId});return b.push(...c),new n.TransactionInstruction({programId:this.programId,keys:b,data:m})}static async revoke({payer:e,inputCompressedTokenAccounts:r,recentValidityProof:o,recentInputStateRootIndices:i}){ue(r);const{inputTokenDataWithContext:s,remainingAccountMetas:a}=_({inputCompressedTokenAccounts:r,rootIndices:i,tokenTransferOutputs:[]}),{mint:u,currentOwner:c}=ce(r),d=ie({proof:o,mint:u,inputTokenDataWithContext:s,cpiContext:null,outputAccountMerkleTreeIndex:r[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?2:1}),{accountCompressionAuthority:l,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=t.defaultStaticAccountsStruct(),f=J({feePayer:e,authority:c,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:l,accountCompressionProgram:h,selfProgram:this.programId,systemProgram:n.SystemProgram.programId});return f.push(...a),new n.TransactionInstruction({programId:this.programId,keys:f,data:d})}}function he(e,n){const r=t.deriveAddressV2(ge(e)[0].toBytes(),n.tree,t.CTOKEN_PROGRAM_ID);return Array.from(r.toBytes())}me.programId=new n.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");const fe=o.Buffer.from([99,111,109,112,114,101,115,115,101,100,95,109,105,110,116]);function ge(e){const[r,o]=n.PublicKey.findProgramAddressSync([fe,e.toBuffer()],t.CTOKEN_PROGRAM_ID);return[r,o]}const ye=o.Buffer.from([103]),be=i.struct([i.publicKey("recipient"),i.u64("amount")]),Ie=i.struct([i.u8("tokenAccountVersion"),i.vec(be,"recipients")]),we=i.struct([i.option(i.publicKey(),"newAuthority")]),ke=i.struct([i.u8("mintBump")]),Ae=i.struct([i.u8("accountIndex"),i.u64("amount")]),Me=i.struct([i.u8("extensionIndex"),i.u8("fieldType"),i.vecU8("key"),i.vecU8("value")]),ve=i.struct([i.u8("extensionIndex"),i.publicKey("newAuthority")]),Pe=i.struct([i.u8("extensionIndex"),i.vecU8("key"),i.u8("idempotent")]),xe=i.struct([i.u8("cmintBump"),i.u8("rentPayment"),i.u32("writeTopUp")]),Te=i.struct([i.u8("idempotent")]),Se=i.rustEnum([Ie.replicate("mintToCompressed"),we.replicate("updateMintAuthority"),we.replicate("updateFreezeAuthority"),ke.replicate("createSplMint"),Ae.replicate("mintToCToken"),Me.replicate("updateMetadataField"),ve.replicate("updateMetadataAuthority"),Pe.replicate("removeMetadataKey"),xe.replicate("decompressMint"),Te.replicate("compressAndCloseCMint")]),Ce=i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")]),Oe=i.struct([i.bool("setContext"),i.bool("firstSetContext"),i.u8("inTreeIndex"),i.u8("inQueueIndex"),i.u8("outQueueIndex"),i.u8("tokenOutQueueIndex"),i.u8("assignedAccountIndex"),i.array(i.u8(),4,"readOnlyAddressTrees"),i.array(i.u8(),32,"addressTreePubkey")]),_e=i.struct([i.array(i.u8(),4,"readOnlyAddressTrees"),i.array(i.u16(),4,"readOnlyAddressTreeRootIndices")]),Ee=i.struct([i.vecU8("key"),i.vecU8("value")]),Be=i.struct([i.option(i.publicKey(),"updateAuthority"),i.vecU8("name"),i.vecU8("symbol"),i.vecU8("uri"),i.option(i.vec(Ee),"additionalMetadata")]),De=i.struct([]),Re=i.rustEnum([De.replicate("placeholder0"),De.replicate("placeholder1"),De.replicate("placeholder2"),De.replicate("placeholder3"),De.replicate("placeholder4"),De.replicate("placeholder5"),De.replicate("placeholder6"),De.replicate("placeholder7"),De.replicate("placeholder8"),De.replicate("placeholder9"),De.replicate("placeholder10"),De.replicate("placeholder11"),De.replicate("placeholder12"),De.replicate("placeholder13"),De.replicate("placeholder14"),De.replicate("placeholder15"),De.replicate("placeholder16"),De.replicate("placeholder17"),De.replicate("placeholder18"),Be.replicate("tokenMetadata")]),Ke=i.struct([i.u8("version"),i.bool("cmintDecompressed"),i.publicKey("mint")]),Le=i.struct([i.u64("supply"),i.u8("decimals"),Ke.replicate("metadata"),i.option(i.publicKey(),"mintAuthority"),i.option(i.publicKey(),"freezeAuthority"),i.option(i.vec(Re),"extensions")]),Ne=i.struct([i.u32("leafIndex"),i.bool("proveByIndex"),i.u16("rootIndex"),i.array(i.u8(),32,"compressedAddress"),i.u8("tokenPoolBump"),i.u8("tokenPoolIndex"),i.u16("maxTopUp"),i.option(_e,"createMint"),i.vec(Se,"actions"),i.option(Ce,"proof"),i.option(Oe,"cpiContext"),i.option(Le,"mint")]);function We(e){const n=Object.assign(Object.assign({},e),{mint:e.mint?Object.assign(Object.assign({},e.mint),{supply:t.bn(e.mint.supply.toString())}):null,actions:e.actions.map((e=>"mintToCompressed"in e&&e.mintToCompressed?{mintToCompressed:Object.assign(Object.assign({},e.mintToCompressed),{recipients:e.mintToCompressed.recipients.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())})))})}:"mintToCToken"in e&&e.mintToCToken?{mintToCToken:Object.assign(Object.assign({},e.mintToCToken),{amount:t.bn(e.mintToCToken.amount.toString())})}:e))}),r=o.Buffer.alloc(1e4),i=Ne.encode(n,r);return o.Buffer.concat([ye,r.subarray(0,i)])}function Ue(e,r,i,s,a,u,c,d,l){const p=function(e){var n;const[r]=ge(e.mintSigner),i=t.deriveAddressV2(r.toBytes(),e.addressTree,t.CTOKEN_PROGRAM_ID);let s=null;e.metadata&&(s=[{tokenMetadata:{updateAuthority:null!==(n=e.metadata.updateAuthority)&&void 0!==n?n:null,name:o.Buffer.from(e.metadata.name),symbol:o.Buffer.from(e.metadata.symbol),uri:o.Buffer.from(e.metadata.uri),additionalMetadata:e.metadata.additionalMetadata}}]);const a=function(e){if(!e)return null;if(32!==e.a.length)throw new Error(`Invalid proof.a length: expected 32, got ${e.a.length}`);if(64!==e.b.length)throw new Error(`Invalid proof.b length: expected 64, got ${e.b.length}`);if(32!==e.c.length)throw new Error(`Invalid proof.c length: expected 32, got ${e.c.length}`);return e}(e.proof);return We({leafIndex:0,proveByIndex:0,rootIndex:e.rootIndex,compressedAddress:Array.from(i.toBytes()),tokenPoolBump:0,tokenPoolIndex:0,maxTopUp:0,createMint:{readOnlyAddressTrees:[0,0,0,0],readOnlyAddressTreeRootIndices:[0,0,0,0]},actions:[],proof:a,cpiContext:null,mint:{supply:BigInt(0),decimals:e.decimals,metadata:{version:exports.TokenDataVersion.ShaFlat,cmintDecompressed:0,mint:r},mintAuthority:e.mintAuthority,freezeAuthority:e.freezeAuthority,extensions:s}})}({mintSigner:e,mintAuthority:i,freezeAuthority:s,decimals:r,addressTree:c.tree,outputQueue:d.queue,rootIndex:u.rootIndices[0],proof:u.compressedProof,metadata:l}),m=t.defaultStaticAccountsStruct(),h=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:0},{pubkey:i,isSigner:1,isWritable:0},{pubkey:a,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:m.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:m.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:m.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:d.queue,isSigner:0,isWritable:1},{pubkey:c.tree,isSigner:0,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:h,data:p})}function qe(e){var n;const r=t.deriveAddressV2(e.splMint.toBytes(),e.addressTree,t.CTOKEN_PROGRAM_ID),i="mintAuthority"===e.actionType?{updateMintAuthority:{newAuthority:e.newAuthority}}:{updateFreezeAuthority:{newAuthority:e.newAuthority}};let s=null;return e.mintInterface.tokenMetadata&&(s=[{tokenMetadata:{updateAuthority:null!==(n=e.mintInterface.tokenMetadata.updateAuthority)&&void 0!==n?n:null,name:o.Buffer.from(e.mintInterface.tokenMetadata.name),symbol:o.Buffer.from(e.mintInterface.tokenMetadata.symbol),uri:o.Buffer.from(e.mintInterface.tokenMetadata.uri),additionalMetadata:null}}]),We({leafIndex:e.leafIndex,proveByIndex:e.proveByIndex,rootIndex:e.rootIndex,compressedAddress:Array.from(r.toBytes()),tokenPoolBump:0,tokenPoolIndex:0,maxTopUp:0,createMint:null,actions:[i],proof:e.proof,cpiContext:null,mint:{supply:e.mintInterface.mint.supply,decimals:e.mintInterface.mint.decimals,metadata:{version:e.mintInterface.mintContext.version,cmintDecompressed:e.mintInterface.mintContext.cmintDecompressed,mint:e.mintInterface.mintContext.splMint},mintAuthority:e.mintInterface.mint.mintAuthority,freezeAuthority:e.mintInterface.mint.freezeAuthority,extensions:s}})}function Ge(e,r,o,i,s){if(!e.merkleContext)throw new Error("MintInterface must have merkleContext for compressed mint operations");if(!e.mintContext)throw new Error("MintInterface must have mintContext for compressed mint operations");const a=e.merkleContext,u=t.getOutputQueue(a),c=t.getDefaultAddressTreeInfo(),d=qe({splMint:e.mintContext.splMint,addressTree:c.tree,leafIndex:a.leafIndex,proveByIndex:1,rootIndex:s.rootIndices[0],proof:s.compressedProof,mintInterface:e,newAuthority:o,actionType:"mintAuthority"}),l=t.defaultStaticAccountsStruct(),p=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:i,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:l.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:l.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:l.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:1},{pubkey:a.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:a.treeInfo.queue,isSigner:0,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:p,data:d})}function Ve(e,r,o,i,s){if(!e.merkleContext)throw new Error("MintInterface must have merkleContext for compressed mint operations");if(!e.mintContext)throw new Error("MintInterface must have mintContext for compressed mint operations");const a=e.merkleContext,u=t.getOutputQueue(a),c=t.getDefaultAddressTreeInfo(),d=qe({splMint:e.mintContext.splMint,addressTree:c.tree,leafIndex:a.leafIndex,proveByIndex:1,rootIndex:s.rootIndices[0],proof:s.compressedProof,mintInterface:e,newAuthority:o,actionType:"freezeAuthority"}),l=t.defaultStaticAccountsStruct(),p=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:i,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:l.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:l.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:l.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:1},{pubkey:a.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:a.treeInfo.queue,isSigner:0,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:p,data:d})}function Fe(e,r,i,s,a){if(!e.merkleContext)throw new Error("MintInterface must have merkleContext for compressed mint operations");if(!e.mintContext)throw new Error("MintInterface must have mintContext for compressed mint operations");if(!e.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const u=e.merkleContext,c=t.getOutputQueue(u),d=t.getDefaultAddressTreeInfo(),l=function(e){var n;const r=t.deriveAddressV2(e.splMint.toBytes(),e.addressTree,t.CTOKEN_PROGRAM_ID),i=e.mintInterface;if(!i.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");var s;return We({leafIndex:e.leafIndex,proveByIndex:null===e.proof,rootIndex:e.rootIndex,compressedAddress:Array.from(r.toBytes()),tokenPoolBump:0,tokenPoolIndex:0,maxTopUp:0,createMint:null,actions:[(s=e.action,"updateField"===s.type?{updateMetadataField:{extensionIndex:s.extensionIndex,fieldType:s.fieldType,key:o.Buffer.from(s.key),value:o.Buffer.from(s.value)}}:"updateAuthority"===s.type?{updateMetadataAuthority:{extensionIndex:s.extensionIndex,newAuthority:s.newAuthority}}:{removeMetadataKey:{extensionIndex:s.extensionIndex,key:o.Buffer.from(s.key),idempotent:s.idempotent?1:0}})],proof:e.proof,cpiContext:null,mint:{supply:i.mint.supply,decimals:i.mint.decimals,metadata:{version:i.mintContext.version,cmintDecompressed:i.mintContext.cmintDecompressed,mint:i.mintContext.splMint},mintAuthority:i.mint.mintAuthority,freezeAuthority:i.mint.freezeAuthority,extensions:[{tokenMetadata:{updateAuthority:null!==(n=i.tokenMetadata.updateAuthority)&&void 0!==n?n:null,name:o.Buffer.from(i.tokenMetadata.name),symbol:o.Buffer.from(i.tokenMetadata.symbol),uri:o.Buffer.from(i.tokenMetadata.uri),additionalMetadata:null}}]}})}({splMint:e.mintContext.splMint,addressTree:d.tree,leafIndex:u.leafIndex,rootIndex:s.rootIndices[0],proof:s.compressedProof,mintInterface:e,action:a}),p=t.defaultStaticAccountsStruct(),m=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:i,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:p.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:p.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:p.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1},{pubkey:u.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:u.treeInfo.queue,isSigner:0,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:m,data:l})}function ze(e,t,n,r,o,i,s,a=0){return Fe(e,t,n,r,{type:"updateField",extensionIndex:a,fieldType:"name"===o?0:"symbol"===o?1:"uri"===o?2:3,key:s||"",value:i})}function je(e,t,n,r,o,i=0){return Fe(e,t,r,o,{type:"updateAuthority",extensionIndex:i,newAuthority:n})}function $e(e,t,n,r,o,i=0,s=0){return Fe(e,t,n,r,{type:"removeKey",extensionIndex:s,key:o,idempotent:i})}const Ze=o.Buffer.from([100]),He=o.Buffer.from([102]),Qe=i.struct([i.u8("bump"),i.array(i.u8(),32,"programId"),i.vec(i.vec(i.u8()),"seeds")]),Je=i.struct([i.u8("tokenAccountVersion"),i.u8("rentPayment"),i.u8("hasTopUp"),i.u8("compressionOnly"),i.u32("writeTopUp"),i.option(Qe,"compressToAccountPubkey")]),Xe=i.struct([i.u8("bump"),i.option(Je,"compressibleConfig")]);function Ye(e,r){return n.PublicKey.findProgramAddressSync([e.toBuffer(),t.CTOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.CTOKEN_PROGRAM_ID)}function et(e,t){const n=o.Buffer.alloc(2e3),r=Xe.encode({bump:e.bump,compressibleConfig:e.compressibleConfig||null},n),i=t?He:Ze;return o.Buffer.concat([i,n.subarray(0,r)])}function tt(e,r,o,i,s,a){const[u,c]=Ye(r,o),d=et({bump:c,compressibleConfig:i},0),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&s&&a&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:l,data:d})}function nt(e,r,o,i,s,a){const[u,c]=Ye(r,o),d=et({bump:c,compressibleConfig:i},1),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&s&&a&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:l,data:d})}function rt(e){return e.equals(t.CTOKEN_PROGRAM_ID)?t.CTOKEN_PROGRAM_ID:r.ASSOCIATED_TOKEN_PROGRAM_ID}function ot(e,n,o,i,s=0){if(i){const t=r.getAssociatedTokenAddressSync(n,o,s,i,rt(i));if(e.equals(t))return{valid:1,type:it(i),programId:i};throw new Error(`ATA address mismatch for ${i.toBase58()}. Expected: ${t.toBase58()}, got: ${e.toBase58()}`)}let a,u,c;if(a=r.getAssociatedTokenAddressSync(n,o,s,t.CTOKEN_PROGRAM_ID,rt(t.CTOKEN_PROGRAM_ID)),e.equals(a))return{valid:1,type:"ctoken",programId:t.CTOKEN_PROGRAM_ID};if(u=r.getAssociatedTokenAddressSync(n,o,s,r.TOKEN_PROGRAM_ID,rt(r.TOKEN_PROGRAM_ID)),e.equals(u))return{valid:1,type:"spl",programId:r.TOKEN_PROGRAM_ID};if(c=r.getAssociatedTokenAddressSync(n,o,s,r.TOKEN_2022_PROGRAM_ID,rt(r.TOKEN_2022_PROGRAM_ID)),e.equals(c))return{valid:1,type:"token2022",programId:r.TOKEN_2022_PROGRAM_ID};throw new Error(`ATA address does not match any valid derivation from mint+owner. Got: ${e.toBase58()}, expected one of: c-token=${a.toBase58()}, SPL=${u.toBase58()}, T22=${c.toBase58()}`)}function it(e){if(e.equals(t.CTOKEN_PROGRAM_ID))return"ctoken";if(e.equals(r.TOKEN_PROGRAM_ID))return"spl";if(e.equals(r.TOKEN_2022_PROGRAM_ID))return"token2022";throw new Error(`Unknown program ID: ${e.toBase58()}`)}function st(e,n,o,i,s=r.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:rt(s);return s.equals(t.CTOKEN_PROGRAM_ID)?tt(e,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):r.createAssociatedTokenAccountInstruction(e,n,o,i,s,c)}function at(e,n,o,i,s=r.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:rt(s);return s.equals(t.CTOKEN_PROGRAM_ID)?nt(e,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):r.createAssociatedTokenAccountIdempotentInstruction(e,n,o,i,s,c)}const ut=at;function ct(e,r,o,i,s,a,u,c){const d=function(e){const n=t.deriveAddressV2(e.mintData.splMint.toBytes(),e.addressTree,t.CTOKEN_PROGRAM_ID);if(e.mintData.metadata)throw new Error("TokenMetadata extension not supported in mintTo instruction");return We({leafIndex:e.leafIndex,proveByIndex:1,rootIndex:e.rootIndex,compressedAddress:Array.from(n.toBytes()),tokenPoolBump:0,tokenPoolIndex:0,maxTopUp:0,createMint:null,actions:[{mintToCToken:{accountIndex:e.recipientAccountIndex,amount:BigInt(e.amount.toString())}}],proof:e.proof,cpiContext:null,mint:{supply:e.mintData.supply,decimals:e.mintData.decimals,metadata:{version:e.mintData.version,cmintDecompressed:e.mintData.cmintDecompressed,mint:e.mintData.splMint},mintAuthority:e.mintData.mintAuthority,freezeAuthority:e.mintData.freezeAuthority,extensions:null}})}({addressTree:t.getDefaultAddressTreeInfo().tree,leafIndex:i.leafIndex,rootIndex:o.rootIndices[0],proof:o.compressedProof,mintData:s,recipientAccountIndex:0,amount:c}),l=t.defaultStaticAccountsStruct(),p=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:0},{pubkey:r,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:l.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:l.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:l.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:a.queue,isSigner:0,isWritable:1},{pubkey:i.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:i.treeInfo.queue,isSigner:0,isWritable:1}];return p.push({pubkey:u,isSigner:0,isWritable:1}),new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:p,data:d})}function dt(e,r,o,i,s,a,u,c=exports.TokenDataVersion.ShaFlat){var d;const l=function(e){const n=t.deriveAddressV2(e.mintData.splMint.toBytes(),e.addressTree,t.CTOKEN_PROGRAM_ID);if(e.mintData.metadata)throw new Error("TokenMetadata extension not supported in mintTo instruction");return We({leafIndex:e.leafIndex,proveByIndex:1,rootIndex:e.rootIndex,compressedAddress:Array.from(n.toBytes()),tokenPoolBump:0,tokenPoolIndex:0,maxTopUp:0,createMint:null,actions:[{mintToCompressed:{tokenAccountVersion:e.tokenAccountVersion,recipients:e.recipients.map((e=>({recipient:e.recipient,amount:BigInt(e.amount.toString())})))}}],proof:e.proof,cpiContext:null,mint:{supply:e.mintData.supply,decimals:e.mintData.decimals,metadata:{version:e.mintData.version,cmintDecompressed:e.mintData.cmintDecompressed,mint:e.mintData.splMint},mintAuthority:e.mintData.mintAuthority,freezeAuthority:e.mintData.freezeAuthority,extensions:null}})}({addressTree:t.getDefaultAddressTreeInfo().tree,leafIndex:i.leafIndex,rootIndex:o.rootIndices[0],proof:o.compressedProof,mintData:s,recipients:a,tokenAccountVersion:c}),p=null!==(d=null==u?void 0:u.queue)&&void 0!==d?d:t.getOutputQueue(i),m=t.defaultStaticAccountsStruct(),h=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:0},{pubkey:r,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:m.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:m.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:m.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:i.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:i.treeInfo.queue,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:h,data:l})}function lt(e,n,o,i,s,a,u=[]){const c=e.mint.address,d=e.programId;if(!e.merkleContext)return r.createMintToInstruction(c,n,o,BigInt(s.toString()),u,d);if(!a)throw new Error("Validity proof required for c-token mint-to");if(!e.mintContext)throw new Error("mintContext required for c-token mint-to");const l={supply:e.mint.supply,decimals:e.mint.decimals,mintAuthority:e.mint.mintAuthority,freezeAuthority:e.mint.freezeAuthority,splMint:e.mintContext.splMint,cmintDecompressed:e.mintContext.cmintDecompressed,version:e.mintContext.version,metadata:e.tokenMetadata?{updateAuthority:e.tokenMetadata.updateAuthority||null,name:e.tokenMetadata.name,symbol:e.tokenMetadata.symbol,uri:e.tokenMetadata.uri}:void 0};return ct(o,i,a,e.merkleContext,l,t.getOutputTreeInfo(e.merkleContext),n,s)}const pt=3;function mt(e,r,o,i){const s=Buffer.alloc(9);s.writeUInt8(pt,0),s.writeBigUInt64LE(BigInt(i),1);const a=[{pubkey:e,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:1}];return new n.TransactionInstruction({programId:t.CTOKEN_PROGRAM_ID,keys:a,data:s})}function ht(e,o,i,s,a=[],u=t.CTOKEN_PROGRAM_ID){if(u.equals(t.CTOKEN_PROGRAM_ID)){if(a.length>0)throw new Error("c-token transfer does not support multi-signers. Use a single owner.");return mt(e,o,i,s)}if(u.equals(r.TOKEN_PROGRAM_ID)||u.equals(r.TOKEN_2022_PROGRAM_ID))return r.createTransferInstruction(e,o,i,s,a.map((e=>e instanceof n.PublicKey?e:e.publicKey)),u);throw new Error(`Unsupported program ID: ${u.toBase58()}`)}const ft=o.Buffer.from([101]),gt=0,yt=1,bt=i.struct([i.u8("mode"),i.u64("amount"),i.u8("mint"),i.u8("sourceOrRecipient"),i.u8("authority"),i.u8("poolAccountIndex"),i.u8("poolIndex"),i.u8("bump"),i.u8("decimals")]),It=i.struct([i.u8("merkleTreePubkeyIndex"),i.u8("queuePubkeyIndex"),i.u32("leafIndex"),i.bool("proveByIndex")]),wt=i.struct([i.u8("owner"),i.u64("amount"),i.bool("hasDelegate"),i.u8("delegate"),i.u8("mint"),i.u8("version"),It.replicate("merkleContext"),i.u16("rootIndex")]),kt=i.struct([i.u8("owner"),i.u64("amount"),i.bool("hasDelegate"),i.u8("delegate"),i.u8("mint"),i.u8("version")]),At=i.struct([i.bool("setContext"),i.bool("firstSetContext"),i.u8("cpiContextAccountIndex")]),Mt=i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")]),vt=i.struct([i.bool("withTransactionHash"),i.bool("withLamportsChangeAccountMerkleTreeIndex"),i.u8("lamportsChangeAccountMerkleTreeIndex"),i.u8("lamportsChangeAccountOwnerIndex"),i.u8("outputQueue"),i.u16("maxTopUp"),i.option(At,"cpiContext"),i.option(i.vec(bt),"compressions"),i.option(Mt,"proof"),i.vec(wt,"inTokenData"),i.vec(kt,"outTokenData"),i.option(i.vec(i.u64()),"inLamports"),i.option(i.vec(i.u64()),"outLamports"),i.option(i.vec(i.vec(i.u8())),"inTlv"),i.option(i.vec(i.vec(i.u8())),"outTlv")]);function Pt(e){var n,r,i,s,a,u;const c=Object.assign(Object.assign({},e),{compressions:null!==(r=null===(n=e.compressions)||void 0===n?void 0:n.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))))&&void 0!==r?r:null,inTokenData:e.inTokenData.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))),outTokenData:e.outTokenData.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))),inLamports:null!==(s=null===(i=e.inLamports)||void 0===i?void 0:i.map((e=>t.bn(e.toString()))))&&void 0!==s?s:null,outLamports:null!==(u=null===(a=e.outLamports)||void 0===a?void 0:a.map((e=>t.bn(e.toString()))))&&void 0!==u?u:null}),d=o.Buffer.alloc(2e3),l=vt.encode(c,d);return o.Buffer.concat([ft,d.subarray(0,l)])}function xt(e,t,n,r,o,i,s){return{mode:gt,amount:e,mint:t,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:i,bump:s,decimals:0}}function Tt(e,t,n,r){return{mode:yt,amount:e,mint:t,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:0,bump:0,decimals:0}}function St(e){return!e||e.length<8?exports.TokenDataVersion.ShaFlat:2===e[0]?exports.TokenDataVersion.V1:3===e[7]?exports.TokenDataVersion.V2:exports.TokenDataVersion.ShaFlat}function Ct(e,r,o,i,s,a){var u;if(0===r.length)throw new Error("No input compressed token accounts provided");const c=r[0].parsed.mint,d=r[0].parsed.owner,l=new Map,p=[],m=new Set,h=new Set;for(const e of r)m.add(e.compressedAccount.treeInfo.tree.toBase58()),h.add(e.compressedAccount.treeInfo.queue.toBase58());for(const e of m)l.set(e,p.length),p.push(new n.PublicKey(e));let f=0,g=1;for(const e of h)g&&(f=p.length,g=0),l.set(e,p.length),p.push(new n.PublicKey(e));const y=p.length;l.set(c.toBase58(),y),p.push(c);const b=p.length;l.set(d.toBase58(),b),p.push(d);const I=p.length;l.set(o.toBase58(),I),p.push(o);let w=0,k=0,A=0,M=0;a&&(w=p.length,l.set(a.splInterfacePda.toBase58(),w),p.push(a.splInterfacePda),M=p.length,l.set(a.tokenProgram.toBase58(),M),p.push(a.tokenProgram),k=a.poolIndex,A=a.bump);const v=function(e,t,n){return e.map(((e,r)=>{var o,i;const s=e.parsed.owner.toBase58(),a=e.parsed.mint.toBase58(),u=St(null===(o=e.compressedAccount.data)||void 0===o?void 0:o.discriminator);return{owner:n.get(s),amount:BigInt(e.parsed.amount.toString()),hasDelegate:null!==e.parsed.delegate,delegate:e.parsed.delegate&&null!==(i=n.get(e.parsed.delegate.toBase58()))&&void 0!==i?i:0,mint:n.get(a),version:u,merkleContext:{merkleTreePubkeyIndex:n.get(e.compressedAccount.treeInfo.tree.toBase58()),queuePubkeyIndex:n.get(e.compressedAccount.treeInfo.queue.toBase58()),leafIndex:e.compressedAccount.leafIndex,proveByIndex:e.compressedAccount.proveByIndex},rootIndex:t[r]}}))}(r,s.rootIndices,l),P=r.reduce(((e,t)=>e+BigInt(t.parsed.amount.toString())),BigInt(0))-i,x=[];if(P>0){const e=St(null===(u=r[0].compressedAccount.data)||void 0===u?void 0:u.discriminator);x.push({owner:b,amount:P,hasDelegate:0,delegate:0,mint:y,version:e})}const T=Pt({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:f,maxTopUp:0,cpiContext:null,compressions:[{mode:yt,amount:i,mint:y,sourceOrRecipient:I,authority:0,poolAccountIndex:a?w:0,poolIndex:a?k:0,bump:a?A:0,decimals:0}],proof:s.compressedProof?{a:Array.from(s.compressedProof.a),b:Array.from(s.compressedProof.b),c:Array.from(s.compressedProof.c)}:null,inTokenData:v,outTokenData:x,inLamports:null,outLamports:null,inTlv:null,outTlv:null}),{accountCompressionAuthority:S,registeredProgramPda:C,accountCompressionProgram:O}=t.defaultStaticAccountsStruct(),_=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:e,isSigner:1,isWritable:1},{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:C,isSigner:0,isWritable:0},{pubkey:S,isSigner:0,isWritable:0},{pubkey:O,isSigner:0,isWritable:0},{pubkey:n.SystemProgram.programId,isSigner:0,isWritable:0},...p.map(((e,t)=>{const n=t<m.size+h.size,r=e.equals(o),i=void 0!==a&&e.equals(a.splInterfacePda);return{pubkey:e,isSigner:t===b,isWritable:n||r||i}}))];return new n.TransactionInstruction({programId:me.programId,keys:_,data:T})}var Ot="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function _t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Et(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:1}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:1,get:function(){return e[t]}})})),n}var Bt={exports:{}},Dt=Et(Object.freeze({__proto__:null,default:{}}));!function(e,t){function n(e,t){if(!e)throw new 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 o(e,t,n){if(o.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(n=t,t=10),this._init(e||0,t||10,n||"be"))}var i;"object"==typeof Bt?Bt.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:Dt.Buffer}catch(e){}function s(e,t){var r=e.charCodeAt(t);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(0,"Invalid character in "+e)}function a(e,t,n){var r=s(e,n);return n-1>=t&&(r|=s(e,n-1)<<4),r}function u(e,t,r,o){for(var i=0,s=0,a=Math.min(e.length,r),u=t;u<a;u++){var c=e.charCodeAt(u)-48;i*=o,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<o,"Invalid character"),i+=s}return i}function c(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(o.isBN=function(e){return e instanceof o?1:null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36);var o=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<e.length&&(16===t?this._parseHex(e,o,r):(this._parseBase(e,t,o),"le"===r&&this._initArray(this.toArray(),t,r)))},o.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var i,s,a=0;if("be"===r)for(o=e.length-1,i=0;o>=0;o-=3)s=e[o]|e[o-1]<<8|e[o-2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);else if("le"===r)for(o=0,i=0;o<e.length;o+=3)s=e[o]|e[o+1]<<8|e[o+2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);return this._strip()},o.prototype._parseHex=function(e,t,n){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,i=0,s=0;if("be"===n)for(r=e.length-1;r>=t;r-=2)o=a(e,t,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;else for(r=(e.length-t)%2==0?t+1:t;r<e.length;r+=2)o=a(e,t,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;this._strip()},o.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var r=0,o=1;o<=67108863;o*=t)r++;r--,o=o/t|0;for(var i=e.length-n,s=i%r,a=Math.min(i,i-s)+n,c=0,d=n;d<a;d+=r)c=u(e,d,d+r,t),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==s){var l=1;for(c=u(e,d,e.length,t),d=0;d<s;d++)l*=t;this.imuln(l),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(e){e.words=new 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},o.prototype._move=function(e){c(e,this)},o.prototype.clone=function(){var e=new o(null);return this.copy(e),e},o.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=d}catch(e){o.prototype.inspect=d}else o.prototype.inspect=d;function d(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var l=["","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"],p=[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],m=[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];function h(e,t,n){n.negative=t.negative^e.negative;var r=e.length+t.length|0;n.length=r,r=r-1|0;var o=0|e.words[0],i=0|t.words[0],s=o*i,a=67108863&s,u=s/67108864|0;n.words[0]=a;for(var c=1;c<r;c++){for(var d=u>>>26,l=67108863&u,p=Math.min(c,t.length-1),m=Math.max(0,c-e.length+1);m<=p;m++){var h=c-m|0;d+=(s=(o=0|e.words[h])*(i=0|t.words[m])+l)/67108864|0,l=67108863&s}n.words[c]=0|l,u=0|d}return 0!==u?n.words[c]=0|u:n.length--,n._strip()}o.prototype.toString=function(e,t){var r;if(t=0|t||1,16===(e=e||10)||"hex"===e){r="";for(var o=0,i=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<o|i)).toString(16);i=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,s--),r=0!==i||s!==this.length-1?l[6-u.length]+u+r:u+r}for(0!==i&&(r=i.toString(16)+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var c=p[e],d=m[e];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var f=h.modrn(d).toString(e);r=(h=h.idivn(d)).isZero()?f+r:l[c-f.length]+f+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(0,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(e,t){return this.toArrayLike(i,e,t)}),o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,r){this._strip();var o=this.byteLength(),i=r||Math.max(1,o);n(o<=i,"byte array longer than desired length"),n(i>0,"Requested array length <= 0");var s=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)}(e,i);return this["_toArrayLike"+("le"===t?"LE":"BE")](s,o),s},o.prototype._toArrayLikeLE=function(e){for(var t=0,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;e[t++]=255&i,t<e.length&&(e[t++]=i>>8&255),t<e.length&&(e[t++]=i>>16&255),6===o?(t<e.length&&(e[t++]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(t<e.length)for(e[t++]=n;t<e.length;)e[t++]=0},o.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;e[t--]=255&i,t>=0&&(e[t--]=i>>8&255),t>=0&&(e[t--]=i>>16&255),6===o?(t>=0&&(e[t--]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(t>=0)for(e[t--]=n;t>=0;)e[t--]=0},Math.clz32?o.prototype._countBits=function(e){return 32-Math.clz32(e)}:o.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},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,n=0;return 0==(8191&t)&&(n+=13,t>>>=13),0==(127&t)&&(n+=7,t>>>=7),0==(15&t)&&(n+=4,t>>>=4),0==(3&t)&&(n+=2,t>>>=2),0==(1&t)&&n++,n},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.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,26!==n)break}return e},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},o.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.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()},o.prototype.ior=function(e){return n(0==(this.negative|e.negative)),this.iuor(e)},o.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var n=0;n<t.length;n++)this.words[n]=this.words[n]&e.words[n];return this.length=t.length,this._strip()},o.prototype.iand=function(e){return n(0==(this.negative|e.negative)),this.iuand(e)},o.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.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()},o.prototype.ixor=function(e){return n(0==(this.negative|e.negative)),this.iuxor(e)},o.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var o=0;o<t;o++)this.words[o]=67108863&~this.words[o];return r>0&&(this.words[o]=~this.words[o]&67108863>>26-r),this._strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,o=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<<o:this.words[r]&~(1<<o),this._strip()},o.prototype.iadd=function(e){var t,n,r;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(n=this,r=e):(n=e,r=this);for(var o=0,i=0;i<r.length;i++)t=(0|n.words[i])+(0|r.words[i])+o,this.words[i]=67108863&t,o=t>>>26;for(;0!==o&&i<n.length;i++)t=(0|n.words[i])+o,this.words[i]=67108863&t,o=t>>>26;if(this.length=n.length,0!==o)this.words[this.length]=o,this.length++;else if(n!==this)for(;i<n.length;i++)this.words[i]=n.words[i];return this},o.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n,r,o=this.cmp(e);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(n=this,r=e):(n=e,r=this);for(var i=0,s=0;s<r.length;s++)i=(t=(0|n.words[s])-(0|r.words[s])+i)>>26,this.words[s]=67108863&t;for(;0!==i&&s<n.length;s++)i=(t=(0|n.words[s])+i)>>26,this.words[s]=67108863&t;if(0===i&&s<n.length&&n!==this)for(;s<n.length;s++)this.words[s]=n.words[s];return this.length=Math.max(this.length,s),n!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var f=function(e,t,n){var r,o,i,s=e.words,a=t.words,u=n.words,c=0,d=0|s[0],l=8191&d,p=d>>>13,m=0|s[1],h=8191&m,f=m>>>13,g=0|s[2],y=8191&g,b=g>>>13,I=0|s[3],w=8191&I,k=I>>>13,A=0|s[4],M=8191&A,v=A>>>13,P=0|s[5],x=8191&P,T=P>>>13,S=0|s[6],C=8191&S,O=S>>>13,_=0|s[7],E=8191&_,B=_>>>13,D=0|s[8],R=8191&D,K=D>>>13,L=0|s[9],N=8191&L,W=L>>>13,U=0|a[0],q=8191&U,G=U>>>13,V=0|a[1],F=8191&V,z=V>>>13,j=0|a[2],$=8191&j,Z=j>>>13,H=0|a[3],Q=8191&H,J=H>>>13,X=0|a[4],Y=8191&X,ee=X>>>13,te=0|a[5],ne=8191&te,re=te>>>13,oe=0|a[6],ie=8191&oe,se=oe>>>13,ae=0|a[7],ue=8191&ae,ce=ae>>>13,de=0|a[8],le=8191&de,pe=de>>>13,me=0|a[9],he=8191&me,fe=me>>>13;n.negative=e.negative^t.negative,n.length=19;var ge=(c+(r=Math.imul(l,q))|0)+((8191&(o=(o=Math.imul(l,G))+Math.imul(p,q)|0))<<13)|0;c=((i=Math.imul(p,G))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,r=Math.imul(h,q),o=(o=Math.imul(h,G))+Math.imul(f,q)|0,i=Math.imul(f,G);var ye=(c+(r=r+Math.imul(l,F)|0)|0)+((8191&(o=(o=o+Math.imul(l,z)|0)+Math.imul(p,F)|0))<<13)|0;c=((i=i+Math.imul(p,z)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,r=Math.imul(y,q),o=(o=Math.imul(y,G))+Math.imul(b,q)|0,i=Math.imul(b,G),r=r+Math.imul(h,F)|0,o=(o=o+Math.imul(h,z)|0)+Math.imul(f,F)|0,i=i+Math.imul(f,z)|0;var be=(c+(r=r+Math.imul(l,$)|0)|0)+((8191&(o=(o=o+Math.imul(l,Z)|0)+Math.imul(p,$)|0))<<13)|0;c=((i=i+Math.imul(p,Z)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,r=Math.imul(w,q),o=(o=Math.imul(w,G))+Math.imul(k,q)|0,i=Math.imul(k,G),r=r+Math.imul(y,F)|0,o=(o=o+Math.imul(y,z)|0)+Math.imul(b,F)|0,i=i+Math.imul(b,z)|0,r=r+Math.imul(h,$)|0,o=(o=o+Math.imul(h,Z)|0)+Math.imul(f,$)|0,i=i+Math.imul(f,Z)|0;var Ie=(c+(r=r+Math.imul(l,Q)|0)|0)+((8191&(o=(o=o+Math.imul(l,J)|0)+Math.imul(p,Q)|0))<<13)|0;c=((i=i+Math.imul(p,J)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,r=Math.imul(M,q),o=(o=Math.imul(M,G))+Math.imul(v,q)|0,i=Math.imul(v,G),r=r+Math.imul(w,F)|0,o=(o=o+Math.imul(w,z)|0)+Math.imul(k,F)|0,i=i+Math.imul(k,z)|0,r=r+Math.imul(y,$)|0,o=(o=o+Math.imul(y,Z)|0)+Math.imul(b,$)|0,i=i+Math.imul(b,Z)|0,r=r+Math.imul(h,Q)|0,o=(o=o+Math.imul(h,J)|0)+Math.imul(f,Q)|0,i=i+Math.imul(f,J)|0;var we=(c+(r=r+Math.imul(l,Y)|0)|0)+((8191&(o=(o=o+Math.imul(l,ee)|0)+Math.imul(p,Y)|0))<<13)|0;c=((i=i+Math.imul(p,ee)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,r=Math.imul(x,q),o=(o=Math.imul(x,G))+Math.imul(T,q)|0,i=Math.imul(T,G),r=r+Math.imul(M,F)|0,o=(o=o+Math.imul(M,z)|0)+Math.imul(v,F)|0,i=i+Math.imul(v,z)|0,r=r+Math.imul(w,$)|0,o=(o=o+Math.imul(w,Z)|0)+Math.imul(k,$)|0,i=i+Math.imul(k,Z)|0,r=r+Math.imul(y,Q)|0,o=(o=o+Math.imul(y,J)|0)+Math.imul(b,Q)|0,i=i+Math.imul(b,J)|0,r=r+Math.imul(h,Y)|0,o=(o=o+Math.imul(h,ee)|0)+Math.imul(f,Y)|0,i=i+Math.imul(f,ee)|0;var ke=(c+(r=r+Math.imul(l,ne)|0)|0)+((8191&(o=(o=o+Math.imul(l,re)|0)+Math.imul(p,ne)|0))<<13)|0;c=((i=i+Math.imul(p,re)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,r=Math.imul(C,q),o=(o=Math.imul(C,G))+Math.imul(O,q)|0,i=Math.imul(O,G),r=r+Math.imul(x,F)|0,o=(o=o+Math.imul(x,z)|0)+Math.imul(T,F)|0,i=i+Math.imul(T,z)|0,r=r+Math.imul(M,$)|0,o=(o=o+Math.imul(M,Z)|0)+Math.imul(v,$)|0,i=i+Math.imul(v,Z)|0,r=r+Math.imul(w,Q)|0,o=(o=o+Math.imul(w,J)|0)+Math.imul(k,Q)|0,i=i+Math.imul(k,J)|0,r=r+Math.imul(y,Y)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(b,Y)|0,i=i+Math.imul(b,ee)|0,r=r+Math.imul(h,ne)|0,o=(o=o+Math.imul(h,re)|0)+Math.imul(f,ne)|0,i=i+Math.imul(f,re)|0;var Ae=(c+(r=r+Math.imul(l,ie)|0)|0)+((8191&(o=(o=o+Math.imul(l,se)|0)+Math.imul(p,ie)|0))<<13)|0;c=((i=i+Math.imul(p,se)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,r=Math.imul(E,q),o=(o=Math.imul(E,G))+Math.imul(B,q)|0,i=Math.imul(B,G),r=r+Math.imul(C,F)|0,o=(o=o+Math.imul(C,z)|0)+Math.imul(O,F)|0,i=i+Math.imul(O,z)|0,r=r+Math.imul(x,$)|0,o=(o=o+Math.imul(x,Z)|0)+Math.imul(T,$)|0,i=i+Math.imul(T,Z)|0,r=r+Math.imul(M,Q)|0,o=(o=o+Math.imul(M,J)|0)+Math.imul(v,Q)|0,i=i+Math.imul(v,J)|0,r=r+Math.imul(w,Y)|0,o=(o=o+Math.imul(w,ee)|0)+Math.imul(k,Y)|0,i=i+Math.imul(k,ee)|0,r=r+Math.imul(y,ne)|0,o=(o=o+Math.imul(y,re)|0)+Math.imul(b,ne)|0,i=i+Math.imul(b,re)|0,r=r+Math.imul(h,ie)|0,o=(o=o+Math.imul(h,se)|0)+Math.imul(f,ie)|0,i=i+Math.imul(f,se)|0;var Me=(c+(r=r+Math.imul(l,ue)|0)|0)+((8191&(o=(o=o+Math.imul(l,ce)|0)+Math.imul(p,ue)|0))<<13)|0;c=((i=i+Math.imul(p,ce)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,r=Math.imul(R,q),o=(o=Math.imul(R,G))+Math.imul(K,q)|0,i=Math.imul(K,G),r=r+Math.imul(E,F)|0,o=(o=o+Math.imul(E,z)|0)+Math.imul(B,F)|0,i=i+Math.imul(B,z)|0,r=r+Math.imul(C,$)|0,o=(o=o+Math.imul(C,Z)|0)+Math.imul(O,$)|0,i=i+Math.imul(O,Z)|0,r=r+Math.imul(x,Q)|0,o=(o=o+Math.imul(x,J)|0)+Math.imul(T,Q)|0,i=i+Math.imul(T,J)|0,r=r+Math.imul(M,Y)|0,o=(o=o+Math.imul(M,ee)|0)+Math.imul(v,Y)|0,i=i+Math.imul(v,ee)|0,r=r+Math.imul(w,ne)|0,o=(o=o+Math.imul(w,re)|0)+Math.imul(k,ne)|0,i=i+Math.imul(k,re)|0,r=r+Math.imul(y,ie)|0,o=(o=o+Math.imul(y,se)|0)+Math.imul(b,ie)|0,i=i+Math.imul(b,se)|0,r=r+Math.imul(h,ue)|0,o=(o=o+Math.imul(h,ce)|0)+Math.imul(f,ue)|0,i=i+Math.imul(f,ce)|0;var ve=(c+(r=r+Math.imul(l,le)|0)|0)+((8191&(o=(o=o+Math.imul(l,pe)|0)+Math.imul(p,le)|0))<<13)|0;c=((i=i+Math.imul(p,pe)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,r=Math.imul(N,q),o=(o=Math.imul(N,G))+Math.imul(W,q)|0,i=Math.imul(W,G),r=r+Math.imul(R,F)|0,o=(o=o+Math.imul(R,z)|0)+Math.imul(K,F)|0,i=i+Math.imul(K,z)|0,r=r+Math.imul(E,$)|0,o=(o=o+Math.imul(E,Z)|0)+Math.imul(B,$)|0,i=i+Math.imul(B,Z)|0,r=r+Math.imul(C,Q)|0,o=(o=o+Math.imul(C,J)|0)+Math.imul(O,Q)|0,i=i+Math.imul(O,J)|0,r=r+Math.imul(x,Y)|0,o=(o=o+Math.imul(x,ee)|0)+Math.imul(T,Y)|0,i=i+Math.imul(T,ee)|0,r=r+Math.imul(M,ne)|0,o=(o=o+Math.imul(M,re)|0)+Math.imul(v,ne)|0,i=i+Math.imul(v,re)|0,r=r+Math.imul(w,ie)|0,o=(o=o+Math.imul(w,se)|0)+Math.imul(k,ie)|0,i=i+Math.imul(k,se)|0,r=r+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(b,ue)|0,i=i+Math.imul(b,ce)|0,r=r+Math.imul(h,le)|0,o=(o=o+Math.imul(h,pe)|0)+Math.imul(f,le)|0,i=i+Math.imul(f,pe)|0;var Pe=(c+(r=r+Math.imul(l,he)|0)|0)+((8191&(o=(o=o+Math.imul(l,fe)|0)+Math.imul(p,he)|0))<<13)|0;c=((i=i+Math.imul(p,fe)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,r=Math.imul(N,F),o=(o=Math.imul(N,z))+Math.imul(W,F)|0,i=Math.imul(W,z),r=r+Math.imul(R,$)|0,o=(o=o+Math.imul(R,Z)|0)+Math.imul(K,$)|0,i=i+Math.imul(K,Z)|0,r=r+Math.imul(E,Q)|0,o=(o=o+Math.imul(E,J)|0)+Math.imul(B,Q)|0,i=i+Math.imul(B,J)|0,r=r+Math.imul(C,Y)|0,o=(o=o+Math.imul(C,ee)|0)+Math.imul(O,Y)|0,i=i+Math.imul(O,ee)|0,r=r+Math.imul(x,ne)|0,o=(o=o+Math.imul(x,re)|0)+Math.imul(T,ne)|0,i=i+Math.imul(T,re)|0,r=r+Math.imul(M,ie)|0,o=(o=o+Math.imul(M,se)|0)+Math.imul(v,ie)|0,i=i+Math.imul(v,se)|0,r=r+Math.imul(w,ue)|0,o=(o=o+Math.imul(w,ce)|0)+Math.imul(k,ue)|0,i=i+Math.imul(k,ce)|0,r=r+Math.imul(y,le)|0,o=(o=o+Math.imul(y,pe)|0)+Math.imul(b,le)|0,i=i+Math.imul(b,pe)|0;var xe=(c+(r=r+Math.imul(h,he)|0)|0)+((8191&(o=(o=o+Math.imul(h,fe)|0)+Math.imul(f,he)|0))<<13)|0;c=((i=i+Math.imul(f,fe)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,r=Math.imul(N,$),o=(o=Math.imul(N,Z))+Math.imul(W,$)|0,i=Math.imul(W,Z),r=r+Math.imul(R,Q)|0,o=(o=o+Math.imul(R,J)|0)+Math.imul(K,Q)|0,i=i+Math.imul(K,J)|0,r=r+Math.imul(E,Y)|0,o=(o=o+Math.imul(E,ee)|0)+Math.imul(B,Y)|0,i=i+Math.imul(B,ee)|0,r=r+Math.imul(C,ne)|0,o=(o=o+Math.imul(C,re)|0)+Math.imul(O,ne)|0,i=i+Math.imul(O,re)|0,r=r+Math.imul(x,ie)|0,o=(o=o+Math.imul(x,se)|0)+Math.imul(T,ie)|0,i=i+Math.imul(T,se)|0,r=r+Math.imul(M,ue)|0,o=(o=o+Math.imul(M,ce)|0)+Math.imul(v,ue)|0,i=i+Math.imul(v,ce)|0,r=r+Math.imul(w,le)|0,o=(o=o+Math.imul(w,pe)|0)+Math.imul(k,le)|0,i=i+Math.imul(k,pe)|0;var Te=(c+(r=r+Math.imul(y,he)|0)|0)+((8191&(o=(o=o+Math.imul(y,fe)|0)+Math.imul(b,he)|0))<<13)|0;c=((i=i+Math.imul(b,fe)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,r=Math.imul(N,Q),o=(o=Math.imul(N,J))+Math.imul(W,Q)|0,i=Math.imul(W,J),r=r+Math.imul(R,Y)|0,o=(o=o+Math.imul(R,ee)|0)+Math.imul(K,Y)|0,i=i+Math.imul(K,ee)|0,r=r+Math.imul(E,ne)|0,o=(o=o+Math.imul(E,re)|0)+Math.imul(B,ne)|0,i=i+Math.imul(B,re)|0,r=r+Math.imul(C,ie)|0,o=(o=o+Math.imul(C,se)|0)+Math.imul(O,ie)|0,i=i+Math.imul(O,se)|0,r=r+Math.imul(x,ue)|0,o=(o=o+Math.imul(x,ce)|0)+Math.imul(T,ue)|0,i=i+Math.imul(T,ce)|0,r=r+Math.imul(M,le)|0,o=(o=o+Math.imul(M,pe)|0)+Math.imul(v,le)|0,i=i+Math.imul(v,pe)|0;var Se=(c+(r=r+Math.imul(w,he)|0)|0)+((8191&(o=(o=o+Math.imul(w,fe)|0)+Math.imul(k,he)|0))<<13)|0;c=((i=i+Math.imul(k,fe)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,r=Math.imul(N,Y),o=(o=Math.imul(N,ee))+Math.imul(W,Y)|0,i=Math.imul(W,ee),r=r+Math.imul(R,ne)|0,o=(o=o+Math.imul(R,re)|0)+Math.imul(K,ne)|0,i=i+Math.imul(K,re)|0,r=r+Math.imul(E,ie)|0,o=(o=o+Math.imul(E,se)|0)+Math.imul(B,ie)|0,i=i+Math.imul(B,se)|0,r=r+Math.imul(C,ue)|0,o=(o=o+Math.imul(C,ce)|0)+Math.imul(O,ue)|0,i=i+Math.imul(O,ce)|0,r=r+Math.imul(x,le)|0,o=(o=o+Math.imul(x,pe)|0)+Math.imul(T,le)|0,i=i+Math.imul(T,pe)|0;var Ce=(c+(r=r+Math.imul(M,he)|0)|0)+((8191&(o=(o=o+Math.imul(M,fe)|0)+Math.imul(v,he)|0))<<13)|0;c=((i=i+Math.imul(v,fe)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,r=Math.imul(N,ne),o=(o=Math.imul(N,re))+Math.imul(W,ne)|0,i=Math.imul(W,re),r=r+Math.imul(R,ie)|0,o=(o=o+Math.imul(R,se)|0)+Math.imul(K,ie)|0,i=i+Math.imul(K,se)|0,r=r+Math.imul(E,ue)|0,o=(o=o+Math.imul(E,ce)|0)+Math.imul(B,ue)|0,i=i+Math.imul(B,ce)|0,r=r+Math.imul(C,le)|0,o=(o=o+Math.imul(C,pe)|0)+Math.imul(O,le)|0,i=i+Math.imul(O,pe)|0;var Oe=(c+(r=r+Math.imul(x,he)|0)|0)+((8191&(o=(o=o+Math.imul(x,fe)|0)+Math.imul(T,he)|0))<<13)|0;c=((i=i+Math.imul(T,fe)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,r=Math.imul(N,ie),o=(o=Math.imul(N,se))+Math.imul(W,ie)|0,i=Math.imul(W,se),r=r+Math.imul(R,ue)|0,o=(o=o+Math.imul(R,ce)|0)+Math.imul(K,ue)|0,i=i+Math.imul(K,ce)|0,r=r+Math.imul(E,le)|0,o=(o=o+Math.imul(E,pe)|0)+Math.imul(B,le)|0,i=i+Math.imul(B,pe)|0;var _e=(c+(r=r+Math.imul(C,he)|0)|0)+((8191&(o=(o=o+Math.imul(C,fe)|0)+Math.imul(O,he)|0))<<13)|0;c=((i=i+Math.imul(O,fe)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,r=Math.imul(N,ue),o=(o=Math.imul(N,ce))+Math.imul(W,ue)|0,i=Math.imul(W,ce),r=r+Math.imul(R,le)|0,o=(o=o+Math.imul(R,pe)|0)+Math.imul(K,le)|0,i=i+Math.imul(K,pe)|0;var Ee=(c+(r=r+Math.imul(E,he)|0)|0)+((8191&(o=(o=o+Math.imul(E,fe)|0)+Math.imul(B,he)|0))<<13)|0;c=((i=i+Math.imul(B,fe)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,r=Math.imul(N,le),o=(o=Math.imul(N,pe))+Math.imul(W,le)|0,i=Math.imul(W,pe);var Be=(c+(r=r+Math.imul(R,he)|0)|0)+((8191&(o=(o=o+Math.imul(R,fe)|0)+Math.imul(K,he)|0))<<13)|0;c=((i=i+Math.imul(K,fe)|0)+(o>>>13)|0)+(Be>>>26)|0,Be&=67108863;var De=(c+(r=Math.imul(N,he))|0)+((8191&(o=(o=Math.imul(N,fe))+Math.imul(W,he)|0))<<13)|0;return c=((i=Math.imul(W,fe))+(o>>>13)|0)+(De>>>26)|0,De&=67108863,u[0]=ge,u[1]=ye,u[2]=be,u[3]=Ie,u[4]=we,u[5]=ke,u[6]=Ae,u[7]=Me,u[8]=ve,u[9]=Pe,u[10]=xe,u[11]=Te,u[12]=Se,u[13]=Ce,u[14]=Oe,u[15]=_e,u[16]=Ee,u[17]=Be,u[18]=De,0!==c&&(u[19]=c,n.length++),n};function g(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var r=0,o=0,i=0;i<n.length-1;i++){var s=o;o=0;for(var a=67108863&r,u=Math.min(i,t.length-1),c=Math.max(0,i-e.length+1);c<=u;c++){var d=i-c,l=(0|e.words[d])*(0|t.words[c]),p=67108863&l;a=67108863&(p=p+a|0),o+=(s=(s=s+(l/67108864|0)|0)+(p>>>26)|0)>>>26,s&=67108863}n.words[i]=a,r=s,s=o}return 0!==r?n.words[i]=r:n.length--,n._strip()}function y(e,t,n){return g(e,t,n)}Math.imul||(f=h),o.prototype.mulTo=function(e,t){var n=this.length+e.length;return 10===this.length&&10===e.length?f(this,e,t):n<63?h(this,e,t):n<1024?g(this,e,t):y(this,e,t)},o.prototype.mul=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),y(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){var t=e<0;t&&(e=-e),n("number"==typeof e),n(e<67108864);for(var r=0,o=0;o<this.length;o++){var i=(0|this.words[o])*e,s=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=s>>>26,this.words[o]=67108863&s}return 0!==r&&(this.words[o]=r,this.length++),t?this.ineg():this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),n=0;n<t.length;n++){var r=n/26|0,o=n%26;t[n]=e.words[r]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var n=this,r=0;r<t.length&&0===t[r];r++,n=n.sqr());if(++r<t.length)for(var i=n.sqr();r<t.length;r++,i=i.sqr())0!==t[r]&&(n=n.mul(i));return n},o.prototype.iushln=function(e){n("number"==typeof e&&e>=0);var t,r=e%26,o=(e-r)/26,i=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(t=0;t<this.length;t++){var a=this.words[t]&i,u=(0|this.words[t])-a<<r;this.words[t]=u|s,s=a>>>26-r}s&&(this.words[t]=s,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(e){return n(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,r){var o;n("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var i=e%26,s=Math.min((e-i)/26,this.length),a=67108863^67108863>>>i<<i,u=r;if(o-=s,o=Math.max(0,o),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var d=0;for(c=this.length-1;c>=0&&(0!==d||c>=o);c--){var l=0|this.words[c];this.words[c]=d<<26-i|l>>>i,d=l&a}return u&&0!==d&&(u.words[u.length++]=d),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(e,t,r){return n(0===this.negative),this.iushrn(e,t,r)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26,o=1<<t;return this.length<=r?0:!!(this.words[r]&o)},o.prototype.imaskn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==t&&r++,this.length=Math.min(r,this.length),0!==t){var o=67108863^67108863>>>t<<t;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(e){return this.clone().imaskn(e)},o.prototype.iaddn=function(e){return n("number"==typeof e),n(e<67108864),e<0?this.isubn(-e):0!==this.negative?1===this.length&&(0|this.words[0])<=e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},o.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},o.prototype.isubn=function(e){if(n("number"==typeof e),n(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&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]-=1;return this._strip()},o.prototype.addn=function(e){return this.clone().iaddn(e)},o.prototype.subn=function(e){return this.clone().isubn(e)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(e,t,r){var o,i,s=e.length+r;this._expand(s);var a=0;for(o=0;o<e.length;o++){i=(0|this.words[o+r])+a;var u=(0|e.words[o])*t;a=((i-=67108863&u)>>26)-(u/67108864|0),this.words[o+r]=67108863&i}for(;o<this.length-r;o++)a=(i=(0|this.words[o+r])+a)>>26,this.words[o+r]=67108863&i;if(0===a)return this._strip();for(n(-1===a),a=0,o=0;o<this.length;o++)a=(i=-(0|this.words[o])+a)>>26,this.words[o]=67108863&i;return this.negative=1,this._strip()},o.prototype._wordDiv=function(e,t){var n=(this.length,e.length),r=this.clone(),i=e,s=0|i.words[i.length-1];0!=(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,u=r.length-i.length;if("mod"!==t){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var d=r.clone()._ishlnsubmul(i,1,u);0===d.negative&&(r=d,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var p=67108864*(0|r.words[i.length+l])+(0|r.words[i.length+l-1]);for(p=Math.min(p/s|0,67108863),r._ishlnsubmul(i,p,l);0!==r.negative;)p--,r.negative=0,r._ishlnsubmul(i,1,l),r.isZero()||(r.negative^=1);a&&(a.words[l]=p)}return a&&a._strip(),r._strip(),"div"!==t&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(e,t,r){return n(!e.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(i=a.div.neg()),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(e)),{div:i,mod:s}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(e)),{div:a.div,mod:s}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modrn(e.words[0]))}:this._wordDiv(e,t);var i,s,a},o.prototype.div=function(e){return this.divmod(e,"div",0).div},o.prototype.mod=function(e){return this.divmod(e,"mod",0).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",1).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=0!==t.div.negative?t.mod.isub(e):t.mod,r=e.ushrn(1),o=e.andln(1),i=n.cmp(r);return i<0||1===o&&0===i?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modrn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=(1<<26)%e,o=0,i=this.length-1;i>=0;i--)o=(r*o+(0|this.words[i]))%e;return t?-o:o},o.prototype.modn=function(e){return this.modrn(e)},o.prototype.idivn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=0,o=this.length-1;o>=0;o--){var i=(0|this.words[o])+67108864*r;this.words[o]=i/e|0,r=i%e}return this._strip(),t?this.ineg():this},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++c;for(var d=r.clone(),l=t.clone();!t.isZero();){for(var p=0,m=1;0==(t.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(t.iushrn(p);p-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(d),s.isub(l)),i.iushrn(1),s.iushrn(1);for(var h=0,f=1;0==(r.words[0]&f)&&h<26;++h,f<<=1);if(h>0)for(r.iushrn(h);h-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(d),u.isub(l)),a.iushrn(1),u.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(a),s.isub(u)):(r.isub(t),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,d=1;0==(t.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(t.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,p=1;0==(r.words[0]&p)&&l<26;++l,p<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(r)>=0?(t.isub(r),s.isub(a)):(r.isub(t),a.isub(s))}return(i=0===t.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(e),i},o.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);for(;;){for(;t.isEven();)t.iushrn(1);for(;n.isEven();)n.iushrn(1);var o=t.cmp(n);if(o<0){var i=t;t=n,n=i}else if(0===o||0===n.cmpn(1))break;t.isub(n)}return n.iushln(r)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){n("number"==typeof e);var t=e%26,r=(e-t)/26,o=1<<t;if(this.length<=r)return this._expand(r+1),this.words[r]|=o,this;for(var i=o,s=r;0!==i&&s<this.length;s++){var a=0|this.words[s];i=(a+=i)>>>26,a&=67108863,this.words[s]=a}return 0!==i&&(this.words[s]=i,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(e){var t,r=e<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)t=1;else{r&&(e=-e),n(e<=67108863,"Number is too big");var o=0|this.words[0];t=o===e?0:o<e?-1:1}return 0!==this.negative?0|-t:t},o.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0!==this.negative?0|-t:t},o.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=0|this.words[n],o=0|e.words[n];if(r!==o){r<o?t=-1:r>o&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new v(e)},o.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.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 I(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){I.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function k(){I.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){I.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){I.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function v(e){if("string"==typeof e){var t=o._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}function P(e){v.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}I.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},I.prototype.ireduce=function(e){var t,n=e;do{this.split(n,this.tmp),t=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(t>this.n);var r=t<this.n?-1:n.ucmp(this.p);return 0===r?(n.words[0]=0,n.length=1):r>0?n.isub(this.p):void 0!==n.strip?n.strip():n._strip(),n},I.prototype.split=function(e,t){e.iushrn(this.n,0,t)},I.prototype.imulK=function(e){return e.imul(this.k)},r(w,I),w.prototype.split=function(e,t){for(var n=4194303,r=Math.min(e.length,9),o=0;o<r;o++)t.words[o]=e.words[o];if(t.length=r,e.length<=9)return e.words[0]=0,void(e.length=1);var i=e.words[9];for(t.words[t.length++]=i&n,o=10;o<e.length;o++){var s=0|e.words[o];e.words[o-10]=(s&n)<<4|i>>>22,i=s}i>>>=22,e.words[o-10]=i,0===i&&e.length>10?e.length-=10:e.length-=9},w.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=0|e.words[n];t+=977*r,e.words[n]=67108863&t,t=64*r+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},r(k,I),r(A,I),r(M,I),M.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var r=19*(0|e.words[n])+t,o=67108863&r;r>>>=26,e.words[n]=o,t=r}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(b[e])return b[e];var t;if("k256"===e)t=new w;else if("p224"===e)t=new k;else if("p192"===e)t=new A;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new M}return b[e]=t,t},v.prototype._verify1=function(e){n(0===e.negative,"red works only with positives"),n(e.red,"red works only with red numbers")},v.prototype._verify2=function(e,t){n(0==(e.negative|t.negative),"red works only with positives"),n(e.red&&e.red===t.red,"red works only with red numbers")},v.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},v.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},v.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)},v.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},v.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)},v.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return n.cmpn(0)<0&&n.iadd(this.m),n},v.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},v.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},v.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},v.prototype.isqr=function(e){return this.imul(e,e.clone())},v.prototype.sqr=function(e){return this.mul(e,e)},v.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),3===t){var r=this.m.add(new o(1)).iushrn(2);return this.pow(e,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),d=this.m.bitLength();for(d=new o(2*d*d).toRed(this);0!==this.pow(d,c).cmp(u);)d.redIAdd(u);for(var l=this.pow(d,i),p=this.pow(e,i.addn(1).iushrn(1)),m=this.pow(e,i),h=s;0!==m.cmp(a);){for(var f=m,g=0;0!==f.cmp(a);g++)f=f.redSqr();n(g<h);var y=this.pow(l,new o(1).iushln(h-g-1));p=p.redMul(y),l=y.redSqr(),m=m.redMul(l),h=g}return p},v.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},v.prototype.pow=function(e,t){if(t.isZero())return new o(1).toRed(this);if(0===t.cmpn(1))return e.clone();var n=new Array(16);n[0]=new o(1).toRed(this),n[1]=e;for(var r=2;r<n.length;r++)n[r]=this.mul(n[r-1],e);var i=n[0],s=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),r=t.length-1;r>=0;r--){for(var c=t.words[r],d=u-1;d>=0;d--){var l=c>>d&1;i!==n[0]&&(i=this.sqr(i)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===r&&0===d)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}u=26}return i},v.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},v.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new P(e)},r(P,v),P.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},P.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},P.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),o=n.isub(r).iushrn(this.shift),i=o;return o.cmp(this.m)>=0?i=o.isub(this.m):o.cmpn(0)<0&&(i=o.iadd(this.m)),i._forceRed(this)},P.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var n=e.mul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},P.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,Ot);var Rt=_t(Bt.exports);const Kt={Spl:"spl",Token2022:"token2022",SplCold:"spl-cold",Token2022Cold:"token2022-cold",CTokenHot:"ctoken-hot",CTokenCold:"ctoken-cold"};function Lt(e){if(!e||0===e.length)return null;try{let t=0;const r=new n.PublicKey(e.slice(t,t+32));t+=32;const o=new n.PublicKey(e.slice(t,t+32));t+=32;const i=new Rt(e.slice(t,t+8),"le");t+=8;const s=e[t];t+=1;const a=s?new n.PublicKey(e.slice(t,t+32)):null;t+=32;const u=e[t];t+=1;const c=e[t];return t+=1,{mint:r,owner:o,amount:i,delegate:a,state:u,tlv:c?e.slice(t):null}}catch(e){return console.error("Token data parsing error:",e),null}}function Nt(e,t){return{address:e,mint:t.mint,owner:t.owner,amount:BigInt(t.amount.toString()),delegate:t.delegate,delegatedAmount:BigInt(0),isInitialized:t.state!==r.AccountState.Uninitialized,isFrozen:t.state===r.AccountState.Frozen,isNative:0,rentExemptReserve:null,closeAuthority:null,tlvData:t.tlv?o.Buffer.from(t.tlv):o.Buffer.alloc(0)}}function Wt(e){const t=o.Buffer.from(e.data.discriminator),n=o.Buffer.from(e.data.data),r=o.Buffer.concat([t,n]);return{executable:0,owner:e.owner,lamports:e.lamports.toNumber(),data:r,rentEpoch:void 0}}function Ut(e,t){const n=Lt(t.data);if(!n)throw new Error("Invalid token data");return{accountInfo:t,loadContext:void 0,parsed:Nt(e,n),isCold:0}}function qt(e,t){const n=Lt(t.data.data);if(!n)throw new Error("Invalid token data");return{accountInfo:Wt(t),loadContext:{treeInfo:t.treeInfo,hash:t.hash,leafIndex:t.leafIndex,proveByIndex:t.proveByIndex},parsed:Nt(e,n),isCold:1}}async function Gt(e,t,n,r){return Ft(e,t,n,r,void 0)}async function Vt(e,t,n,r,o,i,s=0,a=0){const u=ot(t,r,n,i,a);if(s&&"ctoken"!==u.type)throw new Error(`For wrap=true, ata must be the c-token ATA. Got ${u.type} ATA instead.`);const c=await Ft(e,t,o,i,{owner:n,mint:r},s);return c._isAta=1,c._owner=n,c._mint=r,c}async function Ft(e,n,o,i,s,a=0){if(!n&&!s)throw new Error("One of address or fetchByOwner is required");if(!i)return async function(e,n,o,i,s){const a=null!=n?n:r.getAssociatedTokenAddressSync(i.mint,i.owner,0,t.CTOKEN_PROGRAM_ID,rt(t.CTOKEN_PROGRAM_ID)),u=[],c=[],d=[];if(u.push(async function(e,n,r){const o=await e.getAccountInfo(n,r);if(!o||!o.owner.equals(t.CTOKEN_PROGRAM_ID))throw new Error("Not a CTOKEN onchain account");return Ut(n,o)}(e,a,o)),c.push(Kt.CTokenHot),d.push(a),u.push(i?async function(e,n,r,o){var i;const s=await e.getCompressedTokenAccountsByOwner(n,{mint:r}),a=s.items.length>0?s.items[0].compressedAccount:null;if(!(null===(i=null==a?void 0:a.data)||void 0===i?void 0:i.data.length))throw new Error("Not a compressed token account");if(!a.owner.equals(t.CTOKEN_PROGRAM_ID))throw new Error("Invalid owner for compressed token");return qt(o,a)}(e,i.owner,i.mint,a):async function(e,n){var r;const o=t.getDefaultAddressTreeInfo().tree,i=t.deriveAddressV2(n.toBytes(),o,t.CTOKEN_PROGRAM_ID),s=await e.getCompressedAccount(t.bn(i.toBytes()));if(!(null===(r=null==s?void 0:s.data)||void 0===r?void 0:r.data.length))throw new Error("Compressed token account not found at derived address. Note: getAccountInterface only finds compressed accounts that were compressed from on-chain (via compress_accounts_idempotent). For tokens minted compressed (via mintTo), use getAtaInterface with owner+mint.");if(!s.owner.equals(t.CTOKEN_PROGRAM_ID))throw new Error("Invalid owner for compressed token");return qt(n,s)}(e,n)),c.push(Kt.CTokenCold),d.push(a),s){if(!i)throw new Error("fetchByOwner is required for wrap=true to derive SPL/T22 addresses");const t=r.getAssociatedTokenAddressSync(i.mint,i.owner,0,r.TOKEN_PROGRAM_ID,rt(r.TOKEN_PROGRAM_ID)),n=r.getAssociatedTokenAddressSync(i.mint,i.owner,0,r.TOKEN_2022_PROGRAM_ID,rt(r.TOKEN_2022_PROGRAM_ID));u.push(async function(e,t,n){const o=await e.getAccountInfo(t,n);if(!o||!o.owner.equals(r.TOKEN_PROGRAM_ID))throw new Error("Not a TOKEN_PROGRAM_ID account");return{accountInfo:o,parsed:r.unpackAccount(t,o,r.TOKEN_PROGRAM_ID),isCold:0,loadContext:void 0}}(e,t,o)),c.push(Kt.Spl),d.push(t),u.push(async function(e,t,n){const o=await e.getAccountInfo(t,n);if(!o||!o.owner.equals(r.TOKEN_2022_PROGRAM_ID))throw new Error("Not a TOKEN_2022_PROGRAM_ID account");return{accountInfo:o,parsed:r.unpackAccount(t,o,r.TOKEN_2022_PROGRAM_ID),isCold:0,loadContext:void 0}}(e,n,o)),c.push(Kt.Token2022),d.push(n)}const l=await Promise.allSettled(u),p=[];for(let e=0;e<l.length;e++){const t=l[e];if("fulfilled"===t.status){const n=t.value;p.push({type:c[e],address:d[e],amount:n.parsed.amount,accountInfo:n.accountInfo,loadContext:n.loadContext,parsed:n.parsed})}}if(0===p.length)throw new r.TokenAccountNotFoundError;const m=[Kt.CTokenHot,Kt.CTokenCold,Kt.Spl,Kt.Token2022];return p.sort(((e,t)=>m.indexOf(e.type)-m.indexOf(t.type))),zt(p,a)}(e,n,o,s,a);if(i.equals(t.CTOKEN_PROGRAM_ID))return async function(e,n,o,i){if(!n){if(!i)throw new Error("fetchByOwner is required");n=r.getAssociatedTokenAddressSync(i.mint,i.owner,0,t.CTOKEN_PROGRAM_ID,rt(t.CTOKEN_PROGRAM_ID))}const[s,a]=await Promise.allSettled([e.getAccountInfo(n,o),i?e.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):e.getCompressedTokenAccountsByOwner(n)]),u="fulfilled"===s.status?s.value:null,c="fulfilled"===a.status?a.value.items.map((e=>e.compressedAccount)):[],d=[];if(u&&u.owner.equals(t.CTOKEN_PROGRAM_ID)){const e=Ut(n,u);d.push({type:Kt.CTokenHot,address:n,amount:e.parsed.amount,accountInfo:u,parsed:e.parsed})}for(const e of c)if(e&&e.data&&e.data.data.length>0&&e.owner.equals(t.CTOKEN_PROGRAM_ID)){const t=qt(n,e);d.push({type:Kt.CTokenCold,address:n,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}if(0===d.length)throw new r.TokenAccountNotFoundError;return d.sort(((e,t)=>"ctoken-hot"===e.type&&"ctoken-cold"===t.type?-1:"ctoken-cold"===e.type&&"ctoken-hot"===t.type?1:0)),zt(d,n)}(e,n,o,s);if(i.equals(r.TOKEN_PROGRAM_ID)||i.equals(r.TOKEN_2022_PROGRAM_ID))return async function(e,n,o,i,s){if(!n){if(!s)throw new Error("fetchByOwner is required");n=r.getAssociatedTokenAddressSync(s.mint,s.owner,0,i,rt(i))}const a=await e.getAccountInfo(n,o);if(!a)throw new r.TokenAccountNotFoundError;const u=r.unpackAccount(n,a,i),c=[{type:i.equals(r.TOKEN_PROGRAM_ID)?Kt.Spl:Kt.Token2022,address:n,amount:u.amount,accountInfo:a,parsed:u}];if(s){const o=(await e.getCompressedTokenAccountsByOwner(s.owner,{mint:s.mint})).items.map((e=>e.compressedAccount)),a=i.equals(r.TOKEN_PROGRAM_ID)?Kt.SplCold:Kt.Token2022Cold;for(const e of o)if(e&&e.data&&e.data.data.length>0&&e.owner.equals(t.CTOKEN_PROGRAM_ID)){const t=qt(n,e);c.push({type:a,address:n,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}}return zt(c,n)}(e,n,o,i,s);throw new Error(`Unsupported program ID: ${i.toBase58()}`)}function zt(e,t){const n=e.reduce(((e,t)=>e+t.amount),BigInt(0)),r=e[0],o=e.some((e=>null!==e.parsed.delegate)),i=e.some((e=>e.parsed.isFrozen)),s=e.length>1,a=Object.assign(Object.assign({},r.parsed),{address:t,amount:n});return{accountInfo:r.accountInfo,parsed:a,isCold:["ctoken-cold","spl-cold","token2022-cold"].includes(r.type),loadContext:r.loadContext,_sources:e,_needsConsolidation:s,_hasDelegate:o,_anyFrozen:i}}function jt(e,n,o=0,i=t.CTOKEN_PROGRAM_ID,s){const a=null!=s?s:rt(i);return r.getAssociatedTokenAddressSync(e,n,o,i,a)}function $t(e,r,o,i,s,a,u=o){const c=Pt({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:0,cpiContext:null,compressions:[xt(s,0,2,1,4,a.poolIndex,a.bump),Tt(s,0,3,6)],proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),d=[{pubkey:me.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:u,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:e,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:t.CTOKEN_PROGRAM_ID,isSigner:0,isWritable:0}];return new n.TransactionInstruction({programId:me.programId,keys:d,data:c})}function Zt(e){const n=new Set([Kt.CTokenCold,Kt.SplCold,Kt.Token2022Cold]);return e.filter((e=>void 0!==e.loadContext)).filter((e=>n.has(e.type))).map((e=>{const n=e.accountInfo.data,r=n.subarray(0,Math.min(8,n.length)),o=n.length>8?n.subarray(8):Buffer.alloc(0),i={treeInfo:e.loadContext.treeInfo,hash:e.loadContext.hash,leafIndex:e.loadContext.leafIndex,proveByIndex:e.loadContext.proveByIndex,owner:e.accountInfo.owner,lamports:t.bn(e.accountInfo.lamports),address:null,data:0===n.length?null:{discriminator:Array.from(r),data:Buffer.from(o),dataHash:new Array(32).fill(0)},readOnly:0},s=e.parsed.isInitialized?e.parsed.isFrozen?2:1:0;return{compressedAccount:i,parsed:{mint:e.parsed.mint,owner:e.parsed.owner,amount:t.bn(e.parsed.amount.toString()),delegate:e.parsed.delegate,state:s,tlv:e.parsed.tlvData.length>0?e.parsed.tlvData:null}}}))}async function Ht(e,t,n,o,i,s,a=0){null!=i||(i=n);try{return Qt(e,i,await Vt(e,t,n,o,void 0,void 0,a),s,a,t)}catch(e){if(e instanceof r.TokenAccountNotFoundError)return[];throw e}}async function Qt(e,n,o,i,s=0,a){var u,c,d,l,p;if(!o._isAta||!o._owner||!o._mint)throw new Error("AccountInterface must be from getAtaInterface (requires _isAta, _owner, _mint)");const m=[],h=o._owner,f=o._mint,g=null!==(u=o._sources)&&void 0!==u?u:[],y=jt(f,h),b=r.getAssociatedTokenAddressSync(f,h,0,r.TOKEN_PROGRAM_ID,rt(r.TOKEN_PROGRAM_ID)),I=r.getAssociatedTokenAddressSync(f,h,0,r.TOKEN_2022_PROGRAM_ID,rt(r.TOKEN_2022_PROGRAM_ID));let w="ctoken";if(a&&(w=ot(a,f,h).type,s&&"ctoken"!==w))throw new Error(`For wrap=true, targetAta must be c-token ATA. Got ${w} ATA.`);const A=g.find((e=>"spl"===e.type)),M=g.find((e=>"token2022"===e.type)),v=g.find((e=>"ctoken-hot"===e.type)),P=g.find((e=>"ctoken-cold"===e.type)),x=null!==(c=null==A?void 0:A.amount)&&void 0!==c?c:BigInt(0),T=null!==(d=null==M?void 0:M.amount)&&void 0!==d?d:BigInt(0),S=null!==(l=null==P?void 0:P.amount)&&void 0!==l?l:BigInt(0);if(x===BigInt(0)&&T===BigInt(0)&&S===BigInt(0))return[];let C;if(s||"spl"===w||"token2022"===w||x>BigInt(0)||T>BigInt(0))try{C=(null!==(p=null==i?void 0:i.splInterfaceInfos)&&void 0!==p?p:await k(e,f)).find((e=>e.isInitialized))}catch(e){}if(s){if(v||m.push(at(n,y,h,f,t.CTOKEN_PROGRAM_ID)),x>BigInt(0)&&C&&m.push($t(b,y,h,f,x,C,n)),T>BigInt(0)&&C&&m.push($t(I,y,h,f,T,C,n)),S>BigInt(0)&&P){const t=Zt(g);if(t.length>0){const r=await e.getValidityProofV0(t.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue}))));m.push(Ct(n,t,y,S,r))}}}else if(S>BigInt(0)&&P){const o=Zt(g);if(o.length>0){const i=await e.getValidityProofV0(o.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue}))));"ctoken"===w?(v||m.push(at(n,y,h,f,t.CTOKEN_PROGRAM_ID)),m.push(Ct(n,o,y,S,i))):"spl"===w&&C?(A||m.push(r.createAssociatedTokenAccountIdempotentInstruction(n,b,h,f,r.TOKEN_PROGRAM_ID)),m.push(Ct(n,o,b,S,i,C))):"token2022"===w&&C&&(M||m.push(r.createAssociatedTokenAccountIdempotentInstruction(n,I,h,f,r.TOKEN_2022_PROGRAM_ID)),m.push(Ct(n,o,I,S,i,C)))}}return m}async function Jt(e,r,o,i,s,a,u,c=0){null!=s||(s=o);const d=await Ht(e,r,o.publicKey,i,s.publicKey,u,c);if(0===d.length)return null;const{blockhash:l}=await e.getLatestBlockhash(),p=t.dedupeSigner(s,[o]),m=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),...d],s,l,p);return t.sendAndConfirmTx(e,m,a)}async function Xt(e,o,i,s,a=n.Keypair.generate(),u,c,d){const l=await e.getMinimumBalanceForRentExemption(r.MINT_SIZE),p=1==c?r.TOKEN_2022_PROGRAM_ID:c||r.TOKEN_PROGRAM_ID,m=await me.createMint({feePayer:o.publicKey,mint:a.publicKey,decimals:s,authority:"secretKey"in i?i.publicKey:i,freezeAuthority:d&&"secretKey"in d?d.publicKey:null!=d?d:null,rentExemptBalance:l,tokenProgramId:p}),{blockhash:h}=await e.getLatestBlockhash(),f=t.dedupeSigner(o,[i,null!=d?d:null].filter((e=>null!=e&&"secretKey"in e))),g=t.buildAndSignTx(m,o,h,[...f,a]),y=await t.sendAndConfirmTx(e,g,u);return{mint:a.publicKey,transactionSignature:y}}var Yt={};Object.defineProperty(Yt,"__esModule",{value:1}),Yt.s16=Yt.s8=Yt.nu64be=Yt.u48be=Yt.u40be=Yt.u32be=Yt.u24be=Yt.u16be=Yt.nu64=Yt.u48=Yt.u40=Yt.u32=Yt.u24=Yt.u16=Nn=Yt.u8=Yt.offset=Yt.greedy=Yt.Constant=Yt.UTF8=Yt.CString=Yt.Blob=Yt.Boolean=Yt.BitField=Yt.BitStructure=Yt.VariantLayout=Yt.Union=Yt.UnionLayoutDiscriminator=Yt.UnionDiscriminator=Yt.Structure=Yt.Sequence=Yt.DoubleBE=Yt.Double=Yt.FloatBE=Yt.Float=Yt.NearInt64BE=Yt.NearInt64=Yt.NearUInt64BE=Yt.NearUInt64=Yt.IntBE=Yt.Int=Yt.UIntBE=Yt.UInt=Yt.OffsetLayout=Yt.GreedyCount=Yt.ExternalLayout=Yt.bindConstructorLayout=Yt.nameWithProperty=Yt.Layout=Yt.uint8ArrayToBuffer=Yt.checkUint8Array=void 0,Yt.constant=Yt.utf8=Yt.cstr=Un=Yt.blob=Yt.unionLayoutDiscriminator=Yt.union=Yt.seq=Yt.bits=Wn=Yt.struct=Yt.f64be=Yt.f64=Yt.f32be=Yt.f32=Yt.ns64be=Yt.s48be=Yt.s40be=Yt.s32be=Yt.s24be=Yt.s16be=Yt.ns64=Yt.s48=Yt.s40=Yt.s32=Yt.s24=void 0;const en=o;function tn(e){if(!(e instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function nn(e){return tn(e),en.Buffer.from(e.buffer,e.byteOffset,e.length)}Yt.checkUint8Array=tn,Yt.uint8ArrayToBuffer=nn;class rn{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function on(e,t){return t.property?e+"["+t.property+"]":e}Yt.Layout=rn,Yt.nameWithProperty=on,Yt.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(e,"layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof rn))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(t,"boundConstructor_"))throw new 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:1}),Object.defineProperty(e,"decode",{value:(e,n)=>t.decode(e,n),writable:1})};class sn extends rn{isCount(){throw new Error("ExternalLayout is abstract")}}Yt.ExternalLayout=sn;class an extends sn{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t=0){tn(e);const n=e.length-t;return Math.floor(n/this.elementSpan)}encode(e,t,n){return 0}}Yt.GreedyCount=an;class un extends sn{constructor(e,t=0,n){if(!(e instanceof rn))throw new TypeError("layout must be a Layout");if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,n||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof cn||this.layout instanceof dn}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)}}Yt.OffsetLayout=un;class cn extends rn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return nn(e).readUIntLE(t,this.span)}encode(e,t,n=0){return nn(t).writeUIntLE(e,n,this.span),this.span}}Yt.UInt=cn;class dn extends rn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return nn(e).readUIntBE(t,this.span)}encode(e,t,n=0){return nn(t).writeUIntBE(e,n,this.span),this.span}}Yt.UIntBE=dn;class ln extends rn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return nn(e).readIntLE(t,this.span)}encode(e,t,n=0){return nn(t).writeIntLE(e,n,this.span),this.span}}Yt.Int=ln;class pn extends rn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return nn(e).readIntBE(t,this.span)}encode(e,t,n=0){return nn(t).writeIntBE(e,n,this.span),this.span}}Yt.IntBE=pn;const mn=Math.pow(2,32);function hn(e){const t=Math.floor(e/mn);return{hi32:t,lo32:e-t*mn}}function fn(e,t){return e*mn+t}class gn extends rn{constructor(e){super(8,e)}decode(e,t=0){const n=nn(e),r=n.readUInt32LE(t);return fn(n.readUInt32LE(t+4),r)}encode(e,t,n=0){const r=hn(e),o=nn(t);return o.writeUInt32LE(r.lo32,n),o.writeUInt32LE(r.hi32,n+4),8}}Yt.NearUInt64=gn;class yn extends rn{constructor(e){super(8,e)}decode(e,t=0){const n=nn(e);return fn(n.readUInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){const r=hn(e),o=nn(t);return o.writeUInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}Yt.NearUInt64BE=yn;class bn extends rn{constructor(e){super(8,e)}decode(e,t=0){const n=nn(e),r=n.readUInt32LE(t);return fn(n.readInt32LE(t+4),r)}encode(e,t,n=0){const r=hn(e),o=nn(t);return o.writeUInt32LE(r.lo32,n),o.writeInt32LE(r.hi32,n+4),8}}Yt.NearInt64=bn;class In extends rn{constructor(e){super(8,e)}decode(e,t=0){const n=nn(e);return fn(n.readInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){const r=hn(e),o=nn(t);return o.writeInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}Yt.NearInt64BE=In;class wn extends rn{constructor(e){super(4,e)}decode(e,t=0){return nn(e).readFloatLE(t)}encode(e,t,n=0){return nn(t).writeFloatLE(e,n),4}}Yt.Float=wn;class kn extends rn{constructor(e){super(4,e)}decode(e,t=0){return nn(e).readFloatBE(t)}encode(e,t,n=0){return nn(t).writeFloatBE(e,n),4}}Yt.FloatBE=kn;class An extends rn{constructor(e){super(8,e)}decode(e,t=0){return nn(e).readDoubleLE(t)}encode(e,t,n=0){return nn(t).writeDoubleLE(e,n),8}}Yt.Double=An;class Mn extends rn{constructor(e){super(8,e)}decode(e,t=0){return nn(e).readDoubleBE(t)}encode(e,t,n=0){return nn(t).writeDoubleBE(e,n),8}}Yt.DoubleBE=Mn;class vn extends rn{constructor(e,t,n){if(!(e instanceof rn))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof sn&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let r=-1;!(t instanceof sn)&&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 sn&&(r=r.decode(e,t)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let o=0;for(;o<r;)n+=this.elementLayout.getSpan(e,t+n),++o}return n}decode(e,t=0){const n=[];let r=0,o=this.count;for(o instanceof sn&&(o=o.decode(e,t));r<o;)n.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),r+=1;return n}encode(e,t,n=0){const r=this.elementLayout,o=e.reduce(((e,o)=>e+r.encode(o,t,n+e)),0);return this.count instanceof sn&&this.count.encode(e.length,t,n),o}}Yt.Sequence=vn;class Pn extends rn{constructor(e,t,n){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof rn),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===n&&(n=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let r=-1;try{r=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}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)=>{const o=r.getSpan(e,t);return t+=o,n+o}),0)}catch(e){throw new RangeError("indeterminate span")}return n}decode(e,t=0){tn(e);const n=this.makeDestinationObject();for(const r of this.fields)if(void 0!==r.property&&(n[r.property]=r.decode(e,t)),t+=r.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return n}encode(e,t,n=0){const r=n;let o=0,i=0;for(const r of this.fields){let s=r.span;if(i=0<s?s:0,void 0!==r.property){const o=e[r.property];void 0!==o&&(i=r.encode(o,t,n),0>s&&(s=r.getSpan(t,n)))}o=n,n+=s}return o+i-r}fromArray(e){const t=this.makeDestinationObject();for(const n of this.fields)void 0!==n.property&&0<e.length&&(t[n.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const n of this.fields){if(n.property===e)return t;0>n.span?t=-1:0<=t&&(t+=n.span)}}}Yt.Structure=Pn;class xn{constructor(e){this.property=e}decode(e,t){throw new Error("UnionDiscriminator is abstract")}encode(e,t,n){throw new Error("UnionDiscriminator is abstract")}}Yt.UnionDiscriminator=xn;class Tn extends xn{constructor(e,t){if(!(e instanceof sn&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,n){return this.layout.encode(e,t,n)}}Yt.UnionLayoutDiscriminator=Tn;class Sn extends rn{constructor(e,t,n){let r;if(e instanceof cn||e instanceof dn)r=new Tn(new un(e));else if(e instanceof sn&&e.isCount())r=new Tn(e);else{if(!(e instanceof xn))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");r=e}if(void 0===t&&(t=null),!(null===t||t instanceof rn))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&(e instanceof cn||e instanceof dn)&&(o+=r.layout.span)),super(o,n),this.discriminator=r,this.usesPrefixDiscriminator=e instanceof cn||e instanceof dn,this.defaultLayout=t,this.registry={};let i=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return i(e)},this.configGetSourceVariant=function(e){i=e.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;const n=this.getVariant(e,t);if(!n)throw new 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;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||t.property&&Object.prototype.hasOwnProperty.call(e,t.property)))return t}else for(const t in this.registry){const n=this.registry[t];if(n.property&&Object.prototype.hasOwnProperty.call(e,n.property))return n}throw new Error("unable to infer src variant")}decode(e,t=0){let n;const r=this.discriminator,o=r.decode(e,t),i=this.registry[o];if(void 0===i){const i=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=r.layout.span),n=this.makeDestinationObject(),n[r.property]=o,n[i.property]=i.decode(e,t+s)}else n=i.decode(e,t);return n}encode(e,t,n=0){const r=this.getSourceVariant(e);if(void 0===r){const r=this.discriminator,o=this.defaultLayout;let i=0;return this.usesPrefixDiscriminator&&(i=r.layout.span),r.encode(e[r.property],t,n),i+o.encode(e[o.property],t,n+i)}return r.encode(e,t,n)}addVariant(e,t,n){const r=new Cn(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]}}Yt.Union=Sn;class Cn extends rn{constructor(e,t,n,r){if(!(e instanceof Sn))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof n&&void 0===r&&(r=n,n=null),n){if(!(n instanceof rn))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=n.span&&n.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof r)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=n?n.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,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){const n=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw new 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]=1: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 new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,n);let o=r;if(this.layout&&(this.layout.encode(e[this.property],t,n+r),o+=this.layout.getSpan(t,n+r),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function On(e){return 0>e&&(e+=4294967296),e}Yt.VariantLayout=Cn;class _n extends rn{constructor(e,t,n){if(!(e instanceof cn||e instanceof dn))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===n&&(n=t,t=0),4<e.span)throw new 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=On(e),this},this._packedGetValue=function(){return r}}decode(e,t=0){const n=this.makeDestinationObject(),r=this.word.decode(e,t);this._packedSetValue(r);for(const t of this.fields)void 0!==t.property&&(n[t.property]=t.decode(e));return n}encode(e,t,n=0){const r=this.word.decode(t,n);this._packedSetValue(r);for(const t of this.fields)if(void 0!==t.property){const n=e[t.property];void 0!==n&&t.encode(n)}return this.word.encode(this._packedGetValue(),t,n)}addField(e,t){const n=new En(this,e,t);return this.fields.push(n),n}addBoolean(e){const t=new Bn(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}Yt.BitStructure=_n;class En{constructor(e,t,n){if(!(e instanceof _n))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const r=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>r)throw new Error("bits too long for span remainder ("+(r-o)+" of "+r+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=r-o-t),this.wordMask=On(this.valueMask<<this.start),this.property=n}decode(e,t){return On(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if("number"!=typeof e||!Number.isInteger(e)||e!==On(e&this.valueMask))throw new TypeError(on("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),n=On(e<<this.start);this.container._packedSetValue(On(t&~this.wordMask)|n)}}Yt.BitField=En;class Bn extends En{constructor(e,t){super(e,1,t)}decode(e,t){return!!super.decode(e,t)}encode(e){"boolean"==typeof e&&(e=+e),super.encode(e)}}Yt.Boolean=Bn;class Dn extends rn{constructor(e,t){if(!(e instanceof sn&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let n=-1;e instanceof sn||(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)),nn(e).slice(t,t+n)}encode(e,t,n){let r=this.length;if(this.length instanceof sn&&(r=e.length),!(e instanceof Uint8Array&&r===e.length))throw new TypeError(on("Blob.encode",this)+" requires (length "+r+") Uint8Array as src");if(n+r>t.length)throw new RangeError("encoding overruns Uint8Array");const o=nn(e);return nn(t).write(o.toString("hex"),n,r,"hex"),this.length instanceof sn&&this.length.encode(r,t,n),r}}Yt.Blob=Dn;class Rn extends rn{constructor(e){super(-1,e)}getSpan(e,t=0){tn(e);let n=t;for(;n<e.length&&0!==e[n];)n+=1;return 1+n-t}decode(e,t=0){const n=this.getSpan(e,t);return nn(e).slice(t,t+n-1).toString("utf-8")}encode(e,t,n=0){"string"!=typeof e&&(e=String(e));const r=en.Buffer.from(e,"utf8"),o=r.length;if(n+o>t.length)throw new RangeError("encoding overruns Buffer");const i=nn(t);return r.copy(i,n),i[n+o]=0,o+1}}Yt.CString=Rn;class Kn extends rn{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t=0){return tn(e),e.length-t}decode(e,t=0){const n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return nn(e).slice(t,t+n).toString("utf-8")}encode(e,t,n=0){"string"!=typeof e&&(e=String(e));const r=en.Buffer.from(e,"utf8"),o=r.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(n+o>t.length)throw new RangeError("encoding overruns Buffer");return r.copy(nn(t),n),o}}Yt.UTF8=Kn;class Ln extends rn{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,n){return 0}}Yt.Constant=Ln,Yt.greedy=(e,t)=>new an(e,t),Yt.offset=(e,t,n)=>new un(e,t,n);var Nn=Yt.u8=e=>new cn(1,e);Yt.u16=e=>new cn(2,e),Yt.u24=e=>new cn(3,e),Yt.u32=e=>new cn(4,e),Yt.u40=e=>new cn(5,e),Yt.u48=e=>new cn(6,e),Yt.nu64=e=>new gn(e),Yt.u16be=e=>new dn(2,e),Yt.u24be=e=>new dn(3,e),Yt.u32be=e=>new dn(4,e),Yt.u40be=e=>new dn(5,e),Yt.u48be=e=>new dn(6,e),Yt.nu64be=e=>new yn(e),Yt.s8=e=>new ln(1,e),Yt.s16=e=>new ln(2,e),Yt.s24=e=>new ln(3,e),Yt.s32=e=>new ln(4,e),Yt.s40=e=>new ln(5,e),Yt.s48=e=>new ln(6,e),Yt.ns64=e=>new bn(e),Yt.s16be=e=>new pn(2,e),Yt.s24be=e=>new pn(3,e),Yt.s32be=e=>new pn(4,e),Yt.s40be=e=>new pn(5,e),Yt.s48be=e=>new pn(6,e),Yt.ns64be=e=>new In(e),Yt.f32=e=>new wn(e),Yt.f32be=e=>new kn(e),Yt.f64=e=>new An(e),Yt.f64be=e=>new Mn(e);var Wn=Yt.struct=(e,t,n)=>new Pn(e,t,n);Yt.bits=(e,t,n)=>new _n(e,t,n),Yt.seq=(e,t,n)=>new vn(e,t,n),Yt.union=(e,t,n)=>new Sn(e,t,n),Yt.unionLayoutDiscriminator=(e,t)=>new Tn(e,t);var Un=Yt.blob=(e,t)=>new Dn(e,t);Yt.cstr=e=>new Rn(e),Yt.utf8=(e,t)=>new Kn(e,t),Yt.constant=(e,t)=>new Ln(e,t);const qn=i.struct([i.publicKey("updateAuthority"),i.publicKey("mint"),i.vecU8("name"),i.vecU8("symbol"),i.vecU8("uri"),i.vec(i.struct([i.vecU8("key"),i.vecU8("value")]),"additionalMetadata")]),Gn=Wn([Nn("version"),Nn("cmintDecompressed"),(()=>{const e=Un(32,"splMint"),{encode:t,decode:r}=(e=>({decode:e.decode.bind(e),encode:e.encode.bind(e)}))(e),o=e;return o.decode=(e,t)=>{const o=r(e,t);return new n.PublicKey(o)},o.encode=(e,n,r)=>{const o=e.toBuffer();return t(o,n,r)},o})()]),Vn=Gn.span;function Fn(e,t,n){return e===exports.ExtensionType.TokenMetadata?function(e,t){let n=t;n+=32,n+=32,n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n);const r=e.readUInt32LE(n);n+=4;for(let t=0;t<r;t++)n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n);return n-t}(t,n):t.length-n}function zn(e){const t=e instanceof o.Buffer?e:o.Buffer.from(e);let n=0;const i=r.MintLayout.decode(t.slice(n,n+r.MINT_SIZE));n+=r.MINT_SIZE;const s=Gn.decode(t.slice(n,n+Vn));n+=Vn;const a=1===t.readUInt8(n);n+=1;let u=null;if(a){const e=t.readUInt32LE(n);n+=4,u=[];for(let r=0;r<e;r++){const e=t.readUInt8(n);n+=1;const r=Fn(e,t,n),o=t.slice(n,n+r);n+=r,u.push({extensionType:e,data:o})}}return{base:{mintAuthority:1===i.mintAuthorityOption?i.mintAuthority:null,supply:i.supply,decimals:i.decimals,isInitialized:i.isInitialized,freezeAuthority:1===i.freezeAuthorityOption?i.freezeAuthority:null},mintContext:{version:s.version,cmintDecompressed:0!==s.cmintDecompressed,splMint:s.splMint},extensions:u}}var jn;function $n(e){try{const t=o.Buffer.from(e);if(t.length<80)return null;const n=qn.decode(t),r=n.updateAuthority.toBuffer().every((e=>0===e))?void 0:n.updateAuthority,i=o.Buffer.from(n.name).toString("utf-8"),s=o.Buffer.from(n.symbol).toString("utf-8"),a=o.Buffer.from(n.uri).toString("utf-8");let u;return n.additionalMetadata&&n.additionalMetadata.length>0&&(u=n.additionalMetadata.map((e=>({key:o.Buffer.from(e.key).toString("utf-8"),value:o.Buffer.from(e.value).toString("utf-8")})))),{updateAuthority:r,mint:n.mint,name:i,symbol:s,uri:a,additionalMetadata:u}}catch(e){return console.error("Failed to decode TokenMetadata:",e),null}}exports.ExtensionType=void 0,(jn=exports.ExtensionType||(exports.ExtensionType={}))[jn.TokenMetadata=19]="TokenMetadata";const Zn=$n;function Hn(e){if(!e)return null;const t=e.find((e=>e.extensionType===exports.ExtensionType.TokenMetadata));return t?Zn(t.data):null}async function Qn(e,n,i,s){var a;if(!s){const[o,s,a]=await Promise.allSettled([Qn(e,n,i,r.TOKEN_PROGRAM_ID),Qn(e,n,i,r.TOKEN_2022_PROGRAM_ID),Qn(e,n,i,t.CTOKEN_PROGRAM_ID)]);if("fulfilled"===o.status)return o.value;if("fulfilled"===s.status)return s.value;if("fulfilled"===a.status)return a.value;throw new Error(`Mint not found: ${n.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and CTOKEN_PROGRAM_ID.`)}if(s.equals(t.CTOKEN_PROGRAM_ID)){const r=t.getDefaultAddressTreeInfo().tree,i=t.deriveAddressV2(n.toBytes(),r,t.CTOKEN_PROGRAM_ID),u=await e.getCompressedAccount(t.bn(i.toBytes()));if(!(null===(a=null==u?void 0:u.data)||void 0===a?void 0:a.data))throw new Error(`Compressed mint not found for ${n.toString()}`);const c=zn(o.Buffer.from(u.data.data)),d={address:n,mintAuthority:c.base.mintAuthority,supply:c.base.supply,decimals:c.base.decimals,isInitialized:c.base.isInitialized,freezeAuthority:c.base.freezeAuthority,tlvData:o.Buffer.alloc(0)},l={treeInfo:u.treeInfo,hash:u.hash,leafIndex:u.leafIndex,proveByIndex:u.proveByIndex},p=Hn(c.extensions),m={mint:d,programId:s,merkleContext:l,mintContext:c.mintContext,tokenMetadata:p||void 0,extensions:c.extensions||void 0};if(s.equals(t.CTOKEN_PROGRAM_ID)){if(!m.merkleContext)throw new Error("Invalid compressed mint: merkleContext is required for CTOKEN_PROGRAM_ID");if(!m.mintContext)throw new Error("Invalid compressed mint: mintContext is required for CTOKEN_PROGRAM_ID")}return m}return{mint:await r.getMint(e,n,i,s),programId:s}}function Jn(e){if(!("publicKey"in e)||!("secretKey"in e))return 0;const t=e;return t.secretKey instanceof Uint8Array&&t.secretKey.length>0}function Xn(e){return Jn(e)?e.publicKey:e}async function Yn(e,o,i,s,a,u,c,d,l,p){const m=Xn(s),h=r.getAssociatedTokenAddressSync(i,m,a,d,l);return d.equals(t.CTOKEN_PROGRAM_ID)?async function(e,n,o,i,s,a,u,c=0,d=0){var l,p,m;const h=Xn(i);let f;Jn(i);let g=0;try{f=await Vt(e,s,h,o,a,t.CTOKEN_PROGRAM_ID,c,d),g=null!==(p=null===(l=f._sources)||void 0===l?void 0:l.some((e=>e.type===Kt.CTokenHot)))&&void 0!==p?p:0}catch(i){if(!(i instanceof r.TokenAccountNotFoundError||i instanceof r.TokenInvalidAccountOwnerError))throw i;await er(e,n,o,h,s,u),f=await Vt(e,s,h,o,a,t.CTOKEN_PROGRAM_ID,c,d),g=1}if(g||await er(e,n,o,h,s,u),Jn(i)){const r=null!==(m=f._sources)&&void 0!==m?m:[],l=r.some((e=>e.type===Kt.CTokenCold&&e.amount>BigInt(0))),p=c&&r.some((e=>(e.type===Kt.Spl||e.type===Kt.Token2022)&&e.amount>BigInt(0)));if(l||p){if(!(i.secretKey instanceof Uint8Array)||0===i.secretKey.length)throw new Error("Owner must be a valid Signer with secretKey to auto-load");await Jt(e,s,i,o,n,u,void 0,c),f=await Vt(e,s,h,o,a,t.CTOKEN_PROGRAM_ID,c,d)}}const y=f.parsed;if(!y.mint.equals(o))throw new r.TokenInvalidMintError;if(!y.owner.equals(h))throw new r.TokenInvalidOwnerError;return f}(e,o,i,s,h,u,c,p,a):async function(e,t,o,i,s,a,u,c,d){let l;try{l=await Gt(e,s,c,a)}catch(p){if(!(p instanceof r.TokenAccountNotFoundError||p instanceof r.TokenInvalidAccountOwnerError))throw p;try{const r=(new n.Transaction).add(st(t.publicKey,s,i,o,a,u));await n.sendAndConfirmTransaction(e,r,[t],d)}catch(e){}l=await Gt(e,s,c,a)}const p=l.parsed;if(!p.mint.equals(o))throw new r.TokenInvalidMintError;if(!p.owner.equals(i))throw new r.TokenInvalidOwnerError;return l}(e,o,i,m,h,d,l,u,c)}async function er(e,r,o,i,s,a){try{const u=at(r.publicKey,s,i,o,t.CTOKEN_PROGRAM_ID),{blockhash:c}=await e.getLatestBlockhash(),d=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),u],r,c,[]);await t.sendAndConfirmTx(e,d,a)}catch(e){}}i.struct([i.array(i.u8(),32,"a"),i.array(i.u8(),64,"b"),i.array(i.u8(),32,"c")]);const tr=i.struct([i.u16("rootIndex"),i.bool("proveByIndex"),i.u8("merkleTreePubkeyIndex"),i.u8("queuePubkeyIndex"),i.u32("leafIndex")]);async function nr(e,n,r,o,i){i=i||await me.getMintProgramId(r,e);const s=await me.createTokenPool({feePayer:n.publicKey,mint:r,tokenProgramId:i}),{blockhash:a}=await e.getLatestBlockhash(),u=t.buildAndSignTx([s],n,a);return await t.sendAndConfirmTx(e,u,o)}i.struct([tr.replicate("treeInfo"),i.option(i.array(i.u8(),32),"address"),i.option(i.u64(),"lamports"),i.u8("outputStateTreeIndex")]);const rr=nr;async function or(e,n,r,o,i,s){s=s||await me.getMintProgramId(r,e);const a=[],u=(await k(e,r)).slice(0,4),c=[];for(let e=0;e<u.length;e++)u[e].isInitialized||c.push(e);for(let e=0;e<o&&!(e>=c.length);e++)a.push(await me.addTokenPool({mint:r,feePayer:n.publicKey,tokenProgramId:s,poolIndex:c[e]}));const{blockhash:d}=await e.getLatestBlockhash(),l=t.buildAndSignTx(a,n,d);return await t.sendAndConfirmTx(e,l,i)}const ir=or;function sr(e){return!Array.isArray(e)}const ar=sr;exports.ADD_TOKEN_POOL_DISCRIMINATOR=f,exports.APPROVE_DISCRIMINATOR=m,exports.BATCH_COMPRESS_DISCRIMINATOR=d,exports.COMPRESSED_MINT_SEED=fe,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=p,exports.CPI_AUTHORITY_SEED=a,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=u,exports.CompressedTokenInstructionDataApproveLayout=ee,exports.CompressedTokenInstructionDataRevokeLayout=te,exports.CompressedTokenInstructionDataTransferLayout=N,exports.CompressedTokenProgram=me,exports.CpiContextLayout=L,exports.DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR=g,exports.DelegatedTransferLayout=K,exports.ERROR_NO_ACCOUNTS_FOUND=x,exports.IDL={version:"1.2.0",name:"light_compressed_token",instructions:[{name:"createTokenPool",docs:["This instruction creates a token pool for a given mint. Every spl mint","can have one token pool. When a token is compressed the tokens are","transferrred to the token pool, and their compressed equivalent is","minted into a Merkle tree."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[]},{name:"addTokenPool",docs:["This instruction creates an additional token pool for a given mint.","The maximum number of token pools per mint is 5."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"existingTokenPoolPda",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[{name:"tokenPoolIndex",type:"u8"}]},{name:"mintTo",docs:["Mints tokens from an spl token mint to a list of compressed accounts.","Minted tokens are transferred to a pool account owned by the compressed","token program. The instruction creates one compressed output account for","every amount and pubkey input pair. A constant amount of lamports can be","transferred to each output account to enable. A use case to add lamports","to a compressed token account is to prevent spam. This is the only way","to add lamports to a compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0,docs:["programs"]},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"merkleTree",isMut:1,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1}],args:[{name:"publicKeys",type:{vec:"publicKey"}},{name:"amounts",type:{vec:"u64"}},{name:"lamports",type:{option:"u64"}}]},{name:"compressSplTokenAccount",docs:["Compresses the balance of an spl token account sub an optional remaining","amount. This instruction does not close the spl token account. To close","the account bundle a close spl account instruction in your transaction."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"owner",type:"publicKey"},{name:"remainingAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]},{name:"transfer",docs:["Transfers compressed tokens from one account to another. All accounts","must be of the same mint. Additional spl tokens can be compressed or","decompressed. In one transaction only compression or decompression is","possible. Lamports can be transferred alongside tokens. If output token","accounts specify less lamports than inputs the remaining lamports are","transferred to an output compressed account. Signer must be owner or","delegate. If a delegated token account is transferred the delegate is","not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"approve",docs:["Delegates an amount to a delegate. A compressed token account is either","completely delegated or not. Prior delegates are not preserved. Cannot","be called by a delegate.","The instruction creates two output accounts:","1. one account with delegated amount","2. one account with remaining(change) amount"],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"revoke",docs:["Revokes a delegation. The instruction merges all inputs into one output","account. Cannot be called by a delegate. Delegates are not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"freeze",docs:["Freezes compressed token accounts. Inputs must not be frozen. Creates as","many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"thaw",docs:["Thaws frozen compressed token accounts. Inputs must be frozen. Creates","as many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"burn",docs:["Burns compressed tokens and spl tokens from the pool account. Delegates","can burn tokens. The output compressed token account remains delegated.","Creates one output compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"CompressedTokenInstructionDataTransfer"}},{name:"inputs2",type:{defined:"TokenData"}}]}],types:[{name:"AccountState",type:{kind:"enum",variants:[{name:"Initialized"},{name:"Frozen"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"CompressedTokenInstructionDataTransfer",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"delegatedTransfer",docs:["Is required if the signer is delegate,","-> delegate is authority account,","owner = Some(owner) is the owner of the token account."],type:{option:{defined:"DelegatedTransfer"}}},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"PackedTokenTransferOutputData"}}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"lamportsChangeAccountMerkleTreeIndex",type:{option:"u8"}}]}},{name:"CompressedTokenInstructionDataRevoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"outputAccountMerkleTreeIndex",type:"u8"}]}},{name:"CompressedTokenInstructionDataApprove",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"delegate",type:"publicKey"},{name:"delegatedAmount",type:"u64"},{name:"delegateMerkleTreeIndex",type:"u8"},{name:"changeAccountMerkleTreeIndex",type:"u8"},{name:"delegateLamports",type:{option:"u64"}}]}},{name:"DelegatedTransfer",docs:["Struct to provide the owner when the delegate is signer of the transaction."],type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"delegateChangeAccountIndex",docs:["Index of change compressed account in output compressed accounts. In","case that the delegate didn't spend the complete delegated compressed","account balance the change compressed account will be delegated to her","as well."],type:{option:"u8"}}]}},{name:"InputTokenDataWithContext",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"delegateIndex",type:{option:"u8"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",type:"u16"},{name:"lamports",type:{option:"u64"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{name:"PackedTokenTransferOutputData",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"amount",type:"u64"},{name:"lamports",type:{option:"u64"}},{name:"merkleTreeIndex",type:"u8"},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"TokenData",type:{kind:"struct",fields:[{name:"mint",docs:["The mint associated with this account"],type:"publicKey"},{name:"owner",docs:["The owner of this account."],type:"publicKey"},{name:"amount",docs:["The amount of tokens this account holds."],type:"u64"},{name:"delegate",docs:["If `delegate` is `Some` then `delegated_amount` represents","the amount authorized by the delegate"],type:{option:"publicKey"}},{name:"state",docs:["The account's state"],type:{defined:"AccountState"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"PublicKeyAmountMissmatch",msg:"public keys and amounts must be of same length"},{code:6001,name:"ComputeInputSumFailed",msg:"ComputeInputSumFailed"},{code:6002,name:"ComputeOutputSumFailed",msg:"ComputeOutputSumFailed"},{code:6003,name:"ComputeCompressSumFailed",msg:"ComputeCompressSumFailed"},{code:6004,name:"ComputeDecompressSumFailed",msg:"ComputeDecompressSumFailed"},{code:6005,name:"SumCheckFailed",msg:"SumCheckFailed"},{code:6006,name:"DecompressRecipientUndefinedForDecompress",msg:"DecompressRecipientUndefinedForDecompress"},{code:6007,name:"CompressedPdaUndefinedForDecompress",msg:"CompressedPdaUndefinedForDecompress"},{code:6008,name:"DeCompressAmountUndefinedForDecompress",msg:"DeCompressAmountUndefinedForDecompress"},{code:6009,name:"CompressedPdaUndefinedForCompress",msg:"CompressedPdaUndefinedForCompress"},{code:6010,name:"DeCompressAmountUndefinedForCompress",msg:"DeCompressAmountUndefinedForCompress"},{code:6011,name:"DelegateSignerCheckFailed",msg:"DelegateSignerCheckFailed"},{code:6012,name:"MintTooLarge",msg:"Minted amount greater than u64::MAX"},{code:6013,name:"SplTokenSupplyMismatch",msg:"SplTokenSupplyMismatch"},{code:6014,name:"HeapMemoryCheckFailed",msg:"HeapMemoryCheckFailed"},{code:6015,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6016,name:"ArithmeticUnderflow",msg:"ArithmeticUnderflow"},{code:6017,name:"HashToFieldError",msg:"HashToFieldError"},{code:6018,name:"InvalidAuthorityMint",msg:"Expected the authority to be also a mint authority"},{code:6019,name:"InvalidFreezeAuthority",msg:"Provided authority is not the freeze authority"},{code:6020,name:"InvalidDelegateIndex"},{code:6021,name:"TokenPoolPdaUndefined"},{code:6022,name:"IsTokenPoolPda",msg:"Compress or decompress recipient is the same account as the token pool pda."},{code:6023,name:"InvalidTokenPoolPda"},{code:6024,name:"NoInputTokenAccountsProvided"},{code:6025,name:"NoInputsProvided"},{code:6026,name:"MintHasNoFreezeAuthority"},{code:6027,name:"MintWithInvalidExtension"},{code:6028,name:"InsufficientTokenAccountBalance",msg:"The token account balance is less than the remaining amount."},{code:6029,name:"InvalidTokenPoolBump",msg:"Max number of token pools reached."},{code:6030,name:"FailedToDecompress"},{code:6031,name:"FailedToBurnSplTokensFromTokenPool"},{code:6032,name:"NoMatchingBumpFound"}]},exports.MINT_TO_DISCRIMINATOR=c,exports.POOL_SEED=s,exports.REVOKE_DISCRIMINATOR=h,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TRANSFER_DISCRIMINATOR=l,exports._getOrCreateAtaInterface=Yn,exports.addSplInterfaces=or,exports.addTokenPoolAccountsLayout=$,exports.addTokenPools=ir,exports.approve=async function(e,r,o,i,s,a,u){i=t.bn(i);const c=await e.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[d]=T(c.items,i),l=await e.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),p=await me.approve({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:l.rootIndices,recentValidityProof:l.compressedProof}),{blockhash:m}=await e.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),p],r,m,h);return t.sendAndConfirmTx(e,f,u)},exports.approveAccountsLayout=Q,exports.approveAndMintTo=async function(e,o,i,s,a,u,c,d,l){c=null!=c?c:t.selectStateTreeInfo(await e.getStateTreeInfos()),d=null!=d?d:v(await k(e,i));const p=await r.getOrCreateAssociatedTokenAccount(e,o,i,a.publicKey,void 0,void 0,l,d.tokenProgram),m=await me.approveAndMintTo({feePayer:o.publicKey,mint:i,authority:a.publicKey,authorityTokenAccount:p.address,amount:u,toPubkey:s,outputStateTreeInfo:c,tokenPoolInfo:d}),{blockhash:h}=await e.getLatestBlockhash(),f=t.dedupeSigner(o,[a]),g=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:15e4+2e4*t.toArray(u).length}),...m],o,h,f);return await t.sendAndConfirmTx(e,g,l)},exports.batchCompressLayout=U,exports.calculateCompressibleLoadComputeUnits=function(e,t){let n=5e4;return t&&(n+=1e5),n+=3e4*e,n},exports.checkMint=E,exports.checkSplInterfaceInfo=w,exports.checkTokenPoolInfo=function(e,t){return w(b(e),t)},exports.compress=async function(e,r,o,i,s,a,u,c,d,l){c=null!=c?c:t.selectStateTreeInfo(await e.getStateTreeInfos()),d=null!=d?d:v(await k(e,o));const p=await me.compress({payer:r.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:i,mint:o,outputStateTreeInfo:c,tokenPoolInfo:d}),m=await e.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:13e4+2e4*t.toArray(i).length}),p],r,m.blockhash,h);return await t.sendAndConfirmTx(e,f,l,m)},exports.compressSplTokenAccount=async function(e,r,o,i,s,a,u,c,d){u=null!=u?u:t.selectStateTreeInfo(await e.getStateTreeInfos()),c=null!=c?c:v(await k(e,o));const l=await me.compressSplTokenAccount({feePayer:r.publicKey,authority:i.publicKey,tokenAccount:s,mint:o,remainingAmount:a,outputStateTreeInfo:u,tokenPoolInfo:c}),p=await e.getLatestBlockhash(),m=t.dedupeSigner(r,[i]),h=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),l],r,p.blockhash,m);return await t.sendAndConfirmTx(e,h,d,p)},exports.compressSplTokenAccountInstructionDataLayout=q,exports.convertTokenDataToAccount=Nt,exports.createAssociatedCTokenAccountIdempotentInstruction=nt,exports.createAssociatedCTokenAccountInstruction=tt,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=at,exports.createAssociatedTokenAccountInterfaceInstruction=st,exports.createAtaInterface=async function(e,r,o,i,s=0,a,u=t.CTOKEN_PROGRAM_ID,c,d){const l=null!=c?c:rt(u),p=jt(o,i,s,u,l),m=st(r.publicKey,p,i,o,u,l,d);if(u.equals(t.CTOKEN_PROGRAM_ID)){const{blockhash:o}=await e.getLatestBlockhash(),i=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await t.sendAndConfirmTx(e,i,a)}else{const t=(new n.Transaction).add(m);await n.sendAndConfirmTransaction(e,t,[r],a)}return p},exports.createAtaInterfaceIdempotent=async function(e,r,o,i,s=0,a,u=t.CTOKEN_PROGRAM_ID,c,d){const l=null!=c?c:rt(u),p=jt(o,i,s,u,l),m=at(r.publicKey,p,i,o,u,l,d);if(u.equals(t.CTOKEN_PROGRAM_ID)){const{blockhash:o}=await e.getLatestBlockhash(),i=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await t.sendAndConfirmTx(e,i,a)}else{const t=(new n.Transaction).add(m);await n.sendAndConfirmTransaction(e,t,[r],a)}return p},exports.createAtaInterfaceIdempotentInstruction=ut,exports.createCTokenTransferInstruction=mt,exports.createCompressCtoken=function(e,t,n,r,o){return{mode:gt,amount:e,mint:t,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:0,bump:0,decimals:0}},exports.createDecompressInterfaceInstruction=Ct,exports.createDecompressOutputState=pe,exports.createDecompressSpl=function(e,t,n,r,o,i){return{mode:yt,amount:e,mint:t,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:o,bump:i,decimals:0}},exports.createLoadAccountsParams=async function(e,n,r,o=[],i=[],s){let a=null;const u=o.filter((e=>void 0!==e.info.loadContext));if(u.length>0){const n=u.map((e=>({hash:e.info.loadContext.hash,tree:e.info.loadContext.treeInfo.tree,queue:e.info.loadContext.treeInfo.queue}))),o=await e.getValidityProofV0(n,[]),i=u.map((e=>{if("cTokenData"===e.accountType){if(!e.tokenVariant)throw new Error('tokenVariant is required when accountType is "cTokenData"');return{key:"cTokenData",data:{variant:{[e.tokenVariant]:{}},tokenData:e.info.parsed},treeInfo:e.info.loadContext.treeInfo}}return{key:e.accountType,data:e.info.parsed,treeInfo:e.info.loadContext.treeInfo}})),s=u.map((e=>e.address)),c=u.map((e=>e.info.loadContext.treeInfo)),d=await t.packDecompressAccountsIdempotent(r,{compressedProof:o.compressedProof,treeInfos:c},i,s);a={proofOption:d.proofOption,compressedAccounts:d.compressedAccounts,systemAccountsOffset:d.systemAccountsOffset,remainingAccounts:d.remainingAccounts}}const c=[];for(const t of i){const r=await Qt(e,n,t,s);c.push(...r)}return{decompressParams:a,ataInstructions:c}},exports.createLoadAtaInstructions=Ht,exports.createLoadAtaInstructionsFromInterface=Qt,exports.createMint=Xt,exports.createMintInstruction=Ue,exports.createMintInterface=async function(e,o,i,s,a,u=n.Keypair.generate(),c,d=t.CTOKEN_PROGRAM_ID,l,p,m){if(d.equals(r.TOKEN_PROGRAM_ID)||d.equals(r.TOKEN_2022_PROGRAM_ID))return Xt(e,o,i,a,u,c,d,s);if(!("secretKey"in i))throw new Error("mintAuthority must be a Signer for compressed token mints");if(m&&!m.tree.equals(t.getDefaultAddressTreeInfo().tree))throw new Error(`addressTreeInfo ${null==m?void 0:m.tree.toString()} must be the default address tree info: ${t.getDefaultAddressTreeInfo().tree.toString()}`);const h=s&&"secretKey"in s?s.publicKey:s;m=null!=m?m:t.getBatchAddressTreeInfo(),p=null!=p?p:t.selectStateTreeInfo(await e.getStateTreeInfos());const f=he(u.publicKey,m),g=await e.getValidityProofV2([],[{address:Uint8Array.from(f),treeInfo:m}],t.DerivationMode.standard),y=Ue(u.publicKey,a,i.publicKey,h,o.publicKey,g,m,p,l),b=t.dedupeSigner(o,[u,i]),{blockhash:I}=await e.getLatestBlockhash(),w=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),y],o,I,b),k=await t.sendAndConfirmTx(e,w);return console.log("txId",k),{mint:ge(u.publicKey)[0],transactionSignature:k}},exports.createMintToCompressedInstruction=dt,exports.createMintToInstruction=ct,exports.createMintToInterfaceInstruction=lt,exports.createRemoveMetadataKeyInstruction=$e,exports.createSplInterface=nr,exports.createTokenMetadata=function(e,t,n,r,o=null){return{name:e,symbol:t,uri:n,updateAuthority:null!=r?r:null,additionalMetadata:null!=o?o:null}},exports.createTokenPool=rr,exports.createTokenPoolAccountsLayout=j,exports.createTokenProgramLookupTable=async function(e,n,r,o,i){const s=await e.getSlot("finalized"),{instructions:a,address:u}=await me.createTokenProgramLookupTable({payer:n.publicKey,authority:r.publicKey,mints:o,remainingAccounts:i,recentSlot:s}),c=t.dedupeSigner(n,[r]),d=[];for(const r of a){const o=await e.getLatestBlockhash(),i=t.buildAndSignTx([r],n,o.blockhash,c),s=await t.sendAndConfirmTx(e,i,{commitment:"finalized"},o);d.push(s)}return{txIds:d,address:u}},exports.createTransferInterfaceInstruction=ht,exports.createTransferOutputState=le,exports.createUpdateFreezeAuthorityInstruction=Ve,exports.createUpdateMetadataAuthorityInstruction=je,exports.createUpdateMetadataFieldInstruction=ze,exports.createUpdateMintAuthorityInstruction=Ge,exports.createWrapInstruction=$t,exports.decodeApproveInstructionData=function(e){const t=ee.decode(e.subarray(m.length));return Object.assign(Object.assign({},t),{proof:re(t.proof)?null:t.proof})},exports.decodeBatchCompressInstructionData=function(e){return U.decode(e.subarray(d.length+4))},exports.decodeCompressSplTokenAccountInstructionData=function(e){const t=q.decode(e.subarray(p.length));return{owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext}},exports.decodeMintToInstructionData=function(e){return W.decode(e.subarray(c.length))},exports.decodeRevokeInstructionData=function(e){const t=te.decode(e.subarray(h.length));return Object.assign(Object.assign({},t),{proof:re(t.proof)?null:t.proof})},exports.decodeTokenMetadata=$n,exports.decodeTransferInstructionData=function(e){return N.decode(e.slice(l.length+4))},exports.decompress=async function(e,r,o,i,s,a,u,c){i=t.bn(i);const d=await e.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[l]=S(d.items,i),p=await e.getValidityProofV0(l.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=P(u=null!=u?u:await k(e,o),i),h=await me.decompress({payer:r.publicKey,inputCompressedTokenAccounts:l,toAddress:a,amount:i,tokenPoolInfos:m,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:f}=await e.getLatestBlockhash(),g=t.dedupeSigner(r,[s]),y=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),h],r,f,g);return await t.sendAndConfirmTx(e,y,c)},exports.decompressDelegated=async function(e,r,o,i,s,a,u,c){i=t.bn(i);const d=await e.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),[l]=S(d.items,i),p=await e.getValidityProofV0(l.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=null!=u?u:P(await k(e,o),i),h=await me.decompress({payer:r.publicKey,inputCompressedTokenAccounts:l,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof,tokenPoolInfos:m}),{blockhash:f}=await e.getLatestBlockhash(),g=t.dedupeSigner(r,[s]),y=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),h],r,f,g);return t.sendAndConfirmTx(e,y,c)},exports.decompressInterface=async function(e,o,i,s,a,u,c,d,l){var p;const m=void 0!==d,h=(await e.getCompressedTokenAccountsByOwner(i.publicKey,{mint:s})).items;if(0===h.length)return null;const f=h.reduce(((e,t)=>e+BigInt(t.parsed.amount.toString())),BigInt(0)),g=a?BigInt(a.toString()):f;if(g>f)throw new Error(`Insufficient compressed balance. Requested: ${g}, Available: ${f}`);const y=[];let b=BigInt(0);for(const e of h){if(b>=g)break;y.push(e),b+=BigInt(e.parsed.amount.toString())}const I=await e.getValidityProofV0(y.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),w=null!=c?c:i.publicKey;let k;k=m?null!=u?u:await r.getAssociatedTokenAddress(s,w,0,d.tokenProgram):null!=u?u:jt(s,w);const A=[];await e.getAccountInfo(k)||(m?A.push(r.createAssociatedTokenAccountIdempotentInstruction(o.publicKey,k,w,s,d.tokenProgram)):A.push(at(o.publicKey,k,w,s,t.CTOKEN_PROGRAM_ID)));let M=5e4;null!==I.compressedProof&&(M+=1e5);for(const e of y)M+=null!==(p=e.compressedAccount.proveByIndex)&&void 0!==p&&p?1e4:3e4;m&&(M+=5e4),A.push(Ct(o.publicKey,y,k,g,I,d));const{blockhash:v}=await e.getLatestBlockhash(),P=t.dedupeSigner(o,[i]),x=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:M}),...A],o,v,P);return t.sendAndConfirmTx(e,x,l)},exports.deriveCMintAddress=he,exports.deriveSplInterfaceInfo=I,exports.deriveTokenPoolInfo=function(e,t,n=0){return y(I(e,t,n))},exports.deserializeMint=zn,exports.encodeApproveInstructionData=oe,exports.encodeBatchCompressInstructionData=V,exports.encodeCompressSplTokenAccountInstructionData=F,exports.encodeMintToInstructionData=G,exports.encodeRevokeInstructionData=ie,exports.encodeTokenMetadata=function(e){const t=o.Buffer.alloc(2e3),r=e.updateAuthority||new n.PublicKey(0),i=qn.encode({updateAuthority:r,mint:e.mint,name:o.Buffer.from(e.name),symbol:o.Buffer.from(e.symbol),uri:o.Buffer.from(e.uri),additionalMetadata:e.additionalMetadata?e.additionalMetadata.map((e=>({key:o.Buffer.from(e.key),value:o.Buffer.from(e.value)}))):[]},t);return t.subarray(0,i)},exports.encodeTransfer2InstructionData=Pt,exports.encodeTransferInstructionData=z,exports.extractTokenMetadata=Hn,exports.findMintAddress=ge,exports.freezeAccountsLayout=X,exports.getAccountInterface=Gt,exports.getAssociatedCTokenAddress=function(e,r){return n.PublicKey.findProgramAddressSync([e.toBuffer(),t.CTOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.CTOKEN_PROGRAM_ID)[0]},exports.getAssociatedCTokenAddressAndBump=function(e,r){return n.PublicKey.findProgramAddressSync([e.toBuffer(),t.CTOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.CTOKEN_PROGRAM_ID)},exports.getAssociatedTokenAddressInterface=jt,exports.getAtaInterface=Vt,exports.getAtaProgramId=rt,exports.getMintInterface=Qn,exports.getOrCreateAtaInterface=async function(e,n,r,o,i=0,s,a,u=t.CTOKEN_PROGRAM_ID,c=rt(u)){return Yn(e,n,r,o,i,s,a,u,c,0)},exports.getSplInterfaceInfos=k,exports.getTokenPoolInfos=async function(e,t,n){return(await k(e,t,n)).map(y)},exports.isSingleSplInterfaceInfo=sr,exports.isSingleTokenPoolInfo=ar,exports.loadAta=Jt,exports.mergeTokenAccounts=async function(e,r,o,i,s){const a=await e.getCompressedTokenAccountsByOwner(i.publicKey,{mint:o});if(0===a.items.length)throw new Error(`No compressed token accounts found for mint ${o.toBase58()}`);if(1===a.items.length)throw new Error("Only one token account exists, nothing to merge");const u=a.items.slice(0,4),c=await e.getValidityProof(u.map((e=>t.bn(e.compressedAccount.hash)))),d=await me.mergeTokenAccounts({payer:r.publicKey,owner:i.publicKey,inputCompressedTokenAccounts:u,mint:o,recentValidityProof:c.compressedProof,recentInputStateRootIndices:c.rootIndices}),l=[n.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...d],{blockhash:p}=await e.getLatestBlockhash(),m=t.dedupeSigner(r,[i]),h=t.buildAndSignTx(l,r,p,m);return t.sendAndConfirmTx(e,h,s)},exports.mintTo=async function(e,r,o,i,s,a,u,c){const d=await Qn(e,o,null==c?void 0:c.commitment,t.CTOKEN_PROGRAM_ID);if(!d.merkleContext)throw new Error("Mint does not have MerkleContext");let l;if(u){if(l=(await e.getStateTreeInfos()).find((e=>e.queue.equals(u)||e.tree.equals(u))),!l)throw new Error("Could not find TreeInfo for provided outputQueue")}else{const n=await e.getStateTreeInfos();l=t.selectStateTreeInfo(n)}const p=await e.getValidityProofV2([{hash:t.bn(d.merkleContext.hash),leafIndex:d.merkleContext.leafIndex,treeInfo:d.merkleContext.treeInfo,proveByIndex:d.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),m=ct(s.publicKey,r.publicKey,p,d.merkleContext,{supply:d.mint.supply,decimals:d.mint.decimals,mintAuthority:d.mint.mintAuthority,freezeAuthority:d.mint.freezeAuthority,splMint:d.mintContext.splMint,cmintDecompressed:d.mintContext.cmintDecompressed,version:d.mintContext.version,metadata:d.tokenMetadata?{updateAuthority:d.tokenMetadata.updateAuthority||null,name:d.tokenMetadata.name,symbol:d.tokenMetadata.symbol,uri:d.tokenMetadata.uri}:void 0},l,i,a),h=s.publicKey.equals(r.publicKey)?[]:[s],{blockhash:f}=await e.getLatestBlockhash(),g=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await t.sendAndConfirmTx(e,g,c)},exports.mintTo$1=async function(e,r,o,i,s,a,u,c,d){u=null!=u?u:t.selectStateTreeInfo(await e.getStateTreeInfos()),c=null!=c?c:v(await k(e,o));const l=await me.mintTo({feePayer:r.publicKey,mint:o,authority:s.publicKey,amount:a,toPubkey:i,outputStateTreeInfo:u,tokenPoolInfo:c}),{blockhash:p}=await e.getLatestBlockhash(),m=t.dedupeSigner(r,[s]),h=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,p,m);return t.sendAndConfirmTx(e,h,d)},exports.mintToAccountsLayout=Z,exports.mintToCompressed=async function(e,r,o,i,s,a,u=3,c){const d=await Qn(e,o,null==c?void 0:c.commitment,t.CTOKEN_PROGRAM_ID);if(!d.merkleContext)throw new Error("Mint does not have MerkleContext");if(!a){const n=await e.getStateTreeInfos();a=t.selectStateTreeInfo(n)}const l=await e.getValidityProofV2([{hash:t.bn(d.merkleContext.hash),leafIndex:d.merkleContext.leafIndex,treeInfo:d.merkleContext.treeInfo,proveByIndex:d.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),p=dt(i.publicKey,r.publicKey,l,d.merkleContext,{supply:d.mint.supply,decimals:d.mint.decimals,mintAuthority:d.mint.mintAuthority,freezeAuthority:d.mint.freezeAuthority,splMint:d.mintContext.splMint,cmintDecompressed:d.mintContext.cmintDecompressed,version:d.mintContext.version,metadata:d.tokenMetadata?{updateAuthority:d.tokenMetadata.updateAuthority||null,name:d.tokenMetadata.name,symbol:d.tokenMetadata.symbol,uri:d.tokenMetadata.uri}:void 0},s,a,u),m=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:h}=await e.getLatestBlockhash(),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),p],r,h,m);return await t.sendAndConfirmTx(e,f,c)},exports.mintToInterface=async function(e,r,o,i,s,a,u=[],c,d){const l=await Qn(e,o,null==c?void 0:c.commitment,d);let p;l.merkleContext&&(p=await e.getValidityProofV2([{hash:t.bn(l.merkleContext.hash),leafIndex:l.merkleContext.leafIndex,treeInfo:l.merkleContext.treeInfo,proveByIndex:l.merkleContext.proveByIndex}],[],t.DerivationMode.compressible));const m=s instanceof n.PublicKey?s:s.publicKey,h=u.map((e=>e.publicKey)),f=lt(l,i,m,r.publicKey,a,p,h),g=[];s instanceof n.PublicKey||s.publicKey.equals(r.publicKey)||g.push(s),g.push(...u);const{blockhash:y}=await e.getLatestBlockhash(),b=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),f],r,y,g);return await t.sendAndConfirmTx(e,b,c)},exports.mintToLayout=W,exports.packCompressedTokenAccounts=_,exports.parseCTokenCold=qt,exports.parseCTokenHot=Ut,exports.parseMaybeDelegatedTransfer=de,exports.parseTokenData=ce,exports.removeMetadataKey=async function(e,r,o,i,s,a=0,u=0,c){const d=await Qn(e,o,null==c?void 0:c.commitment,t.CTOKEN_PROGRAM_ID);if(!d.tokenMetadata||!d.merkleContext)throw new Error("Mint does not have TokenMetadata extension");const l=await e.getValidityProofV2([{hash:t.bn(d.merkleContext.hash),leafIndex:d.merkleContext.leafIndex,treeInfo:d.merkleContext.treeInfo,proveByIndex:d.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),p=$e(d,i.publicKey,r.publicKey,l,s,a,u),m=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:h}=await e.getLatestBlockhash(),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),p],r,h,m);return await t.sendAndConfirmTx(e,f,c)},exports.revoke=async function(e,r,o,i,s){const a=await e.getValidityProofV0(o.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue}))));!function(e,t){if(!e.publicKey.equals(t[0].parsed.owner))throw new Error(`Owner ${e.publicKey.toBase58()} does not match account ${t[0].parsed.owner.toBase58()}`)}(i,o),function(e){if(e.some((e=>null===e.parsed.delegate)))throw new Error("Account is not delegated")}(o);const u=await me.revoke({payer:r.publicKey,inputCompressedTokenAccounts:o,recentInputStateRootIndices:a.rootIndices,recentValidityProof:a.compressedProof}),{blockhash:c}=await e.getLatestBlockhash(),d=t.dedupeSigner(r,[i]),l=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),u],r,c,d);return t.sendAndConfirmTx(e,l,s)},exports.revokeAccountsLayout=J,exports.selectMinCompressedTokenAccountsForDecompression=function(e,t,n=4){const[r,o,i,s]=S(e,t,n);return{selectedAccounts:r,total:o,totalLamports:i,maxPossibleAmount:s}},exports.selectMinCompressedTokenAccountsForTransfer=S,exports.selectMinCompressedTokenAccountsForTransferOrPartial=C,exports.selectSmartCompressedTokenAccountsForTransfer=function(e,n,r=4){const[o,i,s,a]=O(e,n,r);if(i.lt(t.bn(n))){const i=e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw o.length>=r?new Error(`Account limit exceeded: max ${a.toString()} (${r} accounts) per transaction. Total balance: ${i.toString()} (${e.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance. Required: ${n.toString()}, available: ${i.toString()}.`)}if(0===o.length)throw new Error(x);return[o,i,s,a]},exports.selectSmartCompressedTokenAccountsForTransferOrPartial=O,exports.selectSplInterfaceInfo=v,exports.selectSplInterfaceInfosForDecompression=P,exports.selectTokenAccountsForApprove=T,exports.selectTokenPoolInfo=function(e){return y(v(e.map(b)))},exports.selectTokenPoolInfosForDecompression=function(e,t){return P(e.map(b),t).map(y)},exports.serializeMint=function(e){const t=[],i=o.Buffer.alloc(r.MINT_SIZE);r.MintLayout.encode({mintAuthorityOption:e.base.mintAuthority?1:0,mintAuthority:e.base.mintAuthority||new n.PublicKey(0),supply:e.base.supply,decimals:e.base.decimals,isInitialized:e.base.isInitialized,freezeAuthorityOption:e.base.freezeAuthority?1:0,freezeAuthority:e.base.freezeAuthority||new n.PublicKey(0)},i),t.push(i);const s=o.Buffer.alloc(Vn);if(Gn.encode({version:e.mintContext.version,cmintDecompressed:e.mintContext.cmintDecompressed?1:0,splMint:e.mintContext.splMint},s),t.push(s),e.extensions&&e.extensions.length>0){t.push(o.Buffer.from([1]));const n=o.Buffer.alloc(4);n.writeUInt32LE(e.extensions.length),t.push(n);for(const n of e.extensions)t.push(o.Buffer.from([n.extensionType])),t.push(o.Buffer.from(n.data))}else t.push(o.Buffer.from([0]));return o.Buffer.concat(t)},exports.sumUpTokenAmount=ae,exports.thawAccountsLayout=Y,exports.toAccountInfo=Wt,exports.toOffChainMetadataJson=function(e){const t={name:e.name,symbol:e.symbol};return void 0!==e.description&&(t.description=e.description),void 0!==e.image&&(t.image=e.image),void 0!==e.additionalMetadata&&e.additionalMetadata.length>0&&(t.additionalMetadata=e.additionalMetadata),t},exports.toTokenPoolInfo=y,exports.transfer=async function(e,r,o,i,s,a,u){i=t.bn(i);const c=await e.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[d]=S(c.items,i),l=await e.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),p=await me.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:l.rootIndices,recentValidityProof:l.compressedProof}),{blockhash:m}=await e.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),p],r,m,h);return t.sendAndConfirmTx(e,f,u)},exports.transferAccountsLayout=H,exports.transferDelegated=async function(e,r,o,i,s,a,u){i=t.bn(i);const c=await e.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),[d]=S(c.items,i),l=await e.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),p=await me.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:l.rootIndices,recentValidityProof:l.compressedProof}),{blockhash:m}=await e.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),p],r,m,h);return t.sendAndConfirmTx(e,f,u)},exports.transferInterface=async function(e,o,i,s,a,u,c,d=t.CTOKEN_PROGRAM_ID,l,p,m=0){const h=BigInt(c.toString()),{splInterfaceInfos:f}=null!=p?p:{},g=[];if(!d.equals(t.CTOKEN_PROGRAM_ID)){const c=r.getAssociatedTokenAddressSync(s,u.publicKey,0,d,rt(d));if(!i.equals(c))throw new Error(`Source mismatch. Expected ${c.toBase58()}, got ${i.toBase58()}`);g.push(ht(i,a,u.publicKey,h,[],d));const{blockhash:p}=await e.getLatestBlockhash(),m=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:1e4}),...g],o,p,[u]);return t.sendAndConfirmTx(e,m,l)}const y=jt(s,u.publicKey);if(!i.equals(y))throw new Error(`Source mismatch. Expected ${y.toBase58()}, got ${i.toBase58()}`);const b=jt(s,u.publicKey);let I,w;m&&(I=r.getAssociatedTokenAddressSync(s,u.publicKey,0,r.TOKEN_PROGRAM_ID,rt(r.TOKEN_PROGRAM_ID)),w=r.getAssociatedTokenAddressSync(s,u.publicKey,0,r.TOKEN_2022_PROGRAM_ID,rt(r.TOKEN_2022_PROGRAM_ID)));const A=[e.getAccountInfo(b),e.getCompressedTokenAccountsByOwner(u.publicKey,{mint:s})];m&&I&&w&&(A.push(e.getAccountInfo(I)),A.push(e.getAccountInfo(w)));const M=await Promise.all(A),v=M[0],P=M[1],x=m?M[2]:null,T=m?M[3]:null,S=P.items,C=v&&v.data.length>=72?v.data.readBigUInt64LE(64):BigInt(0),O=m&&x&&x.data.length>=72?x.data.readBigUInt64LE(64):BigInt(0),_=m&&T&&T.data.length>=72?T.data.readBigUInt64LE(64):BigInt(0),E=S.reduce(((e,t)=>e+BigInt(t.parsed.amount.toString())),BigInt(0)),B=C+O+_+E;if(B<h)throw new Error(`Insufficient balance. Required: ${h}, Available: ${B}`);let D=[];v||g.push(at(o.publicKey,b,u.publicKey,s,t.CTOKEN_PROGRAM_ID));const R=(O>BigInt(0)||_>BigInt(0)||E>BigInt(0)?null!=f?f:await k(e,s):[]).find((e=>e.isInitialized));if(m&&I&&O>BigInt(0)&&R&&g.push($t(I,b,u.publicKey,s,O,R,o.publicKey)),m&&w&&_>BigInt(0)&&R&&g.push($t(w,b,u.publicKey,s,_,R,o.publicKey)),E>BigInt(0)&&S.length>0){const t=await e.getValidityProofV0(S.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue}))));t.compressedProof,D=S,g.push(Ct(o.publicKey,S,b,E,t))}g.push(mt(i,a,u.publicKey,h));const K=function(e){if(e.length>0)for(const t of e)t.compressedAccount.proveByIndex;return 2e5}(D),{blockhash:L}=await e.getLatestBlockhash(),N=t.dedupeSigner(o,[u]),W=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:K}),...g],o,L,N);return t.sendAndConfirmTx(e,W,l)},exports.unpackMintData=function(e){const t=zn(e instanceof o.Buffer?e:o.Buffer.from(e)),n=Hn(t.extensions);return{mintContext:t.mintContext,tokenMetadata:n||void 0,extensions:t.extensions||void 0}},exports.unpackMintInterface=function(e,n,i=r.TOKEN_PROGRAM_ID){const s=n instanceof o.Buffer?n:n instanceof Uint8Array?o.Buffer.from(n):n.data;if(i.equals(t.CTOKEN_PROGRAM_ID)){const n=zn(s),r={address:e,mintAuthority:n.base.mintAuthority,supply:n.base.supply,decimals:n.base.decimals,isInitialized:n.base.isInitialized,freezeAuthority:n.base.freezeAuthority,tlvData:o.Buffer.alloc(0)},a=Hn(n.extensions),u={mint:r,programId:i,mintContext:n.mintContext,tokenMetadata:a||void 0,extensions:n.extensions||void 0};if(i.equals(t.CTOKEN_PROGRAM_ID)&&!u.mintContext)throw new Error("Invalid compressed mint: mintContext is required for CTOKEN_PROGRAM_ID");return u}const a=n;return{mint:r.unpackMint(e,a,i),programId:i}},exports.updateFreezeAuthority=async function(e,r,o,i,s,a){const u=await Qn(e,o,null==a?void 0:a.commitment,t.CTOKEN_PROGRAM_ID);if(!u.merkleContext)throw new Error("Mint does not have MerkleContext");const c=await e.getValidityProofV2([{hash:t.bn(u.merkleContext.hash),leafIndex:u.merkleContext.leafIndex,treeInfo:u.merkleContext.treeInfo,proveByIndex:u.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),d=Ve(u,i.publicKey,s,r.publicKey,c),l=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:p}=await e.getLatestBlockhash(),m=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),d],r,p,l);return await t.sendAndConfirmTx(e,m,a)},exports.updateMetadataAuthority=async function(e,r,o,i,s,a=0,u){const c=await Qn(e,o,null==u?void 0:u.commitment,t.CTOKEN_PROGRAM_ID);if(!c.tokenMetadata||!c.merkleContext)throw new Error("Mint does not have TokenMetadata extension");const d=await e.getValidityProofV2([{hash:t.bn(c.merkleContext.hash),leafIndex:c.merkleContext.leafIndex,treeInfo:c.merkleContext.treeInfo,proveByIndex:c.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),l=je(c,i.publicKey,s,r.publicKey,d,a),p=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:m}=await e.getLatestBlockhash(),h=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),l],r,m,p);return await t.sendAndConfirmTx(e,h,u)},exports.updateMetadataField=async function(e,r,o,i,s,a,u,c=0,d){const l=await Qn(e,o,null==d?void 0:d.commitment,t.CTOKEN_PROGRAM_ID);if(!l.tokenMetadata||!l.merkleContext)throw new Error("Mint does not have TokenMetadata extension");const p=await e.getValidityProofV2([{hash:t.bn(l.merkleContext.hash),leafIndex:l.merkleContext.leafIndex,treeInfo:l.merkleContext.treeInfo,proveByIndex:l.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),m=ze(l,i.publicKey,r.publicKey,p,s,a,u,c),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await e.getLatestBlockhash(),g=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await t.sendAndConfirmTx(e,g,d)},exports.updateMintAuthority=async function(e,r,o,i,s,a){const u=await Qn(e,o,null==a?void 0:a.commitment,t.CTOKEN_PROGRAM_ID);if(!u.merkleContext)throw new Error("Mint does not have MerkleContext");const c=await e.getValidityProofV2([{hash:t.bn(u.merkleContext.hash),leafIndex:u.merkleContext.leafIndex,treeInfo:u.merkleContext.treeInfo,proveByIndex:u.merkleContext.proveByIndex}],[],t.DerivationMode.compressible),d=Ge(u,i.publicKey,s,r.publicKey,c),l=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:p}=await e.getLatestBlockhash(),m=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),d],r,p,l);return await t.sendAndConfirmTx(e,m,a)},exports.validateSameTokenOwner=ue,exports.wrap=async function(e,r,o,i,s,a,u,c,d){let l=c;if(!l&&(l=(await k(e,a)).find((e=>e.isInitialized)),!l))throw new Error(`No initialized SPL interface found for mint: ${a.toBase58()}. Please create an SPL interface via createSplInterface().`);const p=$t(o,i,s.publicKey,a,u,l,r.publicKey),{blockhash:m}=await e.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([n.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),p],r,m,h);return await t.sendAndConfirmTx(e,f,d)};
|
|
2
|
+
//# sourceMappingURL=types-BPweZlnn.cjs.map
|