/** * 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, publicKey as publicKeySerializer, struct, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; // Accounts. export type SetDelegateInstructionAccounts = { /** The PDA of the OApp */ oapp: Signer; oappRegistry: PublicKey | Pda; eventAuthority: PublicKey | Pda; program: PublicKey | Pda; }; // Data. export type SetDelegateInstructionData = { discriminator: Uint8Array; delegate: PublicKey; }; export type SetDelegateInstructionDataArgs = { delegate: PublicKey }; export function getSetDelegateInstructionDataSerializer(): Serializer< SetDelegateInstructionDataArgs, SetDelegateInstructionData > { return mapSerializer< SetDelegateInstructionDataArgs, any, SetDelegateInstructionData >( struct( [ ['discriminator', bytes({ size: 8 })], ['delegate', publicKeySerializer()], ], { description: 'SetDelegateInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([242, 30, 46, 76, 108, 235, 128, 181]), }) ) as Serializer; } // Args. export type SetDelegateInstructionArgs = SetDelegateInstructionDataArgs; // Instruction. export function setDelegate( context: Pick, input: SetDelegateInstructionAccounts & SetDelegateInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'endpoint', '76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6' ); // Accounts. const resolvedAccounts = { oapp: { index: 0, isWritable: false as boolean, value: input.oapp ?? null }, oappRegistry: { index: 1, isWritable: true as boolean, value: input.oappRegistry ?? null, }, eventAuthority: { index: 2, isWritable: false as boolean, value: input.eventAuthority ?? null, }, program: { index: 3, isWritable: false as boolean, value: input.program ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: SetDelegateInstructionArgs = { ...input }; // 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 = getSetDelegateInstructionDataSerializer().serialize( resolvedArgs as SetDelegateInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }