UNPKG

@solanafm/explorer-kit

Version:
258 lines (245 loc) 9.13 kB
import { IdlType as IdlType$2, Idl as Idl$2 } from '@solanafm/kinobi-lite'; export { IdlError } from '@solanafm/kinobi-lite'; import { Idl, BorshAccountsCoder, BorshInstructionCoder, BorshEventCoder } from '@coral-xyz/anchor'; export { Event } from '@coral-xyz/anchor'; import { Idl as Idl$1, BorshAccountsCoder as BorshAccountsCoder$1, BorshEventCoder as BorshEventCoder$1, BorshInstructionCoder as BorshInstructionCoder$1 } from '@coral-xyz/anchor-new'; import { Serializer } from '@metaplex-foundation/umi'; type IdlEvent = { name: string; fields: IdlEventField[]; }; type IdlEventField = { name: string; type: IdlType$1; index: boolean; }; type IdlAccountItem = IdlAccount | IdlAccounts; declare function isIdlAccounts(accountItem: IdlAccountItem): accountItem is IdlAccounts; type IdlAccount = { name: string; isMut: boolean; isSigner: boolean; isOptional?: boolean; docs?: string[]; relations?: string[]; pda?: IdlPda; }; type IdlPda = { seeds: any[]; programId?: any; }; type IdlAccounts = { name: string; docs?: string[]; accounts: IdlAccountItem[]; }; type IdlField = { name: string; docs?: string[]; type: IdlType$1; }; type IdlType$1 = "bool" | "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "f32" | "u64" | "i64" | "f64" | "u128" | "i128" | "u256" | "i256" | "bytes" | "string" | "publicKey" | IdlTypeDefined$1 | IdlTypeOption$1 | IdlTypeCOption$1 | IdlTypeVec$1 | IdlTypeArray$1; type IdlTypeDefined$1 = { defined: string; }; type IdlTypeOption$1 = { option: IdlType$1; }; type IdlTypeCOption$1 = { coption: IdlType$1; }; type IdlTypeVec$1 = { vec: IdlType$1; }; type IdlTypeArray$1 = { array: [idlType: IdlType$1, size: number]; }; type IdlErrorCode = { code: number; name: string; msg?: string; }; type IdlArrayLen = IdlArrayLenGeneric | IdlArrayLenValue; type IdlArrayLenGeneric = { generic: string; }; type IdlArrayLenValue = number; type IdlGenericArg = IdlGenericArgType | IdlGenericArgConst; type IdlGenericArgType = { kind: "type"; type: IdlType; }; type IdlGenericArgConst = { kind: "const"; value: string; }; type IdlType = "bool" | "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "f32" | "u64" | "i64" | "f64" | "u128" | "i128" | "u256" | "i256" | "bytes" | "string" | "pubkey" | IdlTypeOption | IdlTypeCOption | IdlTypeVec | IdlTypeArray | IdlTypeDefined | IdlTypeGeneric; type IdlTypeOption = { option: IdlType; }; type IdlTypeCOption = { coption: IdlType; }; type IdlTypeVec = { vec: IdlType; }; type IdlTypeArray = { array: [idlType: IdlType, size: IdlArrayLen]; }; type IdlTypeDefined = { defined: { name: string; generics?: IdlGenericArg[]; }; }; type IdlTypeGeneric = { generic: string; }; type DataWithMappedType = { type: IdlType$2 | IdlType$1 | IdlType; data: any; }; declare const isDataWithMappedType: (data: any) => data is DataWithMappedType; /** * Represents an IDL item, which contains information about a Solana program's IDL. * TODO: Move to solanafm/basekit-core like EC-54 to have a unified types that will be used throughout the monorepo. */ interface IdlItem { /** The program ID of the Solana program. */ programId: string; /** The IDL of the Solana program, which can be an Anchor IDL, Shank IDL, or a string. */ idl: Idl | Idl$1 | Idl$2 | string; /** The type of IDL used by the Solana program. */ idlType: "anchor" | "anchorV1" | "shank" | "kinobi"; /** The version of the Solana program's IDL slot. */ idlSlotVersion?: number; /** The chain ID of the Solana program. */ chainId?: CHAIN_ID; } /** Enum representing the chain ID of a Solana Blockchain. */ declare enum CHAIN_ID { SOLANA_MAINNET = "solana-mainnet", SOLANA_DEVNET = "solana-devnet", SOLANA_TESTNET = "solana-testnet" } /** * @property instructionName - The instruction that the serializer is suppose to serialize * @property serializer - The serializer interface constructed by Kinobi */ type FMShankSerializer = { instructionName: string; serializer: ShankSerializer; }; type ShankSerializer = Serializer<any, any> | null; type ErrorParsers = Map<number, { name: string; msg: string; }>; interface ErrorParserInterface { errorsLayout: ErrorParsers; parseError(errorCode: string): ParserOutput; } declare enum ParserType { ACCOUNT = "account", INSTRUCTION = "instruction", EVENT = "event", ERROR = "error" } type Parser = AccountParserInterface | InstructionParserInterface | EventParserInterface | ErrorParserInterface | null; type ParserOutput = { name: string; data: any; type: ParserType; } | null; /** * Checks if the given parser is an InstructionParserInterface. * @param {Parser} parser - The parser to check. * @returns {boolean} - True if the parser is an InstructionParserInterface, false otherwise. */ declare const checkIfInstructionParser: (parser: Parser) => parser is InstructionParserInterface; /** * Checks if the given parser is an EventParserInterface. * @param {Parser} parser - The parser to check. * @returns {boolean} - True if the parser is an EventParserInterface, false otherwise. */ declare const checkIfEventParser: (parser: Parser) => parser is EventParserInterface; /** * Checks if the given parser is an ErrorParserInterface. * @param {Parser} parser - The parser to check. * @returns {boolean} - True if the parser is an ErrorParserInterface, false otherwise. */ declare const checkIfErrorsParser: (parser: Parser) => parser is ErrorParserInterface; /** * Checks if the given parser is an AccountParserInterface. * @param {Parser} parser - The parser to check. * @returns {boolean} - True if the parser is an AccountParserInterface, false otherwise. */ declare const checkIfAccountParser: (parser: Parser) => parser is AccountParserInterface; type AccountParsers = BorshAccountsCoder | BorshAccountsCoder$1 | Map<number | string, FMShankSerializer>; interface AccountParserInterface { accountLayouts: AccountParsers; parseAccount(accountData: string, mapTypes?: boolean): ParserOutput; getProgramName(): string; } type EventParsers = BorshInstructionCoder | BorshEventCoder | BorshEventCoder$1 | Map<number | string, FMShankSerializer>; interface EventParserInterface { eventsLayout: EventParsers; parseEvents(eventData: string, mapTypes?: boolean): ParserOutput; } type InstructionParsers = BorshInstructionCoder | BorshInstructionCoder$1 | Map<number | string, FMShankSerializer>; interface InstructionParserInterface { instructionsLayout: InstructionParsers; parseInstructions(instructionData: string, accountKeys?: string[], mapTypes?: boolean): ParserOutput; getProgramName(): string; } /** * Represents a SolanaFM Client to parse data in the Solana Blockchain. * @example * ```typescript * // Creates the client so that it can be used to create parsers * const parser = new SolanaFMParser(idl, programHash, accountHash) * // To create an account parser * const accountParser = parser.createParser(ParserType.ACCOUNT); * // To create an error parser * const errorParser = parser.createParser(ParserType.ERROR); * // To create an event parser * const eventParser = parser.createParser(ParserType.EVENT); * // To create an instruction parser * const instructionParser = parser.createParser(ParserType.INSTRUCTION); * ``` */ declare class SolanaFMParser { /** * The IDL item. */ private readonly idlItem; /** * The program hash. * @remarks For account parsing, this is also known as the owner of the account */ private readonly programHash; /** * The account hash. * @remarks This is optional because not all parsers require an account hash and it's only usable for parsing accounts such as sysvar accounts */ private readonly accountHash?; /** * Creates a new instance of the FMClient class. * @param idl The IDL that's to be used for initalizing the client. * @param programHash The program hash. * @param accountHash The account hash. */ constructor(idl: IdlItem, programHash: string, accountHash?: string); /** * Creates a parser based on the specified parser type. * @param parserType The parser type. * @returns A parser instance. */ createParser(parserType: ParserType): Parser; /** * Gets the program hash. * @returns The program hash. */ getProgramHash(): string; } export { AccountParserInterface, DataWithMappedType, ErrorParserInterface, EventParserInterface, IdlAccount, IdlAccountItem, IdlAccounts, IdlErrorCode, IdlEvent, IdlEventField, IdlField, IdlPda, IdlType$1 as IdlType, IdlTypeArray$1 as IdlTypeArray, IdlTypeCOption$1 as IdlTypeCOption, IdlTypeDefined$1 as IdlTypeDefined, IdlTypeOption$1 as IdlTypeOption, IdlTypeVec$1 as IdlTypeVec, InstructionParserInterface, Parser, ParserOutput, ParserType, SolanaFMParser, checkIfAccountParser, checkIfErrorsParser, checkIfEventParser, checkIfInstructionParser, isDataWithMappedType, isIdlAccounts };