/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const TRANSFER_ADMIN_DISCRIMINATOR = new Uint8Array([ 42, 242, 66, 106, 228, 10, 111, 156, ]); export function getTransferAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( TRANSFER_ADMIN_DISCRIMINATOR, ); } export type TransferAdminInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountNewAdmin extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountNewAdmin extends string ? ReadonlyAccount : TAccountNewAdmin, TAccountPerpetuals extends string ? WritableAccount : TAccountPerpetuals, ...TRemainingAccounts, ] >; export type TransferAdminInstructionData = { discriminator: ReadonlyUint8Array; }; export type TransferAdminInstructionDataArgs = {}; export function getTransferAdminInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: TRANSFER_ADMIN_DISCRIMINATOR }), ); } export function getTransferAdminInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getTransferAdminInstructionDataCodec(): FixedSizeCodec< TransferAdminInstructionDataArgs, TransferAdminInstructionData > { return combineCodec( getTransferAdminInstructionDataEncoder(), getTransferAdminInstructionDataDecoder(), ); } export type TransferAdminInput< TAccountAdmin extends string = string, TAccountNewAdmin extends string = string, TAccountPerpetuals extends string = string, > = { admin: TransactionSigner; newAdmin: Address; perpetuals: Address; }; export function getTransferAdminInstruction< TAccountAdmin extends string, TAccountNewAdmin extends string, TAccountPerpetuals extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: TransferAdminInput< TAccountAdmin, TAccountNewAdmin, TAccountPerpetuals >, config?: { programAddress?: TProgramAddress }, ): TransferAdminInstruction< TProgramAddress, TAccountAdmin, TAccountNewAdmin, TAccountPerpetuals > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, newAdmin: { value: input.newAdmin ?? null, isWritable: false }, perpetuals: { value: input.perpetuals ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.newAdmin), getAccountMeta(accounts.perpetuals), ], data: getTransferAdminInstructionDataEncoder().encode({}), programAddress, } as TransferAdminInstruction< TProgramAddress, TAccountAdmin, TAccountNewAdmin, TAccountPerpetuals >); } export type ParsedTransferAdminInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; newAdmin: TAccountMetas[1]; perpetuals: TAccountMetas[2]; }; data: TransferAdminInstructionData; }; export function parseTransferAdminInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedTransferAdminInstruction { if (instruction.accounts.length < 3) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { admin: getNextAccount(), newAdmin: getNextAccount(), perpetuals: getNextAccount(), }, data: getTransferAdminInstructionDataDecoder().decode(instruction.data), }; }