/** * 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 { YVAULTS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const INITIALIZE_COLLATERAL_INFO_DISCRIMINATOR = new Uint8Array([ 74, 61, 216, 76, 244, 91, 18, 119, ]); export function getInitializeCollateralInfoDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INITIALIZE_COLLATERAL_INFO_DISCRIMINATOR, ); } export type InitializeCollateralInfoInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta = string, TAccountGlobalConfig extends string | AccountMeta = string, TAccountCollInfo extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminAuthority extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdminAuthority, TAccountGlobalConfig extends string ? WritableAccount : TAccountGlobalConfig, TAccountCollInfo extends string ? WritableAccount : TAccountCollInfo, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type InitializeCollateralInfoInstructionData = { discriminator: ReadonlyUint8Array; }; export type InitializeCollateralInfoInstructionDataArgs = {}; export function getInitializeCollateralInfoInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: INITIALIZE_COLLATERAL_INFO_DISCRIMINATOR, }), ); } export function getInitializeCollateralInfoInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getInitializeCollateralInfoInstructionDataCodec(): FixedSizeCodec< InitializeCollateralInfoInstructionDataArgs, InitializeCollateralInfoInstructionData > { return combineCodec( getInitializeCollateralInfoInstructionDataEncoder(), getInitializeCollateralInfoInstructionDataDecoder(), ); } export type InitializeCollateralInfoInput< TAccountAdminAuthority extends string = string, TAccountGlobalConfig extends string = string, TAccountCollInfo extends string = string, TAccountSystemProgram extends string = string, > = { adminAuthority: TransactionSigner; globalConfig: Address; collInfo: Address; systemProgram?: Address; }; export function getInitializeCollateralInfoInstruction< TAccountAdminAuthority extends string, TAccountGlobalConfig extends string, TAccountCollInfo extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: InitializeCollateralInfoInput< TAccountAdminAuthority, TAccountGlobalConfig, TAccountCollInfo, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): InitializeCollateralInfoInstruction< TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountCollInfo, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: true }, globalConfig: { value: input.globalConfig ?? null, isWritable: true }, collInfo: { value: input.collInfo ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.adminAuthority), getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.collInfo), getAccountMeta(accounts.systemProgram), ], data: getInitializeCollateralInfoInstructionDataEncoder().encode({}), programAddress, } as InitializeCollateralInfoInstruction< TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountCollInfo, TAccountSystemProgram >); } export type ParsedInitializeCollateralInfoInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminAuthority: TAccountMetas[0]; globalConfig: TAccountMetas[1]; collInfo: TAccountMetas[2]; systemProgram: TAccountMetas[3]; }; data: InitializeCollateralInfoInstructionData; }; export function parseInitializeCollateralInfoInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializeCollateralInfoInstruction { if (instruction.accounts.length < 4) { // 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: { adminAuthority: getNextAccount(), globalConfig: getNextAccount(), collInfo: getNextAccount(), systemProgram: getNextAccount(), }, data: getInitializeCollateralInfoInstructionDataDecoder().decode( instruction.data, ), }; }