/** * 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, Pda, PublicKey, Signer, TransactionBuilder, transactionBuilder, } from '@metaplex-foundation/umi'; import { Serializer, bytes, mapSerializer, struct, u32, u64, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; import { Packet, PacketArgs, getPacketSerializer } from '../types'; // Accounts. export type SendInstructionAccounts = { /** The message lib authority of the endpoint */ endpoint: Signer; /** receive the native fee */ messageLib: PublicKey | Pda; /** pay for the native fee */ payer?: Signer; /** for native fee transfer */ systemProgram?: PublicKey | Pda; }; // Data. export type SendInstructionData = { discriminator: Uint8Array; packet: Packet; options: Uint8Array; nativeFee: bigint; }; export type SendInstructionDataArgs = { packet: PacketArgs; options: Uint8Array; nativeFee: number | bigint; }; export function getSendInstructionDataSerializer(): Serializer< SendInstructionDataArgs, SendInstructionData > { return mapSerializer( struct( [ ['discriminator', bytes({ size: 8 })], ['packet', getPacketSerializer()], ['options', bytes({ size: u32() })], ['nativeFee', u64()], ], { description: 'SendInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([102, 251, 20, 187, 65, 75, 12, 69]), }) ) as Serializer; } // Args. export type SendInstructionArgs = SendInstructionDataArgs; // Instruction. export function send( context: Pick, input: SendInstructionAccounts & SendInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'simpleMessagelib', '6GsmxMTHAAiFKfemuM4zBjumTjNSX5CAiw4xSSXM2Toy' ); // Accounts. const resolvedAccounts = { endpoint: { index: 0, isWritable: false as boolean, value: input.endpoint ?? null, }, messageLib: { index: 1, isWritable: true as boolean, value: input.messageLib ?? null, }, payer: { index: 2, isWritable: true as boolean, value: input.payer ?? null, }, systemProgram: { index: 3, isWritable: false as boolean, value: input.systemProgram ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: SendInstructionArgs = { ...input }; // Default values. if (!resolvedAccounts.payer.value) { resolvedAccounts.payer.value = context.payer; } 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 = getSendInstructionDataSerializer().serialize( resolvedArgs as SendInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }