/** * 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/kinobi-so/kinobi */ import { Context, Option, OptionOrNullable, Pda, PublicKey, Signer, TransactionBuilder, transactionBuilder, } from '@metaplex-foundation/umi'; import { Serializer, bytes, mapSerializer, option, struct, u32, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; // Accounts. export type InitDefaultConfigInstructionAccounts = { admin: Signer; messageLib: PublicKey | Pda; sendConfig: PublicKey | Pda; receiveConfig: PublicKey | Pda; systemProgram?: PublicKey | Pda; }; // Data. export type InitDefaultConfigInstructionData = { discriminator: Uint8Array; eid: number; sendConfig: Option; receiveConfig: Option; }; export type InitDefaultConfigInstructionDataArgs = { eid: number; sendConfig: OptionOrNullable; receiveConfig: OptionOrNullable; }; export function getInitDefaultConfigInstructionDataSerializer(): Serializer< InitDefaultConfigInstructionDataArgs, InitDefaultConfigInstructionData > { return mapSerializer< InitDefaultConfigInstructionDataArgs, any, InitDefaultConfigInstructionData >( struct( [ ['discriminator', bytes({ size: 8 })], ['eid', u32()], ['sendConfig', option(bytes({ size: u32() }))], ['receiveConfig', option(bytes({ size: u32() }))], ], { description: 'InitDefaultConfigInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([98, 218, 197, 194, 173, 179, 112, 21]), }) ) as Serializer< InitDefaultConfigInstructionDataArgs, InitDefaultConfigInstructionData >; } // Args. export type InitDefaultConfigInstructionArgs = InitDefaultConfigInstructionDataArgs; // Instruction. export function initDefaultConfig( context: Pick, accounts: InitDefaultConfigInstructionAccounts, args: InitDefaultConfigInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'simpleMessagelib', '6GsmxMTHAAiFKfemuM4zBjumTjNSX5CAiw4xSSXM2Toy' ); // Accounts. const resolvedAccounts = { admin: { index: 0, isWritable: true as boolean, value: accounts.admin ?? null, }, messageLib: { index: 1, isWritable: false as boolean, value: accounts.messageLib ?? null, }, sendConfig: { index: 2, isWritable: true as boolean, value: accounts.sendConfig ?? null, }, receiveConfig: { index: 3, isWritable: true as boolean, value: accounts.receiveConfig ?? null, }, systemProgram: { index: 4, isWritable: false as boolean, value: accounts.systemProgram ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: InitDefaultConfigInstructionArgs = { ...args }; // Default values. if (!resolvedAccounts.systemProgram.value) { resolvedAccounts.systemProgram.value = context.programs.getPublicKey( 'splSystem', '11111111111111111111111111111111' ); resolvedAccounts.systemProgram.isWritable = false; } // Accounts in order. const orderedAccounts: ResolvedAccount[] = Object.values( resolvedAccounts ).sort((a, b) => a.index - b.index); // Keys and Signers. const [keys, signers] = getAccountMetasAndSigners( orderedAccounts, 'programId', programId ); // Data. const data = getInitDefaultConfigInstructionDataSerializer().serialize( resolvedArgs as InitDefaultConfigInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }