@lightprotocol/compressed-token 0.22.1-alpha.0 → 0.22.1-alpha.3
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-DZs1jl_2.cjs +2 -0
- package/dist/cjs/browser/types-DZs1jl_2.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-CxnYquyR.cjs +2 -0
- package/dist/cjs/node/types-CxnYquyR.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 +2 -0
- package/dist/es/browser/index.js.map +1 -0
- package/dist/es/browser/types-Drp6Yu8A.js +2 -0
- package/dist/es/browser/types-Drp6Yu8A.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 +2212 -121
- package/dist/types/unified/index.d.ts +5392 -0
- package/package.json +57 -13
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("@lightprotocol/stateless.js"),t=require("../types-DZs1jl_2.cjs"),o=require("@solana/web3.js"),r=require("@solana/spl-token");function n(r,n,s,a,c,p,i=s){const u={withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:0,cpiContext:null,compressions:[t.createCompressCtoken(c,0,2,1,6),t.createDecompressSpl(c,0,3,4,p.poolIndex,p.bump)],proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null},I=t.encodeTransfer2InstructionData(u),d=[{pubkey:t.CompressedTokenProgram.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:i,isSigner:1,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:s,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:p.splInterfacePda,isSigner:0,isWritable:1},{pubkey:p.tokenProgram,isSigner:0,isWritable:0},{pubkey:e.CTOKEN_PROGRAM_ID,isSigner:0,isWritable:0}];return new o.TransactionInstruction({programId:t.CompressedTokenProgram.programId,keys:d,data:I})}require("@coral-xyz/borsh"),exports.ADD_TOKEN_POOL_DISCRIMINATOR=t.ADD_TOKEN_POOL_DISCRIMINATOR,exports.APPROVE_DISCRIMINATOR=t.APPROVE_DISCRIMINATOR,Object.defineProperty(exports,"Action",{enumerable:1,get:function(){return t.Action}}),exports.BATCH_COMPRESS_DISCRIMINATOR=t.BATCH_COMPRESS_DISCRIMINATOR,exports.COMPRESSED_MINT_SEED=t.COMPRESSED_MINT_SEED,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=t.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR,exports.CPI_AUTHORITY_SEED=t.CPI_AUTHORITY_SEED,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=t.CREATE_TOKEN_POOL_DISCRIMINATOR,exports.CompressedTokenInstructionDataApproveLayout=t.CompressedTokenInstructionDataApproveLayout,exports.CompressedTokenInstructionDataRevokeLayout=t.CompressedTokenInstructionDataRevokeLayout,exports.CompressedTokenInstructionDataTransferLayout=t.CompressedTokenInstructionDataTransferLayout,exports.CompressedTokenProgram=t.CompressedTokenProgram,exports.CpiContextLayout=t.CpiContextLayout,exports.DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR=t.DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR,exports.DelegatedTransferLayout=t.DelegatedTransferLayout,exports.ERROR_NO_ACCOUNTS_FOUND=t.ERROR_NO_ACCOUNTS_FOUND,Object.defineProperty(exports,"ExtensionType",{enumerable:1,get:function(){return t.ExtensionType}}),exports.IDL=t.IDL,exports.MINT_TO_DISCRIMINATOR=t.MINT_TO_DISCRIMINATOR,exports.POOL_SEED=t.POOL_SEED,exports.REVOKE_DISCRIMINATOR=t.REVOKE_DISCRIMINATOR,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=t.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE,exports.TRANSFER_DISCRIMINATOR=t.TRANSFER_DISCRIMINATOR,Object.defineProperty(exports,"TokenDataVersion",{enumerable:1,get:function(){return t.TokenDataVersion}}),exports.addSplInterfaces=t.addSplInterfaces,exports.addTokenPoolAccountsLayout=t.addTokenPoolAccountsLayout,exports.addTokenPools=t.addTokenPools,exports.approve=t.approve,exports.approveAccountsLayout=t.approveAccountsLayout,exports.approveAndMintTo=t.approveAndMintTo,exports.batchCompressLayout=t.batchCompressLayout,exports.calculateCompressibleLoadComputeUnits=t.calculateCompressibleLoadComputeUnits,exports.checkMint=t.checkMint,exports.checkSplInterfaceInfo=t.checkSplInterfaceInfo,exports.checkTokenPoolInfo=t.checkTokenPoolInfo,exports.compress=t.compress,exports.compressSplTokenAccount=t.compressSplTokenAccount,exports.compressSplTokenAccountInstructionDataLayout=t.compressSplTokenAccountInstructionDataLayout,exports.convertTokenDataToAccount=t.convertTokenDataToAccount,exports.createAssociatedCTokenAccountIdempotentInstruction=t.createAssociatedCTokenAccountIdempotentInstruction,exports.createAssociatedCTokenAccountInstruction=t.createAssociatedCTokenAccountInstruction,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=t.createAssociatedTokenAccountInterfaceIdempotentInstruction,exports.createAssociatedTokenAccountInterfaceInstruction=t.createAssociatedTokenAccountInterfaceInstruction,exports.createAtaInterface=t.createAtaInterface,exports.createAtaInterfaceIdempotent=t.createAtaInterfaceIdempotent,exports.createAtaInterfaceIdempotentInstruction=t.createAtaInterfaceIdempotentInstruction,exports.createCTokenTransferInstruction=t.createCTokenTransferInstruction,exports.createDecompressInterfaceInstruction=t.createDecompressInterfaceInstruction,exports.createDecompressOutputState=t.createDecompressOutputState,exports.createLoadAccountsParams=t.createLoadAccountsParams,exports.createLoadAtaInstructionsFromInterface=t.createLoadAtaInstructionsFromInterface,exports.createMint=t.createMint,exports.createMintInstruction=t.createMintInstruction,exports.createMintInterface=t.createMintInterface,exports.createMintToCompressedInstruction=t.createMintToCompressedInstruction,exports.createMintToInstruction=t.createMintToInstruction,exports.createMintToInterfaceInstruction=t.createMintToInterfaceInstruction,exports.createRemoveMetadataKeyInstruction=t.createRemoveMetadataKeyInstruction,exports.createSplInterface=t.createSplInterface,exports.createTokenMetadata=t.createTokenMetadata,exports.createTokenPool=t.createTokenPool,exports.createTokenPoolAccountsLayout=t.createTokenPoolAccountsLayout,exports.createTokenProgramLookupTable=t.createTokenProgramLookupTable,exports.createTransferInterfaceInstruction=t.createTransferInterfaceInstruction,exports.createTransferOutputState=t.createTransferOutputState,exports.createUpdateFreezeAuthorityInstruction=t.createUpdateFreezeAuthorityInstruction,exports.createUpdateMetadataAuthorityInstruction=t.createUpdateMetadataAuthorityInstruction,exports.createUpdateMetadataFieldInstruction=t.createUpdateMetadataFieldInstruction,exports.createUpdateMintAuthorityInstruction=t.createUpdateMintAuthorityInstruction,exports.createWrapInstruction=t.createWrapInstruction,exports.decodeApproveInstructionData=t.decodeApproveInstructionData,exports.decodeBatchCompressInstructionData=t.decodeBatchCompressInstructionData,exports.decodeCompressSplTokenAccountInstructionData=t.decodeCompressSplTokenAccountInstructionData,exports.decodeMintToInstructionData=t.decodeMintToInstructionData,exports.decodeRevokeInstructionData=t.decodeRevokeInstructionData,exports.decodeTokenMetadata=t.decodeTokenMetadata,exports.decodeTransferInstructionData=t.decodeTransferInstructionData,exports.decompress=t.decompress,exports.decompressDelegated=t.decompressDelegated,exports.decompressInterface=t.decompressInterface,exports.deriveCMintAddress=t.deriveCMintAddress,exports.deriveSplInterfaceInfo=t.deriveSplInterfaceInfo,exports.deriveTokenPoolInfo=t.deriveTokenPoolInfo,exports.deserializeMint=t.deserializeMint,exports.encodeApproveInstructionData=t.encodeApproveInstructionData,exports.encodeBatchCompressInstructionData=t.encodeBatchCompressInstructionData,exports.encodeCompressSplTokenAccountInstructionData=t.encodeCompressSplTokenAccountInstructionData,exports.encodeMintToInstructionData=t.encodeMintToInstructionData,exports.encodeRevokeInstructionData=t.encodeRevokeInstructionData,exports.encodeTokenMetadata=t.encodeTokenMetadata,exports.encodeTransferInstructionData=t.encodeTransferInstructionData,exports.extractTokenMetadata=t.extractTokenMetadata,exports.findMintAddress=t.findMintAddress,exports.freezeAccountsLayout=t.freezeAccountsLayout,exports.getAccountInterface=t.getAccountInterface,exports.getAssociatedCTokenAddress=t.getAssociatedCTokenAddress,exports.getAssociatedCTokenAddressAndBump=t.getAssociatedCTokenAddressAndBump,exports.getMintInterface=t.getMintInterface,exports.getSplInterfaceInfos=t.getSplInterfaceInfos,exports.getTokenPoolInfos=t.getTokenPoolInfos,exports.isSingleSplInterfaceInfo=t.isSingleSplInterfaceInfo,exports.isSingleTokenPoolInfo=t.isSingleTokenPoolInfo,exports.mergeTokenAccounts=t.mergeTokenAccounts,exports.mintTo=t.mintTo$1,exports.mintToAccountsLayout=t.mintToAccountsLayout,exports.mintToCToken=t.mintTo,exports.mintToCompressed=t.mintToCompressed,exports.mintToInterface=t.mintToInterface,exports.mintToLayout=t.mintToLayout,exports.packCompressedTokenAccounts=t.packCompressedTokenAccounts,exports.parseCTokenCold=t.parseCTokenCold,exports.parseCTokenHot=t.parseCTokenHot,exports.parseMaybeDelegatedTransfer=t.parseMaybeDelegatedTransfer,exports.parseTokenData=t.parseTokenData,exports.removeMetadataKey=t.removeMetadataKey,exports.revoke=t.revoke,exports.revokeAccountsLayout=t.revokeAccountsLayout,exports.selectMinCompressedTokenAccountsForDecompression=t.selectMinCompressedTokenAccountsForDecompression,exports.selectMinCompressedTokenAccountsForTransfer=t.selectMinCompressedTokenAccountsForTransfer,exports.selectMinCompressedTokenAccountsForTransferOrPartial=t.selectMinCompressedTokenAccountsForTransferOrPartial,exports.selectSmartCompressedTokenAccountsForTransfer=t.selectSmartCompressedTokenAccountsForTransfer,exports.selectSmartCompressedTokenAccountsForTransferOrPartial=t.selectSmartCompressedTokenAccountsForTransferOrPartial,exports.selectSplInterfaceInfo=t.selectSplInterfaceInfo,exports.selectSplInterfaceInfosForDecompression=t.selectSplInterfaceInfosForDecompression,exports.selectTokenAccountsForApprove=t.selectTokenAccountsForApprove,exports.selectTokenPoolInfo=t.selectTokenPoolInfo,exports.selectTokenPoolInfosForDecompression=t.selectTokenPoolInfosForDecompression,exports.serializeMint=t.serializeMint,exports.sumUpTokenAmount=t.sumUpTokenAmount,exports.thawAccountsLayout=t.thawAccountsLayout,exports.toAccountInfo=t.toAccountInfo,exports.toOffChainMetadataJson=t.toOffChainMetadataJson,exports.toTokenPoolInfo=t.toTokenPoolInfo,exports.transfer=t.transfer,exports.transferAccountsLayout=t.transferAccountsLayout,exports.transferDelegated=t.transferDelegated,exports.unpackMintData=t.unpackMintData,exports.unpackMintInterface=t.unpackMintInterface,exports.updateFreezeAuthority=t.updateFreezeAuthority,exports.updateMetadataAuthority=t.updateMetadataAuthority,exports.updateMetadataField=t.updateMetadataField,exports.updateMintAuthority=t.updateMintAuthority,exports.validateSameTokenOwner=t.validateSameTokenOwner,exports.wrap=t.wrap,Object.defineProperty(exports,"AccountState",{enumerable:1,get:function(){return r.AccountState}}),exports.createLoadAtaInstructions=async function(e,o,r,n,s,a){return t.createLoadAtaInstructions(e,o,r,n,s,a,1)},exports.createUnwrapInstruction=n,exports.getAssociatedTokenAddressInterface=function(o,r,n=0,s=e.CTOKEN_PROGRAM_ID,a){if(!s.equals(e.CTOKEN_PROGRAM_ID))throw new Error("Please derive the unified ATA from the c-token program; balances across SPL, T22, and c-token are unified under the canonical c-token ATA.");return t.getAssociatedTokenAddressInterface(o,r,n,s,a)},exports.getAtaInterface=async function(e,o,r,n,s,a){return t.getAtaInterface(e,o,r,n,s,a,1)},exports.getOrCreateAtaInterface=async function(o,r,n,s,a=0,c,p){return t._getOrCreateAtaInterface(o,r,n,s,a,c,p,e.CTOKEN_PROGRAM_ID,t.getAtaProgramId(e.CTOKEN_PROGRAM_ID),1)},exports.loadAta=async function(e,o,r,n,s,a,c){return t.loadAta(e,o,r,n,s,a,c,1)},exports.transferInterface=async function(o,r,n,s,a,c,p,i=e.CTOKEN_PROGRAM_ID,u,I){return t.transferInterface(o,r,n,s,a,c,p,i,u,I,1)},exports.unwrap=async function(r,s,a,c,p,i,u,I){let d=u;if(!d&&(d=(await t.getSplInterfaceInfos(r,p)).find((e=>e.isInitialized)),!d))throw new Error(`No initialized SPL interface found for mint: ${p.toBase58()}. Please create an SPL interface via createSplInterface().`);if(!await r.getAccountInfo(a))throw new Error(`Destination account does not exist: ${a.toBase58()}. Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`);const T=t.getAssociatedTokenAddressInterface(p,c.publicKey);await t.loadAta(r,T,c,p,s,I);const A=await r.getAccountInfo(T);if(!A)throw new Error("No c-token ATA found after loading");const x=A.data.readBigUInt64LE(64);if(x===BigInt(0))throw new Error("No c-token balance to unwrap");const f=i?BigInt(i.toString()):x;if(f>x)throw new Error(`Insufficient c-token balance. Requested: ${f}, Available: ${x}`);const l=n(T,a,c.publicKey,p,f,d,s.publicKey),{blockhash:k}=await r.getLatestBlockhash(),m=e.dedupeSigner(s,[c]),C=e.buildAndSignTx([o.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),l],s,k,m);return await e.sendAndConfirmTx(r,C,I)};
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../../src/v3/instructions/unwrap.ts","../../../../../../src/v3/unified/index.ts","../../../../../../src/v3/actions/unwrap.ts"],"sourcesContent":["import { PublicKey, TransactionInstruction } from '@solana/web3.js';\nimport { CTOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';\nimport { CompressedTokenProgram } from '../../program';\nimport { SplInterfaceInfo } from '../../utils/get-token-pool-infos';\nimport {\n encodeTransfer2InstructionData,\n createCompressCtoken,\n createDecompressSpl,\n Transfer2InstructionData,\n Compression,\n} from '../layout/layout-transfer2';\n\n/**\n * Create an unwrap instruction that moves tokens from a c-token account to an\n * SPL/T22 account.\n *\n * @param source Source c-token account\n * @param destination Destination SPL/T22 token account\n * @param owner Owner of the source account (signer)\n * @param mint Mint address\n * @param amount Amount to unwrap,\n * @param splInterfaceInfo SPL interface info for the decompression\n * @param payer Fee payer (defaults to owner if not provided)\n * @returns TransactionInstruction to unwrap tokens\n */\nexport function createUnwrapInstruction(\n source: PublicKey,\n destination: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n amount: bigint,\n splInterfaceInfo: SplInterfaceInfo,\n payer: PublicKey = owner,\n): TransactionInstruction {\n const MINT_INDEX = 0;\n const OWNER_INDEX = 1;\n const SOURCE_INDEX = 2;\n const DESTINATION_INDEX = 3;\n const POOL_INDEX = 4;\n const _SPL_TOKEN_PROGRAM_INDEX = 5;\n const CTOKEN_PROGRAM_INDEX = 6;\n\n // Unwrap flow: compress from c-token, decompress to SPL\n const compressions: Compression[] = [\n createCompressCtoken(\n amount,\n MINT_INDEX,\n SOURCE_INDEX,\n OWNER_INDEX,\n CTOKEN_PROGRAM_INDEX,\n ),\n createDecompressSpl(\n amount,\n MINT_INDEX,\n DESTINATION_INDEX,\n POOL_INDEX,\n splInterfaceInfo.poolIndex,\n splInterfaceInfo.bump,\n ),\n ];\n\n const instructionData: Transfer2InstructionData = {\n withTransactionHash: false,\n withLamportsChangeAccountMerkleTreeIndex: false,\n lamportsChangeAccountMerkleTreeIndex: 0,\n lamportsChangeAccountOwnerIndex: 0,\n outputQueue: 0,\n maxTopUp: 0,\n cpiContext: null,\n compressions,\n proof: null,\n inTokenData: [],\n outTokenData: [],\n inLamports: null,\n outLamports: null,\n inTlv: null,\n outTlv: null,\n };\n\n const data = encodeTransfer2InstructionData(instructionData);\n\n // Account order matches wrap instruction for consistency\n const keys = [\n {\n pubkey: CompressedTokenProgram.deriveCpiAuthorityPda,\n isSigner: false,\n isWritable: false,\n },\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: mint, isSigner: false, isWritable: false },\n { pubkey: owner, isSigner: true, isWritable: false },\n { pubkey: source, isSigner: false, isWritable: true },\n { pubkey: destination, isSigner: false, isWritable: true },\n {\n pubkey: splInterfaceInfo.splInterfacePda,\n isSigner: false,\n isWritable: true,\n },\n {\n pubkey: splInterfaceInfo.tokenProgram,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: CTOKEN_PROGRAM_ID,\n isSigner: false,\n isWritable: false,\n },\n ];\n\n return new TransactionInstruction({\n programId: CompressedTokenProgram.programId,\n keys,\n data,\n });\n}\n","/**\n * Exports for @lightprotocol/compressed-token/unified\n *\n * Import from `/unified` to get a single unified ATA for SPL/T22 and c-token\n * mints.\n */\nimport { PublicKey, Signer, ConfirmOptions, Commitment } from '@solana/web3.js';\nimport { Rpc, CTOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';\nimport BN from 'bn.js';\n\nimport {\n getAtaInterface as _getAtaInterface,\n AccountInterface,\n} from '../get-account-interface';\nimport { getAssociatedTokenAddressInterface as _getAssociatedTokenAddressInterface } from '../get-associated-token-address-interface';\nimport {\n createLoadAtaInstructions as _createLoadAtaInstructions,\n loadAta as _loadAta,\n} from '../actions/load-ata';\nimport { transferInterface as _transferInterface } from '../actions/transfer-interface';\nimport { _getOrCreateAtaInterface } from '../actions/get-or-create-ata-interface';\nimport { getAtaProgramId } from '../ata-utils';\nimport { InterfaceOptions } from '..';\n\n/**\n * Get associated token account with unified balance\n *\n * @param rpc RPC connection\n * @param ata Associated token address\n * @param owner Owner public key\n * @param mint Mint public key\n * @param commitment Optional commitment level\n * @param programId Optional program ID (omit for unified behavior)\n * @returns AccountInterface with aggregated balance from all sources\n */\nexport async function getAtaInterface(\n rpc: Rpc,\n ata: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n commitment?: Commitment,\n programId?: PublicKey,\n): Promise<AccountInterface> {\n return _getAtaInterface(rpc, ata, owner, mint, commitment, programId, true);\n}\n\n/**\n * Derive the canonical token ATA for SPL/T22/c-token in the unified path.\n *\n * Enforces CTOKEN_PROGRAM_ID.\n *\n * @param mint Mint public key\n * @param owner Owner public key\n * @param allowOwnerOffCurve Allow owner to be a PDA. Default false.\n * @param programId Token program ID. Default c-token.\n * @param associatedTokenProgramId Associated token program ID. Default\n * auto-detected.\n * @returns Associated token address.\n */\nexport function getAssociatedTokenAddressInterface(\n mint: PublicKey,\n owner: PublicKey,\n allowOwnerOffCurve = false,\n programId: PublicKey = CTOKEN_PROGRAM_ID,\n associatedTokenProgramId?: PublicKey,\n): PublicKey {\n if (!programId.equals(CTOKEN_PROGRAM_ID)) {\n throw new Error(\n 'Please derive the unified ATA from the c-token program; balances across SPL, T22, and c-token are unified under the canonical c-token ATA.',\n );\n }\n\n return _getAssociatedTokenAddressInterface(\n mint,\n owner,\n allowOwnerOffCurve,\n programId,\n associatedTokenProgramId,\n );\n}\n\n/**\n * Create instructions to load ALL token balances into a c-token ATA.\n *\n * @param rpc RPC connection\n * @param ata Associated token address\n * @param owner Owner public key\n * @param mint Mint public key\n * @param payer Fee payer (defaults to owner)\n * @param options Optional interface options\n * @returns Array of instructions (empty if nothing to load)\n */\nexport async function createLoadAtaInstructions(\n rpc: Rpc,\n ata: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n payer?: PublicKey,\n options?: InterfaceOptions,\n) {\n return _createLoadAtaInstructions(\n rpc,\n ata,\n owner,\n mint,\n payer,\n options,\n true,\n );\n}\n\n/**\n * Load all token balances into the c-token ATA.\n *\n * Wraps SPL/Token-2022 balances and decompresses compressed c-tokens\n * into the on-chain c-token ATA. Idempotent: returns null if nothing to load.\n *\n * @param rpc RPC connection\n * @param ata Associated token address (c-token)\n * @param owner Owner of the tokens (signer)\n * @param mint Mint public key\n * @param payer Fee payer (signer, defaults to owner)\n * @param confirmOptions Optional confirm options\n * @param interfaceOptions Optional interface options\n * @returns Transaction signature, or null if nothing to load\n */\nexport async function loadAta(\n rpc: Rpc,\n ata: PublicKey,\n owner: Signer,\n mint: PublicKey,\n payer?: Signer,\n confirmOptions?: ConfirmOptions,\n interfaceOptions?: InterfaceOptions,\n) {\n return _loadAta(\n rpc,\n ata,\n owner,\n mint,\n payer,\n confirmOptions,\n interfaceOptions,\n true,\n );\n}\n\n/**\n * Transfer tokens using the unified ata interface.\n *\n * Matches SPL Token's transferChecked signature order. Destination must exist.\n *\n * @param rpc RPC connection\n * @param payer Fee payer (signer)\n * @param source Source c-token ATA address\n * @param mint Mint address\n * @param destination Destination c-token ATA address (must exist)\n * @param owner Source owner (signer)\n * @param amount Amount to transfer\n * @param programId Token program ID (default: CTOKEN_PROGRAM_ID)\n * @param confirmOptions Optional confirm options\n * @param options Optional interface options\n * @returns Transaction signature\n */\nexport async function transferInterface(\n rpc: Rpc,\n payer: Signer,\n source: PublicKey,\n mint: PublicKey,\n destination: PublicKey,\n owner: Signer,\n amount: number | bigint | BN,\n programId: PublicKey = CTOKEN_PROGRAM_ID,\n confirmOptions?: ConfirmOptions,\n options?: InterfaceOptions,\n) {\n return _transferInterface(\n rpc,\n payer,\n source,\n mint,\n destination,\n owner,\n amount,\n programId,\n confirmOptions,\n options,\n true,\n );\n}\n\n/**\n * Get or create c-token ATA with unified balance detection and auto-loading.\n *\n * Enforces CTOKEN_PROGRAM_ID. Aggregates balances from:\n * - c-token hot (on-chain) account\n * - c-token cold (compressed) accounts\n * - SPL token accounts (for unified wrapping)\n * - Token-2022 accounts (for unified wrapping)\n *\n * When owner is a Signer:\n * - Creates hot ATA if it doesn't exist\n * - Loads cold (compressed) tokens into hot ATA\n * - Wraps SPL/T22 tokens into c-token ATA\n * - Returns account with all tokens ready to use\n *\n * When owner is a PublicKey:\n * - Creates hot ATA if it doesn't exist\n * - Returns aggregated balance but does NOT auto-load (can't sign)\n *\n * @param rpc RPC connection\n * @param payer Fee payer\n * @param mint Mint address\n * @param owner Owner (Signer for auto-load, PublicKey for read-only)\n * @param allowOwnerOffCurve Allow PDA owners (default: false)\n * @param commitment Optional commitment level\n * @param confirmOptions Optional confirm options\n * @returns AccountInterface with unified balance and source breakdown\n */\nexport async function getOrCreateAtaInterface(\n rpc: Rpc,\n payer: Signer,\n mint: PublicKey,\n owner: PublicKey | Signer,\n allowOwnerOffCurve = false,\n commitment?: Commitment,\n confirmOptions?: ConfirmOptions,\n): Promise<AccountInterface> {\n return _getOrCreateAtaInterface(\n rpc,\n payer,\n mint,\n owner,\n allowOwnerOffCurve,\n commitment,\n confirmOptions,\n CTOKEN_PROGRAM_ID,\n getAtaProgramId(CTOKEN_PROGRAM_ID),\n true, // wrap=true for unified path\n );\n}\n\nexport {\n getAccountInterface,\n AccountInterface,\n TokenAccountSource,\n // Note: Account is already exported from @solana/spl-token via get-account-interface\n AccountState,\n ParsedTokenAccount,\n parseCTokenHot,\n parseCTokenCold,\n toAccountInfo,\n convertTokenDataToAccount,\n} from '../get-account-interface';\n\nexport {\n createLoadAccountsParams,\n createLoadAtaInstructionsFromInterface,\n calculateCompressibleLoadComputeUnits,\n CompressibleAccountInput,\n ParsedAccountInfoInterface,\n CompressibleLoadParams,\n PackedCompressedAccount,\n LoadResult,\n} from '../actions/load-ata';\n\nexport { InterfaceOptions } from '../actions/transfer-interface';\n\nexport * from '../../actions';\nexport * from '../../utils';\nexport * from '../../constants';\nexport * from '../../idl';\nexport * from '../../layout';\nexport * from '../../program';\nexport * from '../../types';\nexport * from '../derivation';\n\nexport {\n // Instructions\n createMintInstruction,\n createTokenMetadata,\n createAssociatedCTokenAccountInstruction,\n createAssociatedCTokenAccountIdempotentInstruction,\n createAssociatedTokenAccountInterfaceInstruction,\n createAssociatedTokenAccountInterfaceIdempotentInstruction,\n createAtaInterfaceIdempotentInstruction,\n createMintToInstruction,\n createMintToCompressedInstruction,\n createMintToInterfaceInstruction,\n createUpdateMintAuthorityInstruction,\n createUpdateFreezeAuthorityInstruction,\n createUpdateMetadataFieldInstruction,\n createUpdateMetadataAuthorityInstruction,\n createRemoveMetadataKeyInstruction,\n createWrapInstruction,\n createUnwrapInstruction,\n createDecompressInterfaceInstruction,\n createTransferInterfaceInstruction,\n createCTokenTransferInstruction,\n // Types\n TokenMetadataInstructionData,\n CompressibleConfig,\n CTokenConfig,\n CreateAssociatedCTokenAccountParams,\n // Actions\n createMintInterface,\n createAtaInterface,\n createAtaInterfaceIdempotent,\n // getOrCreateAtaInterface is defined locally with unified behavior\n decompressInterface,\n wrap,\n unwrap,\n mintTo as mintToCToken,\n mintToCompressed,\n mintToInterface,\n updateMintAuthority,\n updateFreezeAuthority,\n updateMetadataField,\n updateMetadataAuthority,\n removeMetadataKey,\n // Helpers\n getMintInterface,\n unpackMintInterface,\n unpackMintData,\n MintInterface,\n // Serde\n BaseMint,\n MintContext,\n MintExtension,\n TokenMetadata,\n CompressedMint,\n deserializeMint,\n serializeMint,\n decodeTokenMetadata,\n encodeTokenMetadata,\n extractTokenMetadata,\n ExtensionType,\n // Metadata formatting\n toOffChainMetadataJson,\n OffChainTokenMetadata,\n OffChainTokenMetadataJson,\n} from '..';\n","import {\n ComputeBudgetProgram,\n ConfirmOptions,\n PublicKey,\n Signer,\n TransactionSignature,\n} from '@solana/web3.js';\nimport {\n Rpc,\n buildAndSignTx,\n sendAndConfirmTx,\n dedupeSigner,\n} from '@lightprotocol/stateless.js';\nimport BN from 'bn.js';\nimport { createUnwrapInstruction } from '../instructions/unwrap';\nimport {\n getSplInterfaceInfos,\n SplInterfaceInfo,\n} from '../../utils/get-token-pool-infos';\nimport { getAssociatedTokenAddressInterface } from '../get-associated-token-address-interface';\nimport { loadAta as _loadAta } from './load-ata';\n\n/**\n * Unwrap c-tokens to SPL tokens.\n *\n * @param rpc RPC connection\n * @param payer Fee payer\n * @param destination Destination SPL/T22 token account\n * @param owner Owner of the c-token (signer)\n * @param mint Mint address\n * @param amount Amount to unwrap (defaults to all)\n * @param splInterfaceInfo SPL interface info\n * @param confirmOptions Confirm options\n *\n * @returns Transaction signature\n */\nexport async function unwrap(\n rpc: Rpc,\n payer: Signer,\n destination: PublicKey,\n owner: Signer,\n mint: PublicKey,\n amount?: number | bigint | BN,\n splInterfaceInfo?: SplInterfaceInfo,\n confirmOptions?: ConfirmOptions,\n): Promise<TransactionSignature> {\n // 1. Get SPL interface info if not provided\n let resolvedSplInterfaceInfo = splInterfaceInfo;\n if (!resolvedSplInterfaceInfo) {\n const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint);\n resolvedSplInterfaceInfo = splInterfaceInfos.find(\n info => info.isInitialized,\n );\n\n if (!resolvedSplInterfaceInfo) {\n throw new Error(\n `No initialized SPL interface found for mint: ${mint.toBase58()}. ` +\n `Please create an SPL interface via createSplInterface().`,\n );\n }\n }\n\n const destAtaInfo = await rpc.getAccountInfo(destination);\n if (!destAtaInfo) {\n throw new Error(\n `Destination account does not exist: ${destination.toBase58()}. ` +\n `Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`,\n );\n }\n\n // Load all tokens to c-token hot ATA\n const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);\n await _loadAta(rpc, ctokenAta, owner, mint, payer, confirmOptions);\n\n // Check c-token hot balance\n const ctokenAccountInfo = await rpc.getAccountInfo(ctokenAta);\n if (!ctokenAccountInfo) {\n throw new Error('No c-token ATA found after loading');\n }\n\n // Parse c-token account balance\n const data = ctokenAccountInfo.data;\n const ctokenBalance = data.readBigUInt64LE(64);\n\n if (ctokenBalance === BigInt(0)) {\n throw new Error('No c-token balance to unwrap');\n }\n\n const unwrapAmount = amount ? BigInt(amount.toString()) : ctokenBalance;\n\n if (unwrapAmount > ctokenBalance) {\n throw new Error(\n `Insufficient c-token balance. Requested: ${unwrapAmount}, Available: ${ctokenBalance}`,\n );\n }\n\n // Build unwrap instruction\n const ix = createUnwrapInstruction(\n ctokenAta,\n destination,\n owner.publicKey,\n mint,\n unwrapAmount,\n resolvedSplInterfaceInfo,\n payer.publicKey,\n );\n\n const { blockhash } = await rpc.getLatestBlockhash();\n const additionalSigners = dedupeSigner(payer, [owner]);\n\n const tx = buildAndSignTx(\n [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), ix],\n payer,\n blockhash,\n additionalSigners,\n );\n\n const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);\n\n return txId;\n}\n"],"names":["createUnwrapInstruction","source","destination","owner","mint","amount","splInterfaceInfo","payer","instructionData","withTransactionHash","withLamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountOwnerIndex","outputQueue","maxTopUp","cpiContext","compressions","createCompressCtoken","createDecompressSpl","poolIndex","bump","proof","inTokenData","outTokenData","inLamports","outLamports","inTlv","outTlv","data","encodeTransfer2InstructionData","keys","pubkey","CompressedTokenProgram","deriveCpiAuthorityPda","isSigner","isWritable","splInterfacePda","tokenProgram","CTOKEN_PROGRAM_ID","TransactionInstruction","programId","async","rpc","ata","options","_createLoadAtaInstructions","createLoadAtaInstructions","allowOwnerOffCurve","associatedTokenProgramId","equals","Error","_getAssociatedTokenAddressInterface","commitment","_getAtaInterface","getAtaInterface","confirmOptions","_getOrCreateAtaInterface","getAtaProgramId","interfaceOptions","_loadAta","loadAta","_transferInterface","transferInterface","resolvedSplInterfaceInfo","getSplInterfaceInfos","find","info","isInitialized","toBase58","getAccountInfo","ctokenAta","getAssociatedTokenAddressInterface","publicKey","ctokenAccountInfo","ctokenBalance","readBigUInt64LE","BigInt","unwrapAmount","toString","ix","blockhash","getLatestBlockhash","additionalSigners","dedupeSigner","tx","buildAndSignTx","ComputeBudgetProgram","setComputeUnitLimit","units","sendAndConfirmTx"],"mappings":"kKAyBgBA,EACZC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAmBJ,GAEnB,MA2BMK,EAA4C,CAC9CC,oBAAqB,EACrBC,yCAA0C,EAC1CC,qCAAsC,EACtCC,gCAAiC,EACjCC,YAAa,EACbC,SAAU,EACVC,WAAY,KACZC,aA1BgC,CAChCC,EAAAA,qBACIZ,EAXW,EAEE,EADD,EAKS,GAWzBa,sBACIb,EAlBW,EAGO,EACP,EAkBXC,EAAiBa,UACjBb,EAAiBc,OAarBC,MAAO,KACPC,YAAa,GACbC,aAAc,GACdC,WAAY,KACZC,YAAa,KACbC,MAAO,KACPC,OAAQ,MAGNC,EAAOC,iCAA+BrB,GAGtCsB,EAAO,CACT,CACIC,OAAQC,EAAsBA,uBAACC,sBAC/BC,SAAU,EACVC,WAAY,GAEhB,CAAEJ,OAAQxB,EAAO2B,SAAU,EAAMC,WAAY,GAC7C,CAAEJ,OAAQ3B,EAAM8B,SAAU,EAAOC,WAAY,GAC7C,CAAEJ,OAAQ5B,EAAO+B,SAAU,EAAMC,WAAY,GAC7C,CAAEJ,OAAQ9B,EAAQiC,SAAU,EAAOC,WAAY,GAC/C,CAAEJ,OAAQ7B,EAAagC,SAAU,EAAOC,WAAY,GACpD,CACIJ,OAAQzB,EAAiB8B,gBACzBF,SAAU,EACVC,WAAY,GAEhB,CACIJ,OAAQzB,EAAiB+B,aACzBH,SAAU,EACVC,WAAY,GAEhB,CACIJ,OAAQO,EAAiBA,kBACzBJ,SAAU,EACVC,WAAY,IAIpB,OAAO,IAAII,EAAAA,uBAAuB,CAC9BC,UAAWR,EAAsBA,uBAACQ,UAClCV,OACAF,QAER,y5RCvBOa,eACHC,EACAC,EACAxC,EACAC,EACAG,EACAqC,GAEA,OAAOC,EAA0BC,0BAC7BJ,EACAC,EACAxC,EACAC,EACAG,EACAqC,EACA,EAER,+EAlDgB,SACZxC,EACAD,EACA4C,EAAqB,EACrBP,EAAuBF,EAAiBA,kBACxCU,GAEA,IAAKR,EAAUS,OAAOX,EAAAA,mBAClB,MAAM,IAAIY,MACN,8IAIR,OAAOC,EAAAA,mCACH/C,EACAD,EACA4C,EACAP,EACAQ,EAER,0BA5COP,eACHC,EACAC,EACAxC,EACAC,EACAgD,EACAZ,GAEA,OAAOa,EAAgBC,gBAACZ,EAAKC,EAAKxC,EAAOC,EAAMgD,EAAYZ,EAAW,EAC1E,kCA+KOC,eACHC,EACAnC,EACAH,EACAD,EACA4C,EAAqB,EACrBK,EACAG,GAEA,OAAOC,EAAwBA,yBAC3Bd,EACAnC,EACAH,EACAD,EACA4C,EACAK,EACAG,EACAjB,EAAAA,kBACAmB,EAAAA,gBAAgBnB,EAAAA,mBAChB,EAER,kBAlHOG,eACHC,EACAC,EACAxC,EACAC,EACAG,EACAgD,EACAG,GAEA,OAAOC,EAAQC,QACXlB,EACAC,EACAxC,EACAC,EACAG,EACAgD,EACAG,EACA,EAER,4BAmBOjB,eACHC,EACAnC,EACAN,EACAG,EACAF,EACAC,EACAE,EACAmC,EAAuBF,oBACvBiB,EACAX,GAEA,OAAOiB,EAAkBC,kBACrBpB,EACAnC,EACAN,EACAG,EACAF,EACAC,EACAE,EACAmC,EACAe,EACAX,EACA,EAER,iBCzJOH,eACHC,EACAnC,EACAL,EACAC,EACAC,EACAC,EACAC,EACAiD,GAGA,IAAIQ,EAA2BzD,EAC/B,IAAKyD,IAEDA,SADgCC,EAAAA,qBAAqBtB,EAAKtC,IACb6D,MACzCC,GAAQA,EAAKC,iBAGZJ,GACD,MAAM,IAAIb,MACN,gDAAgD9C,EAAKgE,wEAOjE,UAD0B1B,EAAI2B,eAAenE,GAEzC,MAAM,IAAIgD,MACN,uCAAuChD,EAAYkE,6HAM3D,MAAME,EAAYC,EAAkCA,mCAACnE,EAAMD,EAAMqE,iBAC3Db,EAAAA,QAASjB,EAAK4B,EAAWnE,EAAOC,EAAMG,EAAOgD,GAGnD,MAAMkB,QAA0B/B,EAAI2B,eAAeC,GACnD,IAAKG,EACD,MAAM,IAAIvB,MAAM,sCAIpB,MACMwB,EADOD,EAAkB7C,KACJ+C,gBAAgB,IAE3C,GAAID,IAAkBE,OAAO,GACzB,MAAM,IAAI1B,MAAM,gCAGpB,MAAM2B,EAAexE,EAASuE,OAAOvE,EAAOyE,YAAcJ,EAE1D,GAAIG,EAAeH,EACf,MAAM,IAAIxB,MACN,4CAA4C2B,iBAA4BH,KAKhF,MAAMK,EAAK/E,EACPsE,EACApE,EACAC,EAAMqE,UACNpE,EACAyE,EACAd,EACAxD,EAAMiE,YAGJQ,UAAEA,SAAoBtC,EAAIuC,qBAC1BC,EAAoBC,EAAYA,aAAC5E,EAAO,CAACJ,IAEzCiF,EAAKC,EAAcA,eACrB,CAACC,EAAAA,qBAAqBC,oBAAoB,CAAEC,MAAO,MAAYT,GAC/DxE,EACAyE,EACAE,GAKJ,aAFmBO,EAAgBA,iBAAC/C,EAAK0C,EAAI7B,EAGjD"}
|
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("@solana/web3.js"),t=require("@lightprotocol/stateless.js"),r=require("buffer"),n=require("@solana/spl-token");const o=r.Buffer.from("pool"),i=r.Buffer.from("cpi_authority"),s=r.Buffer.from([23,169,27,122,147,169,209,152]),a=r.Buffer.from([241,34,48,186,37,179,123,192]),u=r.Buffer.from([65,206,101,37,147,42,221,144]),c=r.Buffer.from([163,52,200,231,140,3,69,186]),d=r.Buffer.from([112,230,105,101,145,202,157,97]),h=r.Buffer.from([69,74,217,36,115,117,97,76]),l=r.Buffer.from([170,23,31,34,133,173,93,242]),m=r.Buffer.from([114,143,210,73,96,115,1,228]);function p(e,t){if(!e.mint.equals(t))throw new Error("TokenPool mint does not match the provided mint.");if(!e.isInitialized)throw new Error(`TokenPool is not initialized. Please create a compressed token pool for mint: ${t.toBase58()} via createTokenPool().`);return 1}async function f(e,r,o){const i=Array.from({length:5},((e,t)=>He.deriveTokenPoolPdaWithIndex(r,t))),s=await e.getMultipleAccountsInfo(i.map((e=>e[0])),o);if(null===s[0])throw new Error(`TokenPool not found. Please create a compressed token pool for mint: ${r.toBase58()} via createTokenPool().`);const a=i.map(((e,t)=>s[t]?n.unpackAccount(e[0],s[t],s[t].owner):null)),u=s[0].owner;return a.map(((e,n)=>e?{mint:r,tokenPoolPda:e.address,tokenProgram:u,activity:void 0,balance:t.bn(e.amount.toString()),isInitialized:1,poolIndex:n,bump:i[n][1]}:{mint:r,tokenPoolPda:i[n][0],tokenProgram:u,activity:void 0,balance:t.bn(0),isInitialized:0,poolIndex:n,bump:i[n][1]}))}var g;exports.Action=void 0,(g=exports.Action||(exports.Action={}))[g.Compress=1]="Compress",g[g.Decompress=2]="Decompress",g[g.Transfer=3]="Transfer";const y=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e};function w(e){const t=y(e).filter((e=>e.isInitialized));if(0===t.length)throw new Error("Please pass at least one initialized token pool info.");return t[0]}function b(e,r){if(0===e.length)throw new Error("Please pass at least one token pool info.");const n=(e=y(e)).find((e=>e.balance.gte(t.bn(r).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 token pool balances are zero. Please pass recent token pool infos.");return n?[n]:e}const v="Could not find accounts to select for transfer.";function M(e,t,r=4){const n=e.find((e=>e.parsed.amount.eq(t)));return n?[[n],n.parsed.amount,n.compressedAccount.lamports,n.parsed.amount]:P(e,t,r)}function P(e,r,n=4){const[o,i,s,a]=k(e,r,n);if(i.lt(t.bn(r))){const i=e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw o.length>=n?new Error(`Account limit exceeded: max ${a.toString()} (${n} accounts) per transaction. Total balance: ${i.toString()} (${e.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance for transfer. Required: ${r.toString()}, available: ${i.toString()}.`)}if(0===o.length)throw new Error(v);return[o,i,s,a]}function k(e,r,n=4){if(0===e.length)throw new Error(v);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>=n)break;if(o.gte(t.bn(r)))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,n).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),o.lt(t.bn(r))&&console.log(`Insufficient balance for transfer. Requested: ${r.toString()}, Returns max available: ${s.toString()}.`),0===a.length)throw new Error(v);return[a,o,i,s]}function S(e,r,n=4){if(0===e.length)throw new Error(v);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>=n)break;if(o=o.add(e.parsed.amount),i=i.add(e.compressedAccount.lamports),s.push(e),o.gte(t.bn(r))){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<n&&(s.push(t),o=o.add(t.parsed.amount),i=i.add(t.compressedAccount.lamports))}break}}const u=a.slice(0,n).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));if(0===s.length)throw new Error(v);return[s,o,i,u]}function A(e){const{inputCompressedTokenAccounts:r,outputStateTreeInfo:n,remainingAccounts:o=[],rootIndices:i,tokenTransferOutputs:s}=e,a=o.slice();let u=null;r.length>0&&r[0].parsed.delegate&&(u=t.getIndexOrAdd(a,r[0].parsed.delegate));const c=[];if(r.forEach(((e,r)=>{const n=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:n,queuePubkeyIndex:o,leafIndex:e.compressedAccount.leafIndex,proveByIndex:e.compressedAccount.proveByIndex},rootIndex:i[r],lamports:e.compressedAccount.lamports.eq(t.bn(0))?null:e.compressedAccount.lamports,tlv:null})})),r.length>0&&n)throw new Error("Cannot specify both input accounts and outputStateTreeInfo");let d;if(r.length>0)d=r[0].compressedAccount.treeInfo;else{if(!n)throw new Error("Neither input accounts nor outputStateTreeInfo are available");d=n}const h=d.nextTreeInfo||d;let l=h.tree;if(h.treeType===t.TreeType.StateV2){if(!t.featureFlags.isV2())throw new Error("V2 trees are not supported yet");l=h.queue}const m=t.padOutputStateMerkleTrees(l,s.length),p=[];m.forEach(((e,r)=>{var n;const o=t.getIndexOrAdd(a,e);p.push({owner:s[r].owner,amount:s[r].amount,lamports:(null===(n=s[r].lamports)||void 0===n?void 0:n.eq(t.bn(0)))?null:s[r].lamports,merkleTreeIndex:o,tlv:null})}));const f=a.map((e=>({pubkey:e,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:f,packedOutputTokenData:p}}function I(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}var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function x(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:1}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:1,get:function(){return e[t]}})})),r}var C={},E={};class _{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}decode(e,t){throw new Error("Layout is abstract")}encode(e,t,r){throw new Error("Layout is abstract")}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 O(e,t){return t.property?e+"["+t.property+"]":e}E.Layout=_,E.nameWithProperty=O,E.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(e.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof _))throw new TypeError("layout must be a Layout");if(t.hasOwnProperty("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:function(e,r){return t.encode(this,e,r)},writable:1}),Object.defineProperty(e,"decode",{value:function(e,r){return t.decode(e,r)},writable:1})};class D extends _{isCount(){throw new Error("ExternalLayout is abstract")}}class B extends D{constructor(e,t){if(void 0===e&&(e=1),!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){void 0===t&&(t=0);const r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}}class L extends D{constructor(e,t,r){if(!(e instanceof _))throw new TypeError("layout must be a Layout");if(void 0===t)t=0;else if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof R||this.layout instanceof K}decode(e,t){return void 0===t&&(t=0),this.layout.decode(e,t+this.offset)}encode(e,t,r){return void 0===r&&(r=0),this.layout.encode(e,t,r+this.offset)}}class R extends _{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntLE(e,r,this.span),this.span}}class K extends _{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntBE(e,r,this.span),this.span}}class W extends _{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntLE(e,r,this.span),this.span}}class U extends _{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntBE(e,r,this.span),this.span}}const N=Math.pow(2,32);function q(e){const t=Math.floor(e/N);return{hi32:t,lo32:e-t*N}}function F(e,t){return e*N+t}class V extends _{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return F(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=q(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class j extends _{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),F(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=q(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class z extends _{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return F(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=q(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Z extends _{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),F(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=q(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class H extends _{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatLE(e,r),4}}class G extends _{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatBE(e,r),4}}class $ extends _{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleLE(e,r),8}}class Q extends _{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleBE(e,r),8}}class X extends _{constructor(e,t,r){if(!(e instanceof _))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof D&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(t instanceof D)&&0<e.span&&(n=t*e.span),super(n,r),this.elementLayout=e,this.count=t}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0,n=this.count;if(n instanceof D&&(n=n.decode(e,t)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let o=0;for(;o<n;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t){void 0===t&&(t=0);const r=[];let n=0,o=this.count;for(o instanceof D&&(o=o.decode(e,t));n<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),n+=1;return r}encode(e,t,r){void 0===r&&(r=0);const n=this.elementLayout,o=e.reduce(((e,o)=>e+n.encode(o,t,r+e)),0);return this.count instanceof D&&this.count.encode(e.length,t,r),o}}class Y extends _{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof _),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===r&&(r=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 n=-1;try{n=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(n,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;try{r=this.fields.reduce(((r,n)=>{const o=n.getSpan(e,t);return t+=o,r+o}),0)}catch(e){throw new RangeError("indeterminate span")}return r}decode(e,t){void 0===t&&(t=0);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(e,t)),t+=n.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r){void 0===r&&(r=0);const n=r;let o=0,i=0;for(const n of this.fields){let s=n.span;if(i=0<s?s:0,void 0!==n.property){const o=e[n.property];void 0!==o&&(i=n.encode(o,t,r),0>s&&(s=n.getSpan(t,r)))}o=r,r+=s}return o+i-n}fromArray(e){const t=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<e.length&&(t[r.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 r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}}class J{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class ee extends J{constructor(e,t){if(!(e instanceof D&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}}class te extends _{constructor(e,t,r){const n=e instanceof R||e instanceof K;if(n)e=new ee(new L(e));else if(e instanceof D&&e.isCount())e=new ee(e);else if(!(e instanceof J))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof _))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&&n&&(o+=e.layout.span)),super(o,r),this.discriminator=e,this.usesPrefixDiscriminator=n,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){if(0<=this.span)return this.span;void 0===t&&(t=0);const r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(e.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&e.hasOwnProperty(this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||e.hasOwnProperty(t.property)))return t}else for(const t in this.registry){const r=this.registry[t];if(e.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(e,t){let r;void 0===t&&(t=0);const n=this.discriminator,o=n.decode(e,t);let i=this.registry[o];if(void 0===i){let s=0;i=this.defaultLayout,this.usesPrefixDiscriminator&&(s=n.layout.span),r=this.makeDestinationObject(),r[n.property]=o,r[i.property]=this.defaultLayout.decode(e,t+s)}else r=i.decode(e,t);return r}encode(e,t,r){void 0===r&&(r=0);const n=this.getSourceVariant(e);if(void 0===n){const n=this.discriminator,o=this.defaultLayout;let i=0;return this.usesPrefixDiscriminator&&(i=n.layout.span),n.encode(e[n.property],t,r),i+o.encode(e[o.property],t,r+i)}return n.encode(e,t,r)}addVariant(e,t,r){const n=new re(this,e,t,r);return this.registry[e]=n,n}getVariant(e,t){let r=e;return Buffer.isBuffer(e)&&(void 0===t&&(t=0),r=this.discriminator.decode(e,t)),this.registry[r]}}class re extends _{constructor(e,t,r,n){if(!(e instanceof te))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 r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof _))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,n),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(e,t+r)}decode(e,t){const r=this.makeDestinationObject();if(void 0===t&&(t=0),this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+n):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!e.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=n;if(this.layout&&(this.layout.encode(e[this.property],t,r+n),o+=this.layout.getSpan(t,r+n),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 ne(e){return 0>e&&(e+=4294967296),e}class oe extends _{constructor(e,t,r){if(!(e instanceof R||e instanceof K))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===r&&(r=t,t=void 0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let n=0;this._packedSetValue=function(e){return n=ne(e),this},this._packedGetValue=function(){return n}}decode(e,t){const r=this.makeDestinationObject();void 0===t&&(t=0);const n=this.word.decode(e,t);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(n));return r}encode(e,t,r){void 0===r&&(r=0);const n=this.word.decode(t,r);this._packedSetValue(n);for(const t of this.fields)if(void 0!==t.property){const r=e[t.property];void 0!==r&&t.encode(r)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){const r=new ie(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new se(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}}class ie{constructor(e,t,r){if(!(e instanceof oe))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const n=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>n)throw new Error("bits too long for span remainder ("+(n-o)+" of "+n+" 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=n-o-t),this.wordMask=ne(this.valueMask<<this.start),this.property=r}decode(){return ne(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==ne(e&this.valueMask))throw new TypeError(O("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=ne(e<<this.start);this.container._packedSetValue(ne(t&~this.wordMask)|r)}}class se extends ie{constructor(e,t){super(e,1,t)}decode(e,t){return!!ie.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),ie.prototype.encode.call(this,e)}}class ae extends _{constructor(e,t){if(!(e instanceof D&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof D||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t){void 0===t&&(t=0);let r=this.span;return 0>r&&(r=this.length.decode(e,t)),e.slice(t,t+r)}encode(e,t,r){let n=this.length;if(this.length instanceof D&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(O("Blob.encode",this)+" requires (length "+n+") Buffer as src");if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return t.write(e.toString("hex"),r,n,"hex"),this.length instanceof D&&this.length.encode(n,t,r),n}}class ue extends _{constructor(e){super(-1,e)}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");void 0===t&&(t=0);let r=t;for(;r<e.length&&0!==e[r];)r+=1;return 1+r-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);return e.slice(t,t+n-1).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),t[r+o]=0,o+1}}class ce extends _{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){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");return void 0===t&&(t=0),e.length-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return e.slice(t,t+n).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),o}}class de extends _{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}E.ExternalLayout=D,E.GreedyCount=B,E.OffsetLayout=L,E.UInt=R,E.UIntBE=K,E.Int=W,E.IntBE=U,E.Float=H,E.FloatBE=G,E.Double=$,E.DoubleBE=Q,E.Sequence=X,E.Structure=Y,E.UnionDiscriminator=J,E.UnionLayoutDiscriminator=ee,E.Union=te,E.VariantLayout=re,E.BitStructure=oe,E.BitField=ie,E.Boolean=se,E.Blob=ae,E.CString=ue,E.UTF8=ce,E.Constant=de,E.greedy=(e,t)=>new B(e,t),E.offset=(e,t,r)=>new L(e,t,r),E.u8=e=>new R(1,e),E.u16=e=>new R(2,e),E.u24=e=>new R(3,e),E.u32=e=>new R(4,e),E.u40=e=>new R(5,e),E.u48=e=>new R(6,e),E.nu64=e=>new V(e),E.u16be=e=>new K(2,e),E.u24be=e=>new K(3,e),E.u32be=e=>new K(4,e),E.u40be=e=>new K(5,e),E.u48be=e=>new K(6,e),E.nu64be=e=>new j(e),E.s8=e=>new W(1,e),E.s16=e=>new W(2,e),E.s24=e=>new W(3,e),E.s32=e=>new W(4,e),E.s40=e=>new W(5,e),E.s48=e=>new W(6,e),E.ns64=e=>new z(e),E.s16be=e=>new U(2,e),E.s24be=e=>new U(3,e),E.s32be=e=>new U(4,e),E.s40be=e=>new U(5,e),E.s48be=e=>new U(6,e),E.ns64be=e=>new Z(e),E.f32=e=>new H(e),E.f32be=e=>new G(e),E.f64=e=>new $(e),E.f64be=e=>new Q(e),E.struct=(e,t,r)=>new Y(e,t,r),E.bits=(e,t,r)=>new oe(e,t,r),E.seq=(e,t,r)=>new X(e,t,r),E.union=(e,t,r)=>new te(e,t,r),E.unionLayoutDiscriminator=(e,t)=>new ee(e,t),E.blob=(e,t)=>new ae(e,t),E.cstr=e=>new ue(e),E.utf8=(e,t)=>new ce(e,t),E.const=(e,t)=>new de(e,t);var he={exports:{}},le=x(Object.freeze({__proto__:null,default:{}}));!function(e,t){function r(e,t){if(!e)throw new Error(t||"Assertion failed")}function n(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function o(e,t,r){if(o.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var i;"object"==typeof he?he.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:le.Buffer}catch(e){}function s(e,t){var n=e.charCodeAt(t);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(0,"Invalid character in "+e)}function a(e,t,r){var n=s(e,r);return r-1>=t&&(n|=s(e,r-1)<<4),n}function u(e,t,n,o){for(var i=0,s=0,a=Math.min(e.length,n),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,r(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,n){if("number"==typeof e)return this._initNumber(e,t,n);if("object"==typeof e)return this._initArray(e,t,n);"hex"===t&&(t=16),r(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,n):(this._parseBase(e,t,o),"le"===n&&this._initArray(this.toArray(),t,n)))},o.prototype._initNumber=function(e,t,n){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):(r(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),t,n)},o.prototype._initArray=function(e,t,n){if(r("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"===n)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"===n)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,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,i=0,s=0;if("be"===r)for(n=e.length-1;n>=t;n-=2)o=a(e,t,n)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;else for(n=(e.length-t)%2==0?t+1:t;n<e.length;n+=2)o=a(e,t,n)<<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,r){this.words=[0],this.length=1;for(var n=0,o=1;o<=67108863;o*=t)n++;n--,o=o/t|0;for(var i=e.length-r,s=i%n,a=Math.min(i,i-s)+r,c=0,d=r;d<a;d+=n)c=u(e,d,d+n,t),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==s){var h=1;for(c=u(e,d,e.length,t),d=0;d<s;d++)h*=t;this.imuln(h),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 h=["","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"],l=[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 p(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var o=0|e.words[0],i=0|t.words[0],s=o*i,a=67108863&s,u=s/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var d=u>>>26,h=67108863&u,l=Math.min(c,t.length-1),m=Math.max(0,c-e.length+1);m<=l;m++){var p=c-m|0;d+=(s=(o=0|e.words[p])*(i=0|t.words[m])+h)/67108864|0,h=67108863&s}r.words[c]=0|h,u=0|d}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}o.prototype.toString=function(e,t){var n;if(t=0|t||1,16===(e=e||10)||"hex"===e){n="";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--),n=0!==i||s!==this.length-1?h[6-u.length]+u+n:u+n}for(0!==i&&(n=i.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var c=l[e],d=m[e];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var f=p.modrn(d).toString(e);n=(p=p.idivn(d)).isZero()?f+n:h[c-f.length]+f+n}for(this.isZero()&&(n="0"+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(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&&r(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,n){this._strip();var o=this.byteLength(),i=n||Math.max(1,o);r(o<=i,"byte array longer than desired length"),r(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,r=0,n=0,o=0;n<this.length;n++){var i=this.words[n]<<o|r;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),r=0,o=0):(r=i>>>24,o+=2)}if(t<e.length)for(e[t++]=r;t<e.length;)e[t++]=0},o.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,r=0,n=0,o=0;n<this.length;n++){var i=this.words[n]<<o|r;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),r=0,o=0):(r=i>>>24,o+=2)}if(t>=0)for(e[t--]=r;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,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},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 r=this._zeroBits(this.words[t]);if(e+=r,26!==r)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 r(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 r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this._strip()},o.prototype.iand=function(e){return r(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,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;n<r.length;n++)this.words[n]=t.words[n]^r.words[n];if(this!==t)for(;n<t.length;n++)this.words[n]=t.words[n];return this.length=t.length,this._strip()},o.prototype.ixor=function(e){return r(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){r("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),n=e%26;this._expand(t),n>0&&t--;for(var o=0;o<t;o++)this.words[o]=67108863&~this.words[o];return n>0&&(this.words[o]=~this.words[o]&67108863>>26-n),this._strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){r("number"==typeof e&&e>=0);var n=e/26|0,o=e%26;return this._expand(n+1),this.words[n]=t?this.words[n]|1<<o:this.words[n]&~(1<<o),this._strip()},o.prototype.iadd=function(e){var t,r,n;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?(r=this,n=e):(r=e,n=this);for(var o=0,i=0;i<n.length;i++)t=(0|r.words[i])+(0|n.words[i])+o,this.words[i]=67108863&t,o=t>>>26;for(;0!==o&&i<r.length;i++)t=(0|r.words[i])+o,this.words[i]=67108863&t,o=t>>>26;if(this.length=r.length,0!==o)this.words[this.length]=o,this.length++;else if(r!==this)for(;i<r.length;i++)this.words[i]=r.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 r,n,o=this.cmp(e);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(r=this,n=e):(r=e,n=this);for(var i=0,s=0;s<n.length;s++)i=(t=(0|r.words[s])-(0|n.words[s])+i)>>26,this.words[s]=67108863&t;for(;0!==i&&s<r.length;s++)i=(t=(0|r.words[s])+i)>>26,this.words[s]=67108863&t;if(0===i&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var f=function(e,t,r){var n,o,i,s=e.words,a=t.words,u=r.words,c=0,d=0|s[0],h=8191&d,l=d>>>13,m=0|s[1],p=8191&m,f=m>>>13,g=0|s[2],y=8191&g,w=g>>>13,b=0|s[3],v=8191&b,M=b>>>13,P=0|s[4],k=8191&P,S=P>>>13,A=0|s[5],I=8191&A,T=A>>>13,x=0|s[6],C=8191&x,E=x>>>13,_=0|s[7],O=8191&_,D=_>>>13,B=0|s[8],L=8191&B,R=B>>>13,K=0|s[9],W=8191&K,U=K>>>13,N=0|a[0],q=8191&N,F=N>>>13,V=0|a[1],j=8191&V,z=V>>>13,Z=0|a[2],H=8191&Z,G=Z>>>13,$=0|a[3],Q=8191&$,X=$>>>13,Y=0|a[4],J=8191&Y,ee=Y>>>13,te=0|a[5],re=8191&te,ne=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],he=8191&de,le=de>>>13,me=0|a[9],pe=8191&me,fe=me>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(c+(n=Math.imul(h,q))|0)+((8191&(o=(o=Math.imul(h,F))+Math.imul(l,q)|0))<<13)|0;c=((i=Math.imul(l,F))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(p,q),o=(o=Math.imul(p,F))+Math.imul(f,q)|0,i=Math.imul(f,F);var ye=(c+(n=n+Math.imul(h,j)|0)|0)+((8191&(o=(o=o+Math.imul(h,z)|0)+Math.imul(l,j)|0))<<13)|0;c=((i=i+Math.imul(l,z)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,q),o=(o=Math.imul(y,F))+Math.imul(w,q)|0,i=Math.imul(w,F),n=n+Math.imul(p,j)|0,o=(o=o+Math.imul(p,z)|0)+Math.imul(f,j)|0,i=i+Math.imul(f,z)|0;var we=(c+(n=n+Math.imul(h,H)|0)|0)+((8191&(o=(o=o+Math.imul(h,G)|0)+Math.imul(l,H)|0))<<13)|0;c=((i=i+Math.imul(l,G)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(v,q),o=(o=Math.imul(v,F))+Math.imul(M,q)|0,i=Math.imul(M,F),n=n+Math.imul(y,j)|0,o=(o=o+Math.imul(y,z)|0)+Math.imul(w,j)|0,i=i+Math.imul(w,z)|0,n=n+Math.imul(p,H)|0,o=(o=o+Math.imul(p,G)|0)+Math.imul(f,H)|0,i=i+Math.imul(f,G)|0;var be=(c+(n=n+Math.imul(h,Q)|0)|0)+((8191&(o=(o=o+Math.imul(h,X)|0)+Math.imul(l,Q)|0))<<13)|0;c=((i=i+Math.imul(l,X)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(k,q),o=(o=Math.imul(k,F))+Math.imul(S,q)|0,i=Math.imul(S,F),n=n+Math.imul(v,j)|0,o=(o=o+Math.imul(v,z)|0)+Math.imul(M,j)|0,i=i+Math.imul(M,z)|0,n=n+Math.imul(y,H)|0,o=(o=o+Math.imul(y,G)|0)+Math.imul(w,H)|0,i=i+Math.imul(w,G)|0,n=n+Math.imul(p,Q)|0,o=(o=o+Math.imul(p,X)|0)+Math.imul(f,Q)|0,i=i+Math.imul(f,X)|0;var ve=(c+(n=n+Math.imul(h,J)|0)|0)+((8191&(o=(o=o+Math.imul(h,ee)|0)+Math.imul(l,J)|0))<<13)|0;c=((i=i+Math.imul(l,ee)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(I,q),o=(o=Math.imul(I,F))+Math.imul(T,q)|0,i=Math.imul(T,F),n=n+Math.imul(k,j)|0,o=(o=o+Math.imul(k,z)|0)+Math.imul(S,j)|0,i=i+Math.imul(S,z)|0,n=n+Math.imul(v,H)|0,o=(o=o+Math.imul(v,G)|0)+Math.imul(M,H)|0,i=i+Math.imul(M,G)|0,n=n+Math.imul(y,Q)|0,o=(o=o+Math.imul(y,X)|0)+Math.imul(w,Q)|0,i=i+Math.imul(w,X)|0,n=n+Math.imul(p,J)|0,o=(o=o+Math.imul(p,ee)|0)+Math.imul(f,J)|0,i=i+Math.imul(f,ee)|0;var Me=(c+(n=n+Math.imul(h,re)|0)|0)+((8191&(o=(o=o+Math.imul(h,ne)|0)+Math.imul(l,re)|0))<<13)|0;c=((i=i+Math.imul(l,ne)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(C,q),o=(o=Math.imul(C,F))+Math.imul(E,q)|0,i=Math.imul(E,F),n=n+Math.imul(I,j)|0,o=(o=o+Math.imul(I,z)|0)+Math.imul(T,j)|0,i=i+Math.imul(T,z)|0,n=n+Math.imul(k,H)|0,o=(o=o+Math.imul(k,G)|0)+Math.imul(S,H)|0,i=i+Math.imul(S,G)|0,n=n+Math.imul(v,Q)|0,o=(o=o+Math.imul(v,X)|0)+Math.imul(M,Q)|0,i=i+Math.imul(M,X)|0,n=n+Math.imul(y,J)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,J)|0,i=i+Math.imul(w,ee)|0,n=n+Math.imul(p,re)|0,o=(o=o+Math.imul(p,ne)|0)+Math.imul(f,re)|0,i=i+Math.imul(f,ne)|0;var Pe=(c+(n=n+Math.imul(h,ie)|0)|0)+((8191&(o=(o=o+Math.imul(h,se)|0)+Math.imul(l,ie)|0))<<13)|0;c=((i=i+Math.imul(l,se)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(O,q),o=(o=Math.imul(O,F))+Math.imul(D,q)|0,i=Math.imul(D,F),n=n+Math.imul(C,j)|0,o=(o=o+Math.imul(C,z)|0)+Math.imul(E,j)|0,i=i+Math.imul(E,z)|0,n=n+Math.imul(I,H)|0,o=(o=o+Math.imul(I,G)|0)+Math.imul(T,H)|0,i=i+Math.imul(T,G)|0,n=n+Math.imul(k,Q)|0,o=(o=o+Math.imul(k,X)|0)+Math.imul(S,Q)|0,i=i+Math.imul(S,X)|0,n=n+Math.imul(v,J)|0,o=(o=o+Math.imul(v,ee)|0)+Math.imul(M,J)|0,i=i+Math.imul(M,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,i=i+Math.imul(w,ne)|0,n=n+Math.imul(p,ie)|0,o=(o=o+Math.imul(p,se)|0)+Math.imul(f,ie)|0,i=i+Math.imul(f,se)|0;var ke=(c+(n=n+Math.imul(h,ue)|0)|0)+((8191&(o=(o=o+Math.imul(h,ce)|0)+Math.imul(l,ue)|0))<<13)|0;c=((i=i+Math.imul(l,ce)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(L,q),o=(o=Math.imul(L,F))+Math.imul(R,q)|0,i=Math.imul(R,F),n=n+Math.imul(O,j)|0,o=(o=o+Math.imul(O,z)|0)+Math.imul(D,j)|0,i=i+Math.imul(D,z)|0,n=n+Math.imul(C,H)|0,o=(o=o+Math.imul(C,G)|0)+Math.imul(E,H)|0,i=i+Math.imul(E,G)|0,n=n+Math.imul(I,Q)|0,o=(o=o+Math.imul(I,X)|0)+Math.imul(T,Q)|0,i=i+Math.imul(T,X)|0,n=n+Math.imul(k,J)|0,o=(o=o+Math.imul(k,ee)|0)+Math.imul(S,J)|0,i=i+Math.imul(S,ee)|0,n=n+Math.imul(v,re)|0,o=(o=o+Math.imul(v,ne)|0)+Math.imul(M,re)|0,i=i+Math.imul(M,ne)|0,n=n+Math.imul(y,ie)|0,o=(o=o+Math.imul(y,se)|0)+Math.imul(w,ie)|0,i=i+Math.imul(w,se)|0,n=n+Math.imul(p,ue)|0,o=(o=o+Math.imul(p,ce)|0)+Math.imul(f,ue)|0,i=i+Math.imul(f,ce)|0;var Se=(c+(n=n+Math.imul(h,he)|0)|0)+((8191&(o=(o=o+Math.imul(h,le)|0)+Math.imul(l,he)|0))<<13)|0;c=((i=i+Math.imul(l,le)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(W,q),o=(o=Math.imul(W,F))+Math.imul(U,q)|0,i=Math.imul(U,F),n=n+Math.imul(L,j)|0,o=(o=o+Math.imul(L,z)|0)+Math.imul(R,j)|0,i=i+Math.imul(R,z)|0,n=n+Math.imul(O,H)|0,o=(o=o+Math.imul(O,G)|0)+Math.imul(D,H)|0,i=i+Math.imul(D,G)|0,n=n+Math.imul(C,Q)|0,o=(o=o+Math.imul(C,X)|0)+Math.imul(E,Q)|0,i=i+Math.imul(E,X)|0,n=n+Math.imul(I,J)|0,o=(o=o+Math.imul(I,ee)|0)+Math.imul(T,J)|0,i=i+Math.imul(T,ee)|0,n=n+Math.imul(k,re)|0,o=(o=o+Math.imul(k,ne)|0)+Math.imul(S,re)|0,i=i+Math.imul(S,ne)|0,n=n+Math.imul(v,ie)|0,o=(o=o+Math.imul(v,se)|0)+Math.imul(M,ie)|0,i=i+Math.imul(M,se)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(w,ue)|0,i=i+Math.imul(w,ce)|0,n=n+Math.imul(p,he)|0,o=(o=o+Math.imul(p,le)|0)+Math.imul(f,he)|0,i=i+Math.imul(f,le)|0;var Ae=(c+(n=n+Math.imul(h,pe)|0)|0)+((8191&(o=(o=o+Math.imul(h,fe)|0)+Math.imul(l,pe)|0))<<13)|0;c=((i=i+Math.imul(l,fe)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(W,j),o=(o=Math.imul(W,z))+Math.imul(U,j)|0,i=Math.imul(U,z),n=n+Math.imul(L,H)|0,o=(o=o+Math.imul(L,G)|0)+Math.imul(R,H)|0,i=i+Math.imul(R,G)|0,n=n+Math.imul(O,Q)|0,o=(o=o+Math.imul(O,X)|0)+Math.imul(D,Q)|0,i=i+Math.imul(D,X)|0,n=n+Math.imul(C,J)|0,o=(o=o+Math.imul(C,ee)|0)+Math.imul(E,J)|0,i=i+Math.imul(E,ee)|0,n=n+Math.imul(I,re)|0,o=(o=o+Math.imul(I,ne)|0)+Math.imul(T,re)|0,i=i+Math.imul(T,ne)|0,n=n+Math.imul(k,ie)|0,o=(o=o+Math.imul(k,se)|0)+Math.imul(S,ie)|0,i=i+Math.imul(S,se)|0,n=n+Math.imul(v,ue)|0,o=(o=o+Math.imul(v,ce)|0)+Math.imul(M,ue)|0,i=i+Math.imul(M,ce)|0,n=n+Math.imul(y,he)|0,o=(o=o+Math.imul(y,le)|0)+Math.imul(w,he)|0,i=i+Math.imul(w,le)|0;var Ie=(c+(n=n+Math.imul(p,pe)|0)|0)+((8191&(o=(o=o+Math.imul(p,fe)|0)+Math.imul(f,pe)|0))<<13)|0;c=((i=i+Math.imul(f,fe)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(W,H),o=(o=Math.imul(W,G))+Math.imul(U,H)|0,i=Math.imul(U,G),n=n+Math.imul(L,Q)|0,o=(o=o+Math.imul(L,X)|0)+Math.imul(R,Q)|0,i=i+Math.imul(R,X)|0,n=n+Math.imul(O,J)|0,o=(o=o+Math.imul(O,ee)|0)+Math.imul(D,J)|0,i=i+Math.imul(D,ee)|0,n=n+Math.imul(C,re)|0,o=(o=o+Math.imul(C,ne)|0)+Math.imul(E,re)|0,i=i+Math.imul(E,ne)|0,n=n+Math.imul(I,ie)|0,o=(o=o+Math.imul(I,se)|0)+Math.imul(T,ie)|0,i=i+Math.imul(T,se)|0,n=n+Math.imul(k,ue)|0,o=(o=o+Math.imul(k,ce)|0)+Math.imul(S,ue)|0,i=i+Math.imul(S,ce)|0,n=n+Math.imul(v,he)|0,o=(o=o+Math.imul(v,le)|0)+Math.imul(M,he)|0,i=i+Math.imul(M,le)|0;var Te=(c+(n=n+Math.imul(y,pe)|0)|0)+((8191&(o=(o=o+Math.imul(y,fe)|0)+Math.imul(w,pe)|0))<<13)|0;c=((i=i+Math.imul(w,fe)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(W,Q),o=(o=Math.imul(W,X))+Math.imul(U,Q)|0,i=Math.imul(U,X),n=n+Math.imul(L,J)|0,o=(o=o+Math.imul(L,ee)|0)+Math.imul(R,J)|0,i=i+Math.imul(R,ee)|0,n=n+Math.imul(O,re)|0,o=(o=o+Math.imul(O,ne)|0)+Math.imul(D,re)|0,i=i+Math.imul(D,ne)|0,n=n+Math.imul(C,ie)|0,o=(o=o+Math.imul(C,se)|0)+Math.imul(E,ie)|0,i=i+Math.imul(E,se)|0,n=n+Math.imul(I,ue)|0,o=(o=o+Math.imul(I,ce)|0)+Math.imul(T,ue)|0,i=i+Math.imul(T,ce)|0,n=n+Math.imul(k,he)|0,o=(o=o+Math.imul(k,le)|0)+Math.imul(S,he)|0,i=i+Math.imul(S,le)|0;var xe=(c+(n=n+Math.imul(v,pe)|0)|0)+((8191&(o=(o=o+Math.imul(v,fe)|0)+Math.imul(M,pe)|0))<<13)|0;c=((i=i+Math.imul(M,fe)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(W,J),o=(o=Math.imul(W,ee))+Math.imul(U,J)|0,i=Math.imul(U,ee),n=n+Math.imul(L,re)|0,o=(o=o+Math.imul(L,ne)|0)+Math.imul(R,re)|0,i=i+Math.imul(R,ne)|0,n=n+Math.imul(O,ie)|0,o=(o=o+Math.imul(O,se)|0)+Math.imul(D,ie)|0,i=i+Math.imul(D,se)|0,n=n+Math.imul(C,ue)|0,o=(o=o+Math.imul(C,ce)|0)+Math.imul(E,ue)|0,i=i+Math.imul(E,ce)|0,n=n+Math.imul(I,he)|0,o=(o=o+Math.imul(I,le)|0)+Math.imul(T,he)|0,i=i+Math.imul(T,le)|0;var Ce=(c+(n=n+Math.imul(k,pe)|0)|0)+((8191&(o=(o=o+Math.imul(k,fe)|0)+Math.imul(S,pe)|0))<<13)|0;c=((i=i+Math.imul(S,fe)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(W,re),o=(o=Math.imul(W,ne))+Math.imul(U,re)|0,i=Math.imul(U,ne),n=n+Math.imul(L,ie)|0,o=(o=o+Math.imul(L,se)|0)+Math.imul(R,ie)|0,i=i+Math.imul(R,se)|0,n=n+Math.imul(O,ue)|0,o=(o=o+Math.imul(O,ce)|0)+Math.imul(D,ue)|0,i=i+Math.imul(D,ce)|0,n=n+Math.imul(C,he)|0,o=(o=o+Math.imul(C,le)|0)+Math.imul(E,he)|0,i=i+Math.imul(E,le)|0;var Ee=(c+(n=n+Math.imul(I,pe)|0)|0)+((8191&(o=(o=o+Math.imul(I,fe)|0)+Math.imul(T,pe)|0))<<13)|0;c=((i=i+Math.imul(T,fe)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(W,ie),o=(o=Math.imul(W,se))+Math.imul(U,ie)|0,i=Math.imul(U,se),n=n+Math.imul(L,ue)|0,o=(o=o+Math.imul(L,ce)|0)+Math.imul(R,ue)|0,i=i+Math.imul(R,ce)|0,n=n+Math.imul(O,he)|0,o=(o=o+Math.imul(O,le)|0)+Math.imul(D,he)|0,i=i+Math.imul(D,le)|0;var _e=(c+(n=n+Math.imul(C,pe)|0)|0)+((8191&(o=(o=o+Math.imul(C,fe)|0)+Math.imul(E,pe)|0))<<13)|0;c=((i=i+Math.imul(E,fe)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(W,ue),o=(o=Math.imul(W,ce))+Math.imul(U,ue)|0,i=Math.imul(U,ce),n=n+Math.imul(L,he)|0,o=(o=o+Math.imul(L,le)|0)+Math.imul(R,he)|0,i=i+Math.imul(R,le)|0;var Oe=(c+(n=n+Math.imul(O,pe)|0)|0)+((8191&(o=(o=o+Math.imul(O,fe)|0)+Math.imul(D,pe)|0))<<13)|0;c=((i=i+Math.imul(D,fe)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,n=Math.imul(W,he),o=(o=Math.imul(W,le))+Math.imul(U,he)|0,i=Math.imul(U,le);var De=(c+(n=n+Math.imul(L,pe)|0)|0)+((8191&(o=(o=o+Math.imul(L,fe)|0)+Math.imul(R,pe)|0))<<13)|0;c=((i=i+Math.imul(R,fe)|0)+(o>>>13)|0)+(De>>>26)|0,De&=67108863;var Be=(c+(n=Math.imul(W,pe))|0)+((8191&(o=(o=Math.imul(W,fe))+Math.imul(U,pe)|0))<<13)|0;return c=((i=Math.imul(U,fe))+(o>>>13)|0)+(Be>>>26)|0,Be&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=be,u[4]=ve,u[5]=Me,u[6]=Pe,u[7]=ke,u[8]=Se,u[9]=Ae,u[10]=Ie,u[11]=Te,u[12]=xe,u[13]=Ce,u[14]=Ee,u[15]=_e,u[16]=Oe,u[17]=De,u[18]=Be,0!==c&&(u[19]=c,r.length++),r};function g(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,o=0,i=0;i<r.length-1;i++){var s=o;o=0;for(var a=67108863&n,u=Math.min(i,t.length-1),c=Math.max(0,i-e.length+1);c<=u;c++){var d=i-c,h=(0|e.words[d])*(0|t.words[c]),l=67108863&h;a=67108863&(l=l+a|0),o+=(s=(s=s+(h/67108864|0)|0)+(l>>>26)|0)>>>26,s&=67108863}r.words[i]=a,n=s,s=o}return 0!==n?r.words[i]=n:r.length--,r._strip()}function y(e,t,r){return g(e,t,r)}Math.imul||(f=p),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?f(this,e,t):r<63?p(this,e,t):r<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),r("number"==typeof e),r(e<67108864);for(var n=0,o=0;o<this.length;o++){var i=(0|this.words[o])*e,s=(67108863&i)+(67108863&n);n>>=26,n+=i/67108864|0,n+=s>>>26,this.words[o]=67108863&s}return 0!==n&&(this.words[o]=n,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()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=e.words[n]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n<t.length&&0===t[n];n++,r=r.sqr());if(++n<t.length)for(var i=r.sqr();n<t.length;n++,i=i.sqr())0!==t[n]&&(r=r.mul(i));return r},o.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,n=e%26,o=(e-n)/26,i=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(t=0;t<this.length;t++){var a=this.words[t]&i,u=(0|this.words[t])-a<<n;this.words[t]=u|s,s=a>>>26-n}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 r(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,n){var o;r("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=n;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 h=0|this.words[c];this.words[c]=d<<26-i|h>>>i,d=h&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,n){return r(0===this.negative),this.iushrn(e,t,n)},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){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26,o=1<<t;return this.length<=n?0:!!(this.words[n]&o)},o.prototype.imaskn=function(e){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==t&&n++,this.length=Math.min(n,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 r("number"==typeof e),r(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(r("number"==typeof e),r(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,n){var o,i,s=e.length+n;this._expand(s);var a=0;for(o=0;o<e.length;o++){i=(0|this.words[o+n])+a;var u=(0|e.words[o])*t;a=((i-=67108863&u)>>26)-(u/67108864|0),this.words[o+n]=67108863&i}for(;o<this.length-n;o++)a=(i=(0|this.words[o+n])+a)>>26,this.words[o+n]=67108863&i;if(0===a)return this._strip();for(r(-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 r=(this.length,e.length),n=this.clone(),i=e,s=0|i.words[i.length-1];0!=(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,u=n.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=n.clone()._ishlnsubmul(i,1,u);0===d.negative&&(n=d,a&&(a.words[u]=1));for(var h=u-1;h>=0;h--){var l=67108864*(0|n.words[i.length+h])+(0|n.words[i.length+h-1]);for(l=Math.min(l/s|0,67108863),n._ishlnsubmul(i,l,h);0!==n.negative;)l--,n.negative=0,n._ishlnsubmul(i,1,h),n.isZero()||(n.negative^=1);a&&(a.words[h]=l)}return a&&a._strip(),n._strip(),"div"!==t&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(e,t,n){return r(!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(),n&&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(),n&&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 r=0!==t.div.negative?t.mod.isub(e):t.mod,n=e.ushrn(1),o=e.andln(1),i=r.cmp(n);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),r(e<=67108863);for(var n=(1<<26)%e,o=0,i=this.length-1;i>=0;i--)o=(n*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),r(e<=67108863);for(var n=0,o=this.length-1;o>=0;o--){var i=(0|this.words[o])+67108864*n;this.words[o]=i/e|0,n=i%e}return this._strip(),t?this.ineg():this},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=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()&&n.isEven();)t.iushrn(1),n.iushrn(1),++c;for(var d=n.clone(),h=t.clone();!t.isZero();){for(var l=0,m=1;0==(t.words[0]&m)&&l<26;++l,m<<=1);if(l>0)for(t.iushrn(l);l-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(d),s.isub(h)),i.iushrn(1),s.iushrn(1);for(var p=0,f=1;0==(n.words[0]&f)&&p<26;++p,f<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(d),u.isub(h)),a.iushrn(1),u.iushrn(1);t.cmp(n)>=0?(t.isub(n),i.isub(a),s.isub(u)):(n.isub(t),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:n.iushln(c)}},o.prototype._invmp=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i,s=new o(1),a=new o(0),u=n.clone();t.cmpn(1)>0&&n.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 h=0,l=1;0==(n.words[0]&l)&&h<26;++h,l<<=1);if(h>0)for(n.iushrn(h);h-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(n)>=0?(t.isub(n),s.isub(a)):(n.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(),r=e.clone();t.negative=0,r.negative=0;for(var n=0;t.isEven()&&r.isEven();n++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var o=t.cmp(r);if(o<0){var i=t;t=r,r=i}else if(0===o||0===r.cmpn(1))break;t.isub(r)}return r.iushln(n)},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){r("number"==typeof e);var t=e%26,n=(e-t)/26,o=1<<t;if(this.length<=n)return this._expand(n+1),this.words[n]|=o,this;for(var i=o,s=n;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,n=e<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)t=1;else{n&&(e=-e),r(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,r=this.length-1;r>=0;r--){var n=0|this.words[r],o=0|e.words[r];if(n!==o){n<o?t=-1:n>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 S(e)},o.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return r(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 r(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var w={k256:null,p224:null,p192:null,p25519:null};function b(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 v(){b.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){b.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function P(){b.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function k(){b.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function S(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function A(e){S.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)}b.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},b.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},b.prototype.split=function(e,t){e.iushrn(this.n,0,t)},b.prototype.imulK=function(e){return e.imul(this.k)},n(v,b),v.prototype.split=function(e,t){for(var r=4194303,n=Math.min(e.length,9),o=0;o<n;o++)t.words[o]=e.words[o];if(t.length=n,e.length<=9)return e.words[0]=0,void(e.length=1);var i=e.words[9];for(t.words[t.length++]=i&r,o=10;o<e.length;o++){var s=0|e.words[o];e.words[o-10]=(s&r)<<4|i>>>22,i=s}i>>>=22,e.words[o-10]=i,0===i&&e.length>10?e.length-=10:e.length-=9},v.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(M,b),n(P,b),n(k,b),k.prototype.imulK=function(e){for(var t=0,r=0;r<e.length;r++){var n=19*(0|e.words[r])+t,o=67108863&n;n>>>=26,e.words[r]=o,t=n}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(w[e])return w[e];var t;if("k256"===e)t=new v;else if("p224"===e)t=new M;else if("p192"===e)t=new P;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new k}return w[e]=t,t},S.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},S.prototype._verify2=function(e,t){r(0==(e.negative|t.negative),"red works only with positives"),r(e.red&&e.red===t.red,"red works only with red numbers")},S.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},S.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},S.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},S.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},S.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},S.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},S.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},S.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},S.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},S.prototype.isqr=function(e){return this.imul(e,e.clone())},S.prototype.sqr=function(e){return this.mul(e,e)},S.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(r(t%2==1),3===t){var n=this.m.add(new o(1)).iushrn(2);return this.pow(e,n)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);r(!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 h=this.pow(d,i),l=this.pow(e,i.addn(1).iushrn(1)),m=this.pow(e,i),p=s;0!==m.cmp(a);){for(var f=m,g=0;0!==f.cmp(a);g++)f=f.redSqr();r(g<p);var y=this.pow(h,new o(1).iushln(p-g-1));l=l.redMul(y),h=y.redSqr(),m=m.redMul(h),p=g}return l},S.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},S.prototype.pow=function(e,t){if(t.isZero())return new o(1).toRed(this);if(0===t.cmpn(1))return e.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=e;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],e);var i=r[0],s=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),n=t.length-1;n>=0;n--){for(var c=t.words[n],d=u-1;d>=0;d--){var h=c>>d&1;i!==r[0]&&(i=this.sqr(i)),0!==h||0!==s?(s<<=1,s|=h,(4==++a||0===n&&0===d)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}u=26}return i},S.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},S.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new A(e)},n(A,S),A.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},A.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},A.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).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)},A.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).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)},A.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,T);var me=he.exports;!function(t){var r=T&&T.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:1}),t.map=t.array=t.rustEnum=t.str=t.vecU8=t.tagged=t.vec=t.bool=t.option=t.publicKey=t.i256=t.u256=t.i128=t.u128=t.i64=t.u64=t.struct=t.f64=t.f32=t.i32=t.u32=t.i16=t.u16=t.i8=t.u8=void 0;const n=E,o=e,i=r(me);var s=E;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return s.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return s.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return s.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return s.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return s.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return s.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return s.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return s.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return s.struct}});class a extends n.Layout{constructor(e,t,r){super(e,r),this.blob=(0,n.blob)(e),this.signed=t}decode(e,t=0){const r=new i.default(this.blob.decode(e,t),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(e,t,r=0){return this.signed&&(e=e.toTwos(8*this.span)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),t,r)}}function u(e){return new a(8,0,e)}t.u64=u,t.i64=function(e){return new a(8,1,e)},t.u128=function(e){return new a(16,0,e)},t.i128=function(e){return new a(16,1,e)},t.u256=function(e){return new a(32,0,e)},t.i256=function(e){return new a(32,1,e)};class c extends n.Layout{constructor(e,t,r,n){super(e.span,n),this.layout=e,this.decoder=t,this.encoder=r}decode(e,t){return this.decoder(this.layout.decode(e,t))}encode(e,t,r){return this.layout.encode(this.encoder(e),t,r)}getSpan(e,t){return this.layout.getSpan(e,t)}}t.publicKey=function(e){return new c((0,n.blob)(32),(e=>new o.PublicKey(e)),(e=>e.toBuffer()),e)};class d extends n.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,n.u8)()}encode(e,t,r=0){return null==e?this.discriminator.encode(0,t,r):(this.discriminator.encode(1,t,r),this.layout.encode(e,t,r+1)+1)}decode(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return null;if(1===r)return this.layout.decode(e,t+1);throw new Error("Invalid option "+this.property)}getSpan(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return 1;if(1===r)return this.layout.getSpan(e,t+1)+1;throw new Error("Invalid option "+this.property)}}function h(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function l(e){return e?1:0}function m(e){const t=(0,n.u32)("length"),r=(0,n.struct)([t,(0,n.blob)((0,n.offset)(t,-t.span),"data")]);return new c(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new d(e,t)},t.bool=function(e){return new c((0,n.u8)(),h,l,e)},t.vec=function(e,t){const r=(0,n.u32)("length"),o=(0,n.struct)([r,(0,n.seq)(e,(0,n.offset)(r,-r.span),"values")]);return new c(o,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const o=(0,n.struct)([u("tag"),t.replicate("data")]);return new c(o,(function({tag:t,data:r}){if(!t.eq(e))throw new Error("Invalid tag, expected: "+e.toString("hex")+", got: "+t.toString("hex"));return r}),(t=>({tag:e,data:t})),r)},t.vecU8=m,t.str=function(e){return new c(m(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const o=(0,n.union)(null!=r?r:(0,n.u8)(),t);return e.forEach(((e,t)=>o.addVariant(t,e,e.property))),o},t.array=function(e,t,r){const o=(0,n.struct)([(0,n.seq)(e,t,"values")]);return new c(o,(({values:e})=>e),(e=>({values:e})),r)};class p extends n.Layout{constructor(e,t,r){super(e.span+t.span,r),this.keyLayout=e,this.valueLayout=t}decode(e,t){return t=t||0,[this.keyLayout.decode(e,t),this.valueLayout.decode(e,t+this.keyLayout.getSpan(e,t))]}encode(e,t,r){r=r||0;const n=this.keyLayout.encode(e[0],t,r);return n+this.valueLayout.encode(e[1],t,r+n)}getSpan(e,t){return this.keyLayout.getSpan(e,t)+this.valueLayout.getSpan(e,t)}}t.map=function(e,t,r){const o=(0,n.u32)("length"),i=(0,n.struct)([o,(0,n.seq)(new p(e,t),(0,n.offset)(o,-o.span),"values")]);return new c(i,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(C);const pe=C.struct([C.array(C.u8(),32,"a"),C.array(C.u8(),64,"b"),C.array(C.u8(),32,"c")]),fe=C.struct([C.publicKey("owner"),C.u64("amount"),C.option(C.u64(),"lamports"),C.u8("merkleTreeIndex"),C.option(C.vecU8(),"tlv")]),ge=C.struct([C.u64("amount"),C.option(C.u8(),"delegateIndex"),C.struct([C.u8("merkleTreePubkeyIndex"),C.u8("queuePubkeyIndex"),C.u32("leafIndex"),C.bool("proveByIndex")],"merkleContext"),C.u16("rootIndex"),C.option(C.u64(),"lamports"),C.option(C.vecU8(),"tlv")]),ye=C.struct([C.publicKey("owner"),C.option(C.u8(),"delegateChangeAccountIndex")]),we=C.struct([C.bool("setContext"),C.bool("firstSetContext"),C.u8("cpiContextAccountIndex")]),be=C.struct([C.option(pe,"proof"),C.publicKey("mint"),C.option(ye,"delegatedTransfer"),C.vec(ge,"inputTokenDataWithContext"),C.vec(fe,"outputCompressedAccounts"),C.bool("isCompress"),C.option(C.u64(),"compressOrDecompressAmount"),C.option(we,"cpiContext"),C.option(C.u8(),"lamportsChangeAccountMerkleTreeIndex")]),ve=C.struct([C.vec(C.publicKey(),"recipients"),C.vec(C.u64(),"amounts"),C.option(C.u64(),"lamports")]),Me=C.struct([C.vec(C.publicKey(),"pubkeys"),C.option(C.vec(C.u64(),"amounts"),"amounts"),C.option(C.u64(),"lamports"),C.option(C.u64(),"amount"),C.u8("index"),C.u8("bump")]),Pe=C.struct([C.publicKey("owner"),C.option(C.u64(),"remainingAmount"),C.option(we,"cpiContext")]);function ke(e){const t=r.Buffer.alloc(1e3),n=ve.encode({recipients:e.recipients,amounts:e.amounts,lamports:e.lamports},t);return r.Buffer.concat([new Uint8Array(a),new Uint8Array(t.subarray(0,n))])}function Se(e){const t=r.Buffer.alloc(1e3),n=Me.encode(e,t),o=r.Buffer.alloc(4);o.writeUInt32LE(n,0);const i=t.subarray(0,n);return r.Buffer.concat([new Uint8Array(u),new Uint8Array(o),new Uint8Array(i)])}function Ae(e){const t=r.Buffer.alloc(1e3),n=Pe.encode({owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext},t);return r.Buffer.concat([new Uint8Array(d),new Uint8Array(t.subarray(0,n))])}function Ie(e){const t=r.Buffer.alloc(1e3),n=be.encode(e,t),o=r.Buffer.alloc(4);o.writeUInt32LE(n,0);const i=t.subarray(0,n);return r.Buffer.concat([new Uint8Array(c),new Uint8Array(o),new Uint8Array(i)])}const Te=e=>{const{feePayer:t,tokenPoolPda:r,systemProgram:n,mint:o,tokenProgram:i,cpiAuthorityPda:s}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},xe=e=>{const{feePayer:t,tokenPoolPda:r,systemProgram:n,mint:o,tokenProgram:i,cpiAuthorityPda:s,existingTokenPoolPda:a}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},Ce=e=>{const t=He.programId,{feePayer:r,authority:n,cpiAuthorityPda:o,mint:i,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:c,noopProgram:d,accountCompressionAuthority:h,accountCompressionProgram:l,merkleTree:m,selfProgram:p,systemProgram:f,solPoolPda:g}=e;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,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:h,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:null!=g?g:t,isSigner:0,isWritable:1}]},Ee=e=>{const t=He.programId,{feePayer:r,authority:n,cpiAuthorityPda:o,lightSystemProgram:i,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:c,selfProgram:d,tokenPoolPda:h,compressOrDecompressTokenAccount:l,tokenProgram:m,systemProgram:p}=e;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,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!=h?h:t,isSigner:0,isWritable:1},{pubkey:null!=l?l:t,isSigner:0,isWritable:1},{pubkey:null!=m?m:t,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0}]},_e=e=>{const{feePayer:t,authority:r,cpiAuthorityPda:n,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:d}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:n,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}]},Oe=_e,De=e=>{const{feePayer:t,authority:r,cpiAuthorityPda:n,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:d,mint:h}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:n,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:h,isSigner:0,isWritable:0}]},Be=De,Le=C.struct([C.struct([C.array(C.u8(),32,"a"),C.array(C.u8(),64,"b"),C.array(C.u8(),32,"c")],"proof"),C.publicKey("mint"),C.vec(ge,"inputTokenDataWithContext"),C.option(we,"cpiContext"),C.publicKey("delegate"),C.u64("delegatedAmount"),C.u8("delegateMerkleTreeIndex"),C.u8("changeAccountMerkleTreeIndex"),C.option(C.u64(),"delegateLamports")]),Re=C.struct([C.struct([C.array(C.u8(),32,"a"),C.array(C.u8(),64,"b"),C.array(C.u8(),32,"c")],"proof"),C.publicKey("mint"),C.vec(ge,"inputTokenDataWithContext"),C.option(we,"cpiContext"),C.u8("outputAccountMerkleTreeIndex")]),Ke={a:new Array(32).fill(0),b:new Array(64).fill(0),c:new Array(32).fill(0)};function We(e){return e.a.every((e=>0===e))&&e.b.every((e=>0===e))&&e.c.every((e=>0===e))}function Ue(e){var t;const n=r.Buffer.alloc(1e3),o=null!==(t=e.proof)&&void 0!==t?t:Ke,i=Le.encode(Object.assign(Object.assign({},e),{proof:o}),n),s=r.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return r.Buffer.concat([new Uint8Array(h),new Uint8Array(s),new Uint8Array(a)])}function Ne(e){var t;const n=r.Buffer.alloc(1e3),o=null!==(t=e.proof)&&void 0!==t?t:Ke,i=Re.encode(Object.assign(Object.assign({},e),{proof:o}),n),s=r.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return r.Buffer.concat([new Uint8Array(l),new Uint8Array(s),new Uint8Array(a)])}const qe=e=>e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),Fe=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")}))},Ve=e=>({mint:e[0].parsed.mint,currentOwner:e[0].parsed.owner,delegate:e[0].parsed.delegate}),je=(e,t)=>{if(e.length<1)throw new Error("Must supply at least one input token account.");const r=e[0].parsed.owner,n=e.findIndex((e=>e.parsed.delegate));if(-1===n)return{delegatedTransfer:null,authority:r};const o=e[n].parsed.delegate;return{delegatedTransfer:{owner:r,delegateChangeAccountIndex:t.length<=1?null:0},authority:o}};function ze(e,r,n){n=t.bn(n);const o=qe(e),i=t.sumUpLamports(e.map((e=>e.compressedAccount))),s=o.sub(n);return t.validateSufficientBalance(s),s.eq(t.bn(0))&&i.eq(t.bn(0))?[{owner:r,amount:n,lamports:i,tlv:null}]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),Fe(e),[{owner:e[0].parsed.owner,amount:s,lamports:i,tlv:null},{owner:r,amount:n,lamports:t.bn(0),tlv:null}])}function Ze(e,r){r=t.bn(r);const n=t.sumUpLamports(e.map((e=>e.compressedAccount))),o=qe(e).sub(r);return t.validateSufficientBalance(o),o.eq(t.bn(0))&&n.eq(t.bn(0))?[]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),Fe(e),[{owner:e[0].parsed.owner,amount:o,lamports:n,tlv:null}])}class He{constructor(){}static setProgramId(t){this.programId="string"==typeof t?new e.PublicKey(t):t}static deriveTokenPoolPda(t){const r=[o,t.toBuffer()],[n,i]=e.PublicKey.findProgramAddressSync(r,this.programId);return n}static findTokenPoolIndexAndBump(e,t){for(let r=0;r<5;r++){const n=He.deriveTokenPoolPdaWithIndex(t,r);if(n[0].equals(e))return[r,n[1]]}throw new Error("Token pool not found")}static deriveTokenPoolPdaWithIndex(t,n){let o=[];o=0===n?[r.Buffer.from("pool"),t.toBuffer(),r.Buffer.from([])]:[r.Buffer.from("pool"),t.toBuffer(),r.Buffer.from([n])];const[i,s]=e.PublicKey.findProgramAddressSync(o,this.programId);return[i,s]}static get deriveCpiAuthorityPda(){const[t,r]=e.PublicKey.findProgramAddressSync([i],this.programId);return t}static async createMint({feePayer:t,mint:r,authority:o,freezeAuthority:i,decimals:s,rentExemptBalance:a,tokenProgramId:u,mintSize:c}){const d=null!=u?u:n.TOKEN_PROGRAM_ID;return[e.SystemProgram.createAccount({fromPubkey:t,lamports:a,newAccountPubkey:r,programId:d,space:null!=c?c:n.MINT_SIZE}),n.createInitializeMint2Instruction(r,s,o,i,d),await this.createTokenPool({feePayer:t,mint:r,tokenProgramId:d})]}static async createTokenPool({feePayer:t,mint:r,tokenProgramId:o}){const i=null!=o?o:n.TOKEN_PROGRAM_ID,a=this.deriveTokenPoolPdaWithIndex(r,0),u=Te({mint:r,feePayer:t,tokenPoolPda:a[0],tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:u,data:s})}static async addTokenPool({feePayer:t,mint:o,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:n.TOKEN_PROGRAM_ID,u=this.deriveTokenPoolPdaWithIndex(o,i-1),c=this.deriveTokenPoolPdaWithIndex(o,i),d=xe({mint:o,feePayer:t,tokenPoolPda:c[0],existingTokenPoolPda:u[0],tokenProgram:a,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:d,data:r.Buffer.concat([new Uint8Array(m),new Uint8Array(r.Buffer.from([i]))])})}static async mintTo({feePayer:r,mint:n,authority:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=t.defaultStaticAccountsStruct(),d=u.tokenProgram;p(u,n);const h=t.toArray(s).map((e=>t.bn(e))),l=t.toArray(i);if(h.length!==l.length)throw new Error("Amount and toPubkey arrays must have the same length");const m=Ce({mint:n,feePayer:r,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:d,tokenPoolPda:u.tokenPoolPda,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:e.SystemProgram.programId,solPoolPda:null}),f=ke({recipients:l,amounts:h,lamports:null});return new e.TransactionInstruction({programId:this.programId,keys:m,data:f})}static async approveAndMintTo({feePayer:e,mint:t,authority:r,authorityTokenAccount:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=BigInt(s.toString());return[n.createMintToInstruction(t,o,r,c,[],u.tokenProgram),await this.compress({payer:e,owner:r,source:o,toAddress:i,mint:t,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u})]}static async transfer({payer:r,inputCompressedTokenAccounts:n,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const u=ze(n,o,i),{inputTokenDataWithContext:c,packedOutputTokenData:d,remainingAccountMetas:h}=A({inputCompressedTokenAccounts:n,rootIndices:a,tokenTransferOutputs:u}),{mint:l}=Ve(n),{delegatedTransfer:m,authority:p}=je(n,u),f=Ie({proof:s,mint:l,delegatedTransfer:m,inputTokenDataWithContext:c,outputCompressedAccounts:d,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:g,noopProgram:y,registeredProgramPda:w,accountCompressionProgram:b}=t.defaultStaticAccountsStruct(),v=Ee({feePayer:r,authority:p,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:w,noopProgram:y,accountCompressionAuthority:g,accountCompressionProgram:b,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:e.SystemProgram.programId});return v.push(...h),new e.TransactionInstruction({programId:this.programId,keys:v,data:f})}static async createTokenProgramLookupTable({payer:r,authority:o,mints:i,recentSlot:s,remainingAccounts:a}){let u=[e.SystemProgram.programId,e.ComputeBudgetProgram.programId,this.deriveCpiAuthorityPda,t.LightSystemProgram.programId,He.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,n.TOKEN_PROGRAM_ID,n.TOKEN_2022_PROGRAM_ID,o];i&&u.push(...i,...i.map((e=>this.deriveTokenPoolPda(e)))),a&&a.length>0&&u.push(...a);const c=new Set,d=u.filter((e=>{const t=e.toBase58();return c.has(t)?0:(c.add(t),1)})),[h,l]=e.AddressLookupTableProgram.createLookupTable({authority:o,payer:o,recentSlot:s}),m=[h];for(let t=0;t<d.length;t+=25){const n=d.slice(t,t+25),i=e.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:l,addresses:n});m.push(i)}return{instructions:m,address:l}}static async compress({payer:r,owner:n,source:o,toAddress:i,amount:s,mint:a,outputStateTreeInfo:u,tokenPoolInfo:c}){let d;const h=t.toArray(s),l=t.toArray(i);if(p(c,a),h.length!==l.length)throw new Error("Amount and toAddress arrays must have the same length");if(t.featureFlags.isV2()){const[i,s]=this.findTokenPoolIndexAndBump(c.tokenPoolPda,a),d=Se({pubkeys:l,amounts:h.length>1?h.map((e=>t.bn(e))):null,lamports:null,amount:1===h.length?t.bn(h[0]):null,index:i,bump:s}),m=Ce(Object.assign(Object.assign({mint:a,feePayer:r,authority:n,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:c.tokenProgram,tokenPoolPda:c.tokenPoolPda,lightSystemProgram:t.LightSystemProgram.programId},t.defaultStaticAccountsStruct()),{merkleTree:u.queue,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,solPoolPda:null}));return m.push({pubkey:o,isWritable:1,isSigner:0}),new e.TransactionInstruction({programId:this.programId,keys:m,data:d})}{d=h.map(((e,r)=>{const n=t.bn(e);return{owner:l[r],amount:n,lamports:null,tlv:null}}));const{inputTokenDataWithContext:i,packedOutputTokenData:m,remainingAccountMetas:p}=A({inputCompressedTokenAccounts:[],outputStateTreeInfo:u,rootIndices:[],tokenTransferOutputs:d}),f=Ie({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=Ee(Object.assign(Object.assign({},t.defaultStaticAccountsStruct()),{feePayer:r,authority:n,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,tokenPoolPda:c.tokenPoolPda,compressOrDecompressTokenAccount:o,tokenProgram:c.tokenProgram}));return g.push(...p),new e.TransactionInstruction({programId:this.programId,keys:g,data:f})}}static async decompress({payer:r,inputCompressedTokenAccounts:n,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a,tokenPoolInfos:u}){const c=t.bn(i),d=t.toArray(u),h=Ze(n,c),{inputTokenDataWithContext:l,packedOutputTokenData:m,remainingAccountMetas:p}=A({inputCompressedTokenAccounts:n,rootIndices:a,tokenTransferOutputs:h,remainingAccounts:d.slice(1).map((e=>e.tokenPoolPda))}),{mint:f}=Ve(n),{delegatedTransfer:g,authority:y}=je(n,h),w=Ie({proof:s,mint:f,delegatedTransfer:g,inputTokenDataWithContext:l,outputCompressedAccounts:m,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),b=d[0].tokenProgram,{accountCompressionAuthority:v,noopProgram:M,registeredProgramPda:P,accountCompressionProgram:k}=t.defaultStaticAccountsStruct(),S=Ee({feePayer:r,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:P,noopProgram:M,accountCompressionAuthority:v,accountCompressionProgram:k,selfProgram:this.programId,tokenPoolPda:d[0].tokenPoolPda,compressOrDecompressTokenAccount:o,tokenProgram:b,systemProgram:e.SystemProgram.programId});return S.push(...p),new e.TransactionInstruction({programId:this.programId,keys:S,data:w})}static async mergeTokenAccounts({payer:e,owner:r,inputCompressedTokenAccounts:n,mint:o,recentValidityProof:i,recentInputStateRootIndices:s}){if(n.length>4)throw new Error("Cannot merge more than 4 token accounts at once");return I(n,o),[await this.transfer({payer:e,inputCompressedTokenAccounts:n,toAddress:r,amount:n.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),recentInputStateRootIndices:s,recentValidityProof:i})]}static async compressSplTokenAccount({feePayer:r,authority:n,tokenAccount:o,mint:i,remainingAmount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){p(u,i);const c=[{pubkey:a.treeType===t.TreeType.StateV2?a.queue:a.tree,isSigner:0,isWritable:1}],d=Ae({owner:n,remainingAmount:null!=s?s:null,cpiContext:null}),{accountCompressionAuthority:h,noopProgram:l,registeredProgramPda:m,accountCompressionProgram:f}=t.defaultStaticAccountsStruct(),g=Ee({feePayer:r,authority:n,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:l,accountCompressionAuthority:h,accountCompressionProgram:f,selfProgram:this.programId,tokenPoolPda:u.tokenPoolPda,compressOrDecompressTokenAccount:o,tokenProgram:u.tokenProgram,systemProgram:e.SystemProgram.programId});return g.push(...c),new e.TransactionInstruction({programId:this.programId,keys:g,data:d})}static async getMintProgramId(e,t){var r;return null===(r=await t.getAccountInfo(e))||void 0===r?void 0:r.owner}static async approve({payer:r,inputCompressedTokenAccounts:n,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const{inputTokenDataWithContext:u,remainingAccountMetas:c}=A({inputCompressedTokenAccounts:n,rootIndices:a,tokenTransferOutputs:[]}),{mint:d,currentOwner:h}=Ve(n),l=n[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?1:0,m=Ue({proof:s,mint:d,inputTokenDataWithContext:u,cpiContext:null,delegate:o,delegatedAmount:t.bn(i),delegateMerkleTreeIndex:l,changeAccountMerkleTreeIndex:l,delegateLamports:null}),{accountCompressionAuthority:p,noopProgram:f,registeredProgramPda:g,accountCompressionProgram:y}=t.defaultStaticAccountsStruct(),w=_e({feePayer:r,authority:h,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:g,noopProgram:f,accountCompressionAuthority:p,accountCompressionProgram:y,selfProgram:this.programId,systemProgram:e.SystemProgram.programId});return w.push(...c),new e.TransactionInstruction({programId:this.programId,keys:w,data:m})}static async revoke({payer:r,inputCompressedTokenAccounts:n,recentValidityProof:o,recentInputStateRootIndices:i}){Fe(n);const{inputTokenDataWithContext:s,remainingAccountMetas:a}=A({inputCompressedTokenAccounts:n,rootIndices:i,tokenTransferOutputs:[]}),{mint:u,currentOwner:c}=Ve(n),d=Ne({proof:o,mint:u,inputTokenDataWithContext:s,cpiContext:null,outputAccountMerkleTreeIndex:n[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?2:1}),{accountCompressionAuthority:h,noopProgram:l,registeredProgramPda:m,accountCompressionProgram:p}=t.defaultStaticAccountsStruct(),f=Oe({feePayer:r,authority:c,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:l,accountCompressionAuthority:h,accountCompressionProgram:p,selfProgram:this.programId,systemProgram:e.SystemProgram.programId});return f.push(...a),new e.TransactionInstruction({programId:this.programId,keys:f,data:d})}}He.programId=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");const Ge=Buffer.from([99,111,109,112,114,101,115,115,101,100,95,109,105,110,116]);function $e(r){const[n,o]=e.PublicKey.findProgramAddressSync([Ge,r.toBuffer()],t.COMPRESSED_TOKEN_PROGRAM_ID);return[n,o]}exports.ADD_TOKEN_POOL_DISCRIMINATOR=m,exports.APPROVE_DISCRIMINATOR=h,exports.BATCH_COMPRESS_DISCRIMINATOR=u,exports.COMPRESSED_MINT_SEED=Ge,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=d,exports.CPI_AUTHORITY_SEED=i,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=s,exports.CompressedTokenInstructionDataApproveLayout=Le,exports.CompressedTokenInstructionDataRevokeLayout=Re,exports.CompressedTokenInstructionDataTransferLayout=be,exports.CompressedTokenProgram=He,exports.CpiContextLayout=we,exports.DelegatedTransferLayout=ye,exports.ERROR_NO_ACCOUNTS_FOUND=v,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=a,exports.POOL_SEED=o,exports.REVOKE_DISCRIMINATOR=l,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TRANSFER_DISCRIMINATOR=c,exports.addTokenPoolAccountsLayout=xe,exports.addTokenPools=async function(e,r,n,o,i,s){s=s||await He.getMintProgramId(n,e);const a=[],u=(await f(e,n)).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 He.addTokenPool({mint:n,feePayer:r.publicKey,tokenProgramId:s,poolIndex:c[e]}));const{blockhash:d}=await e.getLatestBlockhash(),h=t.buildAndSignTx(a,r,d);return await t.sendAndConfirmTx(e,h,i)},exports.approve=async function(r,n,o,i,s,a,u){i=t.bn(i);const c=await r.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[d]=M(c.items,i),h=await r.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),l=await He.approve({payer:n.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:h.rootIndices,recentValidityProof:h.compressedProof}),{blockhash:m}=await r.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),l],n,m,p);return t.sendAndConfirmTx(r,f,u)},exports.approveAccountsLayout=_e,exports.approveAndMintTo=async function(r,o,i,s,a,u,c,d,h){c=null!=c?c:t.selectStateTreeInfo(await r.getStateTreeInfos()),d=null!=d?d:w(await f(r,i));const l=await n.getOrCreateAssociatedTokenAccount(r,o,i,a.publicKey,void 0,void 0,h,d.tokenProgram),m=await He.approveAndMintTo({feePayer:o.publicKey,mint:i,authority:a.publicKey,authorityTokenAccount:l.address,amount:u,toPubkey:s,outputStateTreeInfo:c,tokenPoolInfo:d}),{blockhash:p}=await r.getLatestBlockhash(),g=t.dedupeSigner(o,[a]),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4+2e4*t.toArray(u).length}),...m],o,p,g);return await t.sendAndConfirmTx(r,y,h)},exports.batchCompressLayout=Me,exports.checkMint=I,exports.checkTokenPoolInfo=p,exports.compress=async function(r,n,o,i,s,a,u,c,d,h){c=null!=c?c:t.selectStateTreeInfo(await r.getStateTreeInfos()),d=null!=d?d:w(await f(r,o));const l=await He.compress({payer:n.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:i,mint:o,outputStateTreeInfo:c,tokenPoolInfo:d}),m=await r.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:13e4+2e4*t.toArray(i).length}),l],n,m.blockhash,p);return await t.sendAndConfirmTx(r,g,h,m)},exports.compressSplTokenAccount=async function(r,n,o,i,s,a,u,c,d){u=null!=u?u:t.selectStateTreeInfo(await r.getStateTreeInfos()),c=null!=c?c:w(await f(r,o));const h=await He.compressSplTokenAccount({feePayer:n.publicKey,authority:i.publicKey,tokenAccount:s,mint:o,remainingAmount:a,outputStateTreeInfo:u,tokenPoolInfo:c}),l=await r.getLatestBlockhash(),m=t.dedupeSigner(n,[i]),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),h],n,l.blockhash,m);return await t.sendAndConfirmTx(r,p,d,l)},exports.compressSplTokenAccountInstructionDataLayout=Pe,exports.createDecompressOutputState=Ze,exports.createMint=async function(r,o,i,s,a=e.Keypair.generate(),u,c,d){const h=await r.getMinimumBalanceForRentExemption(n.MINT_SIZE),l=1==c?n.TOKEN_2022_PROGRAM_ID:c||n.TOKEN_PROGRAM_ID,m=await He.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:h,tokenProgramId:l}),{blockhash:p}=await r.getLatestBlockhash(),f=t.dedupeSigner(o,[i,d].filter((e=>null!=e&&"secretKey"in e))),g=t.buildAndSignTx(m,o,p,[...f,a]),y=await t.sendAndConfirmTx(r,g,u);return{mint:a.publicKey,transactionSignature:y}},exports.createTokenPool=async function(e,r,n,o,i){i=i||await He.getMintProgramId(n,e);const s=await He.createTokenPool({feePayer:r.publicKey,mint:n,tokenProgramId:i}),{blockhash:a}=await e.getLatestBlockhash(),u=t.buildAndSignTx([s],r,a);return await t.sendAndConfirmTx(e,u,o)},exports.createTokenPoolAccountsLayout=Te,exports.createTokenProgramLookupTable=async function(e,r,n,o,i){const s=await e.getSlot("finalized"),{instructions:a,address:u}=await He.createTokenProgramLookupTable({payer:r.publicKey,authority:n.publicKey,mints:o,remainingAccounts:i,recentSlot:s}),c=t.dedupeSigner(r,[n]),d=[];for(const n of a){const o=await e.getLatestBlockhash(),i=t.buildAndSignTx([n],r,o.blockhash,c),s=await t.sendAndConfirmTx(e,i,{commitment:"finalized"},o);d.push(s)}return{txIds:d,address:u}},exports.createTransferOutputState=ze,exports.decodeApproveInstructionData=function(e){const t=Le.decode(e.subarray(h.length));return Object.assign(Object.assign({},t),{proof:We(t.proof)?null:t.proof})},exports.decodeBatchCompressInstructionData=function(e){return Me.decode(e.subarray(u.length+4))},exports.decodeCompressSplTokenAccountInstructionData=function(e){const t=Pe.decode(e.subarray(d.length));return{owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext}},exports.decodeMintToInstructionData=function(e){return ve.decode(e.subarray(a.length))},exports.decodeRevokeInstructionData=function(e){const t=Re.decode(e.subarray(l.length));return Object.assign(Object.assign({},t),{proof:We(t.proof)?null:t.proof})},exports.decodeTransferInstructionData=function(e){return be.decode(e.slice(c.length+4))},exports.decompress=async function(r,n,o,i,s,a,u,c){i=t.bn(i);const d=await r.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[h]=P(d.items,i),l=await r.getValidityProofV0(h.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=b(u=null!=u?u:await f(r,o),i),p=await He.decompress({payer:n.publicKey,inputCompressedTokenAccounts:h,toAddress:a,amount:i,tokenPoolInfos:m,recentInputStateRootIndices:l.rootIndices,recentValidityProof:l.compressedProof}),{blockhash:g}=await r.getLatestBlockhash(),y=t.dedupeSigner(n,[s]),w=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),p],n,g,y);return await t.sendAndConfirmTx(r,w,c)},exports.decompressDelegated=async function(r,n,o,i,s,a,u,c){i=t.bn(i);const d=await r.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),[h]=P(d.items,i),l=await r.getValidityProofV0(h.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=null!=u?u:b(await f(r,o),i),p=await He.decompress({payer:n.publicKey,inputCompressedTokenAccounts:h,toAddress:a,amount:i,recentInputStateRootIndices:l.rootIndices,recentValidityProof:l.compressedProof,tokenPoolInfos:m}),{blockhash:g}=await r.getLatestBlockhash(),y=t.dedupeSigner(n,[s]),w=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),p],n,g,y);return t.sendAndConfirmTx(r,w,c)},exports.deriveCompressedMintAddress=function(e,r){const n=t.deriveAddressV2($e(e)[0].toBytes(),r.tree.toBytes(),t.COMPRESSED_TOKEN_PROGRAM_ID.toBytes());return Array.from(n)},exports.encodeApproveInstructionData=Ue,exports.encodeBatchCompressInstructionData=Se,exports.encodeCompressSplTokenAccountInstructionData=Ae,exports.encodeMintToInstructionData=ke,exports.encodeRevokeInstructionData=Ne,exports.encodeTransferInstructionData=Ie,exports.findMintAddress=$e,exports.freezeAccountsLayout=De,exports.getAssociatedCTokenAddress=function(r,n){return e.PublicKey.findProgramAddressSync([r.toBuffer(),t.COMPRESSED_TOKEN_PROGRAM_ID.toBuffer(),n.toBuffer()],t.COMPRESSED_TOKEN_PROGRAM_ID)[0]},exports.getAssociatedCTokenAddressAndBump=function(r,n){return e.PublicKey.findProgramAddressSync([r.toBuffer(),t.COMPRESSED_TOKEN_PROGRAM_ID.toBuffer(),n.toBuffer()],t.COMPRESSED_TOKEN_PROGRAM_ID)},exports.getTokenPoolInfos=f,exports.isSingleTokenPoolInfo=function(e){return!Array.isArray(e)},exports.mergeTokenAccounts=async function(r,n,o,i,s){const a=await r.getCompressedTokenAccountsByOwner(i.publicKey,{mint:o});if(0===a.items.length)throw new Error(`No compressed token accounts found for mint ${o.toBase58()}`);const u=[e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6})];for(let e=0;e<a.items.slice(0,8).length;e+=4){const s=a.items.slice(e,e+4),c=await r.getValidityProof(s.map((e=>t.bn(e.compressedAccount.hash)))),d=await He.mergeTokenAccounts({payer:n.publicKey,owner:i.publicKey,inputCompressedTokenAccounts:s,mint:o,recentValidityProof:c.compressedProof,recentInputStateRootIndices:c.rootIndices});u.push(...d)}const{blockhash:c}=await r.getLatestBlockhash(),d=t.dedupeSigner(n,[i]),h=t.buildAndSignTx(u,n,c,d);return t.sendAndConfirmTx(r,h,s)},exports.mintTo=async function(r,n,o,i,s,a,u,c,d){u=null!=u?u:t.selectStateTreeInfo(await r.getStateTreeInfos()),c=null!=c?c:w(await f(r,o));const h=await He.mintTo({feePayer:n.publicKey,mint:o,authority:s.publicKey,amount:a,toPubkey:i,outputStateTreeInfo:u,tokenPoolInfo:c}),{blockhash:l}=await r.getLatestBlockhash(),m=t.dedupeSigner(n,[s]),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),h],n,l,m);return t.sendAndConfirmTx(r,p,d)},exports.mintToAccountsLayout=Ce,exports.mintToLayout=ve,exports.packCompressedTokenAccounts=A,exports.parseMaybeDelegatedTransfer=je,exports.parseTokenData=Ve,exports.revoke=async function(r,n,o,i,s){const a=await r.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 He.revoke({payer:n.publicKey,inputCompressedTokenAccounts:o,recentInputStateRootIndices:a.rootIndices,recentValidityProof:a.compressedProof}),{blockhash:c}=await r.getLatestBlockhash(),d=t.dedupeSigner(n,[i]),h=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),u],n,c,d);return t.sendAndConfirmTx(r,h,s)},exports.revokeAccountsLayout=Oe,exports.selectMinCompressedTokenAccountsForDecompression=function(e,t,r=4){const[n,o,i,s]=P(e,t,r);return{selectedAccounts:n,total:o,totalLamports:i,maxPossibleAmount:s}},exports.selectMinCompressedTokenAccountsForTransfer=P,exports.selectMinCompressedTokenAccountsForTransferOrPartial=k,exports.selectSmartCompressedTokenAccountsForTransfer=function(e,r,n=4){const[o,i,s,a]=S(e,r,n);if(i.lt(t.bn(r))){const i=e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw o.length>=n?new Error(`Account limit exceeded: max ${a.toString()} (${n} accounts) per transaction. Total balance: ${i.toString()} (${e.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance. Required: ${r.toString()}, available: ${i.toString()}.`)}if(0===o.length)throw new Error(v);return[o,i,s,a]},exports.selectSmartCompressedTokenAccountsForTransferOrPartial=S,exports.selectTokenAccountsForApprove=M,exports.selectTokenPoolInfo=w,exports.selectTokenPoolInfosForDecompression=b,exports.sumUpTokenAmount=qe,exports.thawAccountsLayout=Be,exports.transfer=async function(r,n,o,i,s,a,u){i=t.bn(i);const c=await r.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),[d]=P(c.items,i),h=await r.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),l=await He.transfer({payer:n.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:h.rootIndices,recentValidityProof:h.compressedProof}),{blockhash:m}=await r.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),l],n,m,p);return t.sendAndConfirmTx(r,f,u)},exports.transferAccountsLayout=Ee,exports.transferDelegated=async function(r,n,o,i,s,a,u){i=t.bn(i);const c=await r.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),[d]=P(c.items,i),h=await r.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),l=await He.transfer({payer:n.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:h.rootIndices,recentValidityProof:h.compressedProof}),{blockhash:m}=await r.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),l],n,m,p);return t.sendAndConfirmTx(r,f,u)},exports.validateSameTokenOwner=Fe;
|
|
1
|
+
"use strict";var e=require("./types-CxnYquyR.cjs");require("@solana/web3.js"),require("@lightprotocol/stateless.js");var t=require("@solana/spl-token");require("buffer"),require("@coral-xyz/borsh"),exports.ADD_TOKEN_POOL_DISCRIMINATOR=e.ADD_TOKEN_POOL_DISCRIMINATOR,exports.APPROVE_DISCRIMINATOR=e.APPROVE_DISCRIMINATOR,Object.defineProperty(exports,"Action",{enumerable:1,get:function(){return e.Action}}),exports.BATCH_COMPRESS_DISCRIMINATOR=e.BATCH_COMPRESS_DISCRIMINATOR,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=e.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR,exports.CPI_AUTHORITY_SEED=e.CPI_AUTHORITY_SEED,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=e.CREATE_TOKEN_POOL_DISCRIMINATOR,exports.CompressedTokenInstructionDataApproveLayout=e.CompressedTokenInstructionDataApproveLayout,exports.CompressedTokenInstructionDataRevokeLayout=e.CompressedTokenInstructionDataRevokeLayout,exports.CompressedTokenInstructionDataTransferLayout=e.CompressedTokenInstructionDataTransferLayout,exports.CompressedTokenProgram=e.CompressedTokenProgram,exports.CpiContextLayout=e.CpiContextLayout,exports.DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR=e.DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR,exports.DelegatedTransferLayout=e.DelegatedTransferLayout,exports.ERROR_NO_ACCOUNTS_FOUND=e.ERROR_NO_ACCOUNTS_FOUND,Object.defineProperty(exports,"ExtensionType",{enumerable:1,get:function(){return e.ExtensionType}}),exports.IDL=e.IDL,exports.MINT_TO_DISCRIMINATOR=e.MINT_TO_DISCRIMINATOR,exports.POOL_SEED=e.POOL_SEED,exports.REVOKE_DISCRIMINATOR=e.REVOKE_DISCRIMINATOR,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=e.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE,exports.TRANSFER_DISCRIMINATOR=e.TRANSFER_DISCRIMINATOR,Object.defineProperty(exports,"TokenDataVersion",{enumerable:1,get:function(){return e.TokenDataVersion}}),exports.addSplInterfaces=e.addSplInterfaces,exports.addTokenPoolAccountsLayout=e.addTokenPoolAccountsLayout,exports.addTokenPools=e.addTokenPools,exports.approve=e.approve,exports.approveAccountsLayout=e.approveAccountsLayout,exports.approveAndMintTo=e.approveAndMintTo,exports.batchCompressLayout=e.batchCompressLayout,exports.calculateCompressibleLoadComputeUnits=e.calculateCompressibleLoadComputeUnits,exports.checkMint=e.checkMint,exports.checkSplInterfaceInfo=e.checkSplInterfaceInfo,exports.checkTokenPoolInfo=e.checkTokenPoolInfo,exports.compress=e.compress,exports.compressSplTokenAccount=e.compressSplTokenAccount,exports.compressSplTokenAccountInstructionDataLayout=e.compressSplTokenAccountInstructionDataLayout,exports.convertTokenDataToAccount=e.convertTokenDataToAccount,exports.createAssociatedCTokenAccountIdempotentInstruction=e.createAssociatedCTokenAccountIdempotentInstruction,exports.createAssociatedCTokenAccountInstruction=e.createAssociatedCTokenAccountInstruction,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=e.createAssociatedTokenAccountInterfaceIdempotentInstruction,exports.createAssociatedTokenAccountInterfaceInstruction=e.createAssociatedTokenAccountInterfaceInstruction,exports.createAtaInterface=e.createAtaInterface,exports.createAtaInterfaceIdempotent=e.createAtaInterfaceIdempotent,exports.createAtaInterfaceIdempotentInstruction=e.createAtaInterfaceIdempotentInstruction,exports.createCTokenTransferInstruction=e.createCTokenTransferInstruction,exports.createDecompressInterfaceInstruction=e.createDecompressInterfaceInstruction,exports.createDecompressOutputState=e.createDecompressOutputState,exports.createLoadAccountsParams=e.createLoadAccountsParams,exports.createLoadAtaInstructionsFromInterface=e.createLoadAtaInstructionsFromInterface,exports.createMint=e.createMint,exports.createMintInstruction=e.createMintInstruction,exports.createMintInterface=e.createMintInterface,exports.createMintToCompressedInstruction=e.createMintToCompressedInstruction,exports.createMintToInstruction=e.createMintToInstruction,exports.createMintToInterfaceInstruction=e.createMintToInterfaceInstruction,exports.createRemoveMetadataKeyInstruction=e.createRemoveMetadataKeyInstruction,exports.createSplInterface=e.createSplInterface,exports.createTokenMetadata=e.createTokenMetadata,exports.createTokenPool=e.createTokenPool,exports.createTokenPoolAccountsLayout=e.createTokenPoolAccountsLayout,exports.createTokenProgramLookupTable=e.createTokenProgramLookupTable,exports.createTransferInterfaceInstruction=e.createTransferInterfaceInstruction,exports.createTransferOutputState=e.createTransferOutputState,exports.createUpdateFreezeAuthorityInstruction=e.createUpdateFreezeAuthorityInstruction,exports.createUpdateMetadataAuthorityInstruction=e.createUpdateMetadataAuthorityInstruction,exports.createUpdateMetadataFieldInstruction=e.createUpdateMetadataFieldInstruction,exports.createUpdateMintAuthorityInstruction=e.createUpdateMintAuthorityInstruction,exports.createWrapInstruction=e.createWrapInstruction,exports.decodeApproveInstructionData=e.decodeApproveInstructionData,exports.decodeBatchCompressInstructionData=e.decodeBatchCompressInstructionData,exports.decodeCompressSplTokenAccountInstructionData=e.decodeCompressSplTokenAccountInstructionData,exports.decodeMintToInstructionData=e.decodeMintToInstructionData,exports.decodeRevokeInstructionData=e.decodeRevokeInstructionData,exports.decodeTokenMetadata=e.decodeTokenMetadata,exports.decodeTransferInstructionData=e.decodeTransferInstructionData,exports.decompress=e.decompress,exports.decompressDelegated=e.decompressDelegated,exports.decompressInterface=e.decompressInterface,exports.deriveSplInterfaceInfo=e.deriveSplInterfaceInfo,exports.deriveTokenPoolInfo=e.deriveTokenPoolInfo,exports.deserializeMint=e.deserializeMint,exports.encodeApproveInstructionData=e.encodeApproveInstructionData,exports.encodeBatchCompressInstructionData=e.encodeBatchCompressInstructionData,exports.encodeCompressSplTokenAccountInstructionData=e.encodeCompressSplTokenAccountInstructionData,exports.encodeMintToInstructionData=e.encodeMintToInstructionData,exports.encodeRevokeInstructionData=e.encodeRevokeInstructionData,exports.encodeTokenMetadata=e.encodeTokenMetadata,exports.encodeTransferInstructionData=e.encodeTransferInstructionData,exports.extractTokenMetadata=e.extractTokenMetadata,exports.freezeAccountsLayout=e.freezeAccountsLayout,exports.getAccountInterface=e.getAccountInterface,exports.getAssociatedTokenAddressInterface=e.getAssociatedTokenAddressInterface,exports.getMintInterface=e.getMintInterface,exports.getOrCreateAtaInterface=e.getOrCreateAtaInterface,exports.getSplInterfaceInfos=e.getSplInterfaceInfos,exports.getTokenPoolInfos=e.getTokenPoolInfos,exports.isSingleSplInterfaceInfo=e.isSingleSplInterfaceInfo,exports.isSingleTokenPoolInfo=e.isSingleTokenPoolInfo,exports.mergeTokenAccounts=e.mergeTokenAccounts,exports.mintTo=e.mintTo$1,exports.mintToAccountsLayout=e.mintToAccountsLayout,exports.mintToCToken=e.mintTo,exports.mintToCompressed=e.mintToCompressed,exports.mintToInterface=e.mintToInterface,exports.mintToLayout=e.mintToLayout,exports.packCompressedTokenAccounts=e.packCompressedTokenAccounts,exports.parseCTokenCold=e.parseCTokenCold,exports.parseCTokenHot=e.parseCTokenHot,exports.parseMaybeDelegatedTransfer=e.parseMaybeDelegatedTransfer,exports.parseTokenData=e.parseTokenData,exports.removeMetadataKey=e.removeMetadataKey,exports.revoke=e.revoke,exports.revokeAccountsLayout=e.revokeAccountsLayout,exports.selectMinCompressedTokenAccountsForDecompression=e.selectMinCompressedTokenAccountsForDecompression,exports.selectMinCompressedTokenAccountsForTransfer=e.selectMinCompressedTokenAccountsForTransfer,exports.selectMinCompressedTokenAccountsForTransferOrPartial=e.selectMinCompressedTokenAccountsForTransferOrPartial,exports.selectSmartCompressedTokenAccountsForTransfer=e.selectSmartCompressedTokenAccountsForTransfer,exports.selectSmartCompressedTokenAccountsForTransferOrPartial=e.selectSmartCompressedTokenAccountsForTransferOrPartial,exports.selectSplInterfaceInfo=e.selectSplInterfaceInfo,exports.selectSplInterfaceInfosForDecompression=e.selectSplInterfaceInfosForDecompression,exports.selectTokenAccountsForApprove=e.selectTokenAccountsForApprove,exports.selectTokenPoolInfo=e.selectTokenPoolInfo,exports.selectTokenPoolInfosForDecompression=e.selectTokenPoolInfosForDecompression,exports.serializeMint=e.serializeMint,exports.sumUpTokenAmount=e.sumUpTokenAmount,exports.thawAccountsLayout=e.thawAccountsLayout,exports.toAccountInfo=e.toAccountInfo,exports.toOffChainMetadataJson=e.toOffChainMetadataJson,exports.toTokenPoolInfo=e.toTokenPoolInfo,exports.transfer=e.transfer,exports.transferAccountsLayout=e.transferAccountsLayout,exports.transferDelegated=e.transferDelegated,exports.transferInterface=e.transferInterface,exports.unpackMintData=e.unpackMintData,exports.unpackMintInterface=e.unpackMintInterface,exports.updateFreezeAuthority=e.updateFreezeAuthority,exports.updateMetadataAuthority=e.updateMetadataAuthority,exports.updateMetadataField=e.updateMetadataField,exports.updateMintAuthority=e.updateMintAuthority,exports.validateSameTokenOwner=e.validateSameTokenOwner,exports.wrap=e.wrap,Object.defineProperty(exports,"AccountState",{enumerable:1,get:function(){return t.AccountState}}),exports.createLoadAtaInstructions=async function(t,o,r,n,s,a){return e.createLoadAtaInstructions(t,o,r,n,s,a,0)},exports.getAtaInterface=async function(t,o,r,n,s,a){return e.getAtaInterface(t,o,r,n,s,a)},exports.loadAta=async function(t,o,r,n,s,a,c){return e.loadAta(t,o,r,n,s,a,c,0)};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|