1.1.0 • Published 18 days ago

@solanafm/explorer-kit v1.1.0

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
18 days ago

Features

  • 📦 Framework agnostic - Use it with any framework you want
  • ♻️ Space efficient - Reduce package size overhead as you don't have to generate SDKs for your project to use
  • 🧑‍💻 User friendly - Easy to use and understand

Getting Started

⚡️ Installation

Install ExplorerKit with these simple commands:

  • Use any package manager that you desire to install ExplorerKit

Using npm:

npm add @solanafm/explorer-kit
npm add @solanafm/explorer-kit-idls

Using yarn:

yarn add @solanafm/explorer-kit
yarn add @solanafm/explorer-kit-idls

Using pnpm:

pnpm add @solanafm/explorer-kit
pnpm add @solanafm/explorer-kit-idls

Once the packages have been installed, you can start using ExplorerKit in your project 🎉

🚀 Usage

How to get a SolanaFM IdlItem to start parsing a transaction or account state for a particular program:

import { getProgramIdl } from "@solanafm/explorer-kit-idls";

const programId = "PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY";
// Get the IDL for a specific program hash
const SFMIdlItem = await getProgramIdl(programId);
// You can also get an IDL at a specific slot context if you're trying to histroically parse a transaction / account
// but the IDL might not be backwards compatible.
const historicalSFMIdlItem = await getProgramIdl(programId, {
  slotContext: 132322893,
});

Parsing a transaction:

import { SolanaFMParser, checkIfInstructionParser, ParserType } from "@solanafm/explorer-kit";
import { getProgramIdl } from "@solanafm/explorer-kit-idls";

const programId = "PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY";
// Get the IDL for a specific program hash
const SFMIdlItem = await getProgramIdl(programId);
// You can also get an IDL at a specific slot context if you're trying to histroically parse a transaction / account
// but the IDL might not be backwards compatible.
const historicalSFMIdlItem = await getProgramIdl(programId, {
  slotContext: 132322893,
});
// For now, we only support parsing transactions with an encoded base 58 message
const ixData = "1AMTAauCh9UPEJKKd6LnGGtWqFvRs2aUZkv9r6wNe3PTzB1KS9TbwYzM8Cp7vUSDYZXTxXJp5M";
// Checks if SFMIdlItem is defined, if not you will not be able to initialize the parser layout
if (SFMIdlItem) {
  const parser = new SolanaFMParser(SFMIdlItem, programId);
  const instructionParser = parser.createParser(ParserType.INSTRUCTION);

  if (instructionParser && checkIfInstructionParser(instructionParser)) {
    // Parse the transaction
    const decodedData = instructionParser.parseInstructions(ixData);
  }
}

Parsing an event data:

import { SolanaFMParser. checkIfEventParser, ParserType } from "@solanafm/explorer-kit"

// For event data they have to base-64 encoded and they can be extracted from logs or a inner instruction with CPI logs.
// Phoenix Program Event Data
const eventData = "DwEABF2SDQAAAABDfDtlAAAAAKiVfA0AAAAAL9p3EN7QVm+wCbiCUn2jVyJyazsZQYgqVRhf6h2a/pX5SjR+9eBu2sQU7NYr1TEeH7vRFNOiXSyDLJ9g+fDJrwMAAgAABPzrK7CsLqR5NiVFXYwyp7QgatDNQXbn3JA8wOVXQfANFxMTAAAAAIB/AAAAAAAAg7MAAAAAAAAAAAAAAAAAAAIBAAT86yuwrC6keTYlRV2MMqe0IGrQzUF259yQPMDlV0HwDhcTEwAAAACCfwAAAAAAAByBAAAAAAAA6EwCAAAAAAAGAgAAAAAAAAAAAAAAAAAAAAAAnzQBAAAAAABzEb6ZAAAAALveBwAAAAAA"
const parser = new SolanaFMParser(SFMIdlItem);
const eventParser = parser.createParser(ParserType.EVENT);

if (eventParser && checkIfEventParser(eventParser)) {
    // Parse the transaction
    const decodedData = parser.parseEvents(eventData);
}

Parsing an account data:

import { SolanaFMParser, checkIfAccountParser, ParserType } from "@solanafm/explorer-kit";

const SFMIdlItem = await getProgramIdl(programId);

// Account data have to be base-64 encoded
// Stake Pool Account Data
const accountData =
  "AWq1iyr99ATwNekhxZcljopQjeBixmWt+p/5CTXBmRbd3Noj1MlCDU6CVh08awajdvCUB/G3tPyo/emrHFdD8Wfh4Pippvxf8kLk81F78B7Wst0ZUaC6ttlDVyWShgT3cP/LqkIDCUdVLBkThURwDuYX1RR+JyWBHNvgnIkDCm914o2jckW1NrCzDbv9Jn/RWcT0cAMYKm8U4SfG/F878wV0XwxEYxirEMlfQJSVhXDNBXRlpU2rFNnd40gahv7V/Mvj/aPav/vdTOwRdFALTRZQlijB9G5myz+0QWe7U7EGIQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpE2P1ZIWKAQDUAp5GdmQBAMkBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQJwAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAECcAAAAAAAAAAAAAAAAAAABWHWK1dGQBAAgnQqFYigEAv0rw1gHIAQAPfXpGLPQBABAnAAAAAAAAAAAAAAAAAAAAicd7jscBANVMdCNW7gEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";

const parser = new SolanaFMParser(SFMIdlItem);
const eventParser = parser.createParser(ParserType.ACCOUNT);

if (eventParser && checkIfAccountParser(eventParser)) {
  // Parse the transaction
  const decodedData = eventParser.parseAccount(accountData);
}

Once the data is parsed, the returned data type will look something like this

export type ParserOutput = {
  // The name of the struct that's being used to parse the data
  name: string;
  // The parsed data according to the IDL schema
  data: any;
  // ParserType depends on the type of parser you have initialized
  type: ParserType;
} | null;

More to be added soon...

You can also checkout the examples as well!

Caveats and Limitations

  • IDLs found in @solanafm/explorer-kit-idls are usually IDLs for programs that are immutable and are not expected to change. These IDLs can be imported directly from the package and used in your project without interacting with our API. If you wish to get the latest IDLs that might be on chain, getProgramIdl() will do a API call to our API to query for the relevant IDLs
  • Account and Event parsers only takes in a base64 encoded string at the moment
  • Instruction parsers only takes in a base58 encoded string at the moment

Supported Programs

Program IDsProgramWorking Parsers
11111111111111111111111111111111System ProgramAccount, Instructions
Config1111111111111111111111111111111111111Config ProgramAccount, Instructions
Stake11111111111111111111111111111111111111Stake ProgramAccount, Instructions
Vote111111111111111111111111111111111111111Vote ProgramAccount, Instructions
ComputeBudget111111111111111111111111111111Compute Budget ProgramInstructions
BPFLoaderUpgradeab1e11111111111111111111111BPF Upgradeable Loader ProgramAccount, Instructions
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAToken ProgramAccount, Instructions
TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEbToken 2022 ProgramAccount, Instructions, Extensions (built-in)
namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkXName Service ProgramAccount, Instructions
SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHyStake Pool ProgramAccount, Instructions
ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knLAssociated Token ProgramInstructions
PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXYPhoenix ProgramAccount, Instructions, Events
metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1sToken Metadata ProgramAccount, Instructions
auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmggToken Auth Rules ProgramInstructions
AddressLookupTab1e1111111111111111111111111Address Lookup TableAccount, Instructions
SysvarC1ock11111111111111111111111111111111Clock SysvarAccount
SysvarEpochSchedu1e111111111111111111111111Epoch Schedule SysvarAccount
SysvarFees111111111111111111111111111111111Fees SysvarAccount
SysvarRecentB1ockHashes11111111111111111111Recent Blockhashes SysvarAccount
SysvarRent111111111111111111111111111111111Rent SysvarAccount
SysvarRewards111111111111111111111111111111Rewards SysvarAccount
SysvarS1otHashes111111111111111111111111111Slot Hashes SysvarAccount
SysvarStakeHistory1111111111111111111111111Stake History SysvarAccount
MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNoMemo ProgramInstructions
cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCKSPL Account CompressionInstructions, Events
BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUYBubblegumInstructions, Events
TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDpTensor CompressionInstructions, Events

And many more programs that have their IDLs uploaded on chain. Feel free to contact anyone in the team or open a pull request to have your IDLs added to the list!

Credits

Explorer Kit is hugely inspired and built upon Kinobi. Without Kinobi, Explorer Kit would not have been possible at it's current iteration.

Also, huge thanks to the following projects and engineers for making this possible:

  • Loris - For all the work and help he has poured into Kinobi and Umi
  • Umi - Usage of their deserializers to decode the various data types
  • Kinobi - Kinobi parsing of IDLs to a Kinobi Tree has been a great inspiration in creating a layout to be stored in memory for deserialization
  • Anchor

Contributing

We welcome all contributions to Explorer Kit! Feel free to open a pull request or issues to discuss your ideas and suggestions. You may checkout our contributing guide for more information on how to contribute to Explorer Kit.

License

Explorer Kit is licensed under the GNU v3