/**
 * This code was AUTOGENERATED using the kinobi library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun kinobi to update it.
 *
 * @see https://github.com/metaplex-foundation/kinobi
 */

import { Address, containsBytes, getU32Encoder } from '@solana/web3.js';
import { ParsedCreateAccountInstruction } from '../instructions';

export const SYSTEM_PROGRAM_ADDRESS =
  '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;

export enum SystemInstruction {
  CreateAccount,
}

export function identifySystemInstruction(
  instruction: { data: Uint8Array } | Uint8Array
): SystemInstruction {
  const data =
    instruction instanceof Uint8Array ? instruction : instruction.data;
  if (containsBytes(data, getU32Encoder().encode(0), 0)) {
    return SystemInstruction.CreateAccount;
  }
  throw new Error(
    'The provided instruction could not be identified as a system instruction.'
  );
}

export type ParsedSystemInstruction<
  TProgram extends string = '11111111111111111111111111111111',
> = {
  instructionType: SystemInstruction.CreateAccount;
} & ParsedCreateAccountInstruction<TProgram>;
