/** * 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, u32, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; // Accounts. export type InitNonceInstructionAccounts = { /** only the delegate can initialize the nonce accounts */ delegate: Signer; oappRegistry: PublicKey | Pda; nonce: PublicKey | Pda; pendingInboundNonce: PublicKey | Pda; systemProgram?: PublicKey | Pda; }; // Data. export type InitNonceInstructionData = { discriminator: Uint8Array; localOapp: PublicKey; remoteEid: number; remoteOapp: Uint8Array; }; export type InitNonceInstructionDataArgs = { localOapp: PublicKey; remoteEid: number; remoteOapp: Uint8Array; }; export function getInitNonceInstructionDataSerializer(): Serializer< InitNonceInstructionDataArgs, InitNonceInstructionData > { return mapSerializer< InitNonceInstructionDataArgs, any, InitNonceInstructionData >( struct( [ ['discriminator', bytes({ size: 8 })], ['localOapp', publicKeySerializer()], ['remoteEid', u32()], ['remoteOapp', bytes({ size: 32 })], ], { description: 'InitNonceInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([204, 171, 16, 214, 182, 191, 27, 196]), }) ) as Serializer; } // Args. export type InitNonceInstructionArgs = InitNonceInstructionDataArgs; // Instruction. export function initNonce( context: Pick, input: InitNonceInstructionAccounts & InitNonceInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'endpoint', '76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6' ); // Accounts. const resolvedAccounts = { delegate: { index: 0, isWritable: true as boolean, value: input.delegate ?? null, }, oappRegistry: { index: 1, isWritable: false as boolean, value: input.oappRegistry ?? null, }, nonce: { index: 2, isWritable: true as boolean, value: input.nonce ?? null, }, pendingInboundNonce: { index: 3, isWritable: true as boolean, value: input.pendingInboundNonce ?? null, }, systemProgram: { index: 4, isWritable: false as boolean, value: input.systemProgram ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: InitNonceInstructionArgs = { ...input }; // 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 = getInitNonceInstructionDataSerializer().serialize( resolvedArgs as InitNonceInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }