/** * 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, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from "@solana/kit"; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findProtocolPda } from "../pdas"; import { VOLTR_VAULT_PROGRAM_ADDRESS } from "../programs"; export const ACCEPT_PROTOCOL_ADMIN_DISCRIMINATOR = new Uint8Array([ 76, 35, 211, 183, 82, 72, 131, 36, ]); export function getAcceptProtocolAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ACCEPT_PROTOCOL_ADMIN_DISCRIMINATOR, ); } export type AcceptProtocolAdminInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountPendingAdmin extends string | AccountMeta = string, TAccountProtocol extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPendingAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPendingAdmin, TAccountProtocol extends string ? WritableAccount : TAccountProtocol, ...TRemainingAccounts, ] >; export type AcceptProtocolAdminInstructionData = { discriminator: ReadonlyUint8Array; }; export type AcceptProtocolAdminInstructionDataArgs = {}; export function getAcceptProtocolAdminInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: ACCEPT_PROTOCOL_ADMIN_DISCRIMINATOR, }), ); } export function getAcceptProtocolAdminInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getAcceptProtocolAdminInstructionDataCodec(): FixedSizeCodec< AcceptProtocolAdminInstructionDataArgs, AcceptProtocolAdminInstructionData > { return combineCodec( getAcceptProtocolAdminInstructionDataEncoder(), getAcceptProtocolAdminInstructionDataDecoder(), ); } export type AcceptProtocolAdminAsyncInput< TAccountPendingAdmin extends string = string, TAccountProtocol extends string = string, > = { pendingAdmin: TransactionSigner; protocol?: Address; }; export async function getAcceptProtocolAdminInstructionAsync< TAccountPendingAdmin extends string, TAccountProtocol extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: AcceptProtocolAdminAsyncInput, config?: { programAddress?: TProgramAddress }, ): Promise< AcceptProtocolAdminInstruction< TProgramAddress, TAccountPendingAdmin, TAccountProtocol > > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.protocol.value) { accounts.protocol.value = await findProtocolPda(); } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pendingAdmin", accounts.pendingAdmin), getAccountMeta("protocol", accounts.protocol), ], data: getAcceptProtocolAdminInstructionDataEncoder().encode({}), programAddress, } as AcceptProtocolAdminInstruction< TProgramAddress, TAccountPendingAdmin, TAccountProtocol >); } export type AcceptProtocolAdminInput< TAccountPendingAdmin extends string = string, TAccountProtocol extends string = string, > = { pendingAdmin: TransactionSigner; protocol: Address; }; export function getAcceptProtocolAdminInstruction< TAccountPendingAdmin extends string, TAccountProtocol extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: AcceptProtocolAdminInput, config?: { programAddress?: TProgramAddress }, ): AcceptProtocolAdminInstruction< TProgramAddress, TAccountPendingAdmin, TAccountProtocol > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pendingAdmin", accounts.pendingAdmin), getAccountMeta("protocol", accounts.protocol), ], data: getAcceptProtocolAdminInstructionDataEncoder().encode({}), programAddress, } as AcceptProtocolAdminInstruction< TProgramAddress, TAccountPendingAdmin, TAccountProtocol >); } export type ParsedAcceptProtocolAdminInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { pendingAdmin: TAccountMetas[0]; protocol: TAccountMetas[1]; }; data: AcceptProtocolAdminInstructionData; }; export function parseAcceptProtocolAdminInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedAcceptProtocolAdminInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { pendingAdmin: getNextAccount(), protocol: getNextAccount() }, data: getAcceptProtocolAdminInstructionDataDecoder().decode( instruction.data, ), }; }