/** * 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, u64, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; import { Packet, PacketArgs, getPacketSerializer } from '../types'; // Accounts. export type SendWithLzTokenInstructionAccounts = { endpoint: Signer; uln: PublicKey | Pda; /** The custom send config account may be uninitialized, so deserialize it only if it's initialized */ sendConfig: PublicKey | Pda; defaultSendConfig: PublicKey | Pda; /** pay for the native fee */ payer?: Signer; /** for native fee transfer */ systemProgram?: PublicKey | Pda; /** The token account to pay the lz token fee */ lzTokenSource: PublicKey | Pda; /** The treasury token account to receive the lz token fee */ lzTokenTreasury: PublicKey | Pda; lzTokenMint: PublicKey | Pda; tokenProgram?: PublicKey | Pda; eventAuthority: PublicKey | Pda; program: PublicKey | Pda; }; // Data. export type SendWithLzTokenInstructionData = { discriminator: Uint8Array; packet: Packet; options: Uint8Array; nativeFee: bigint; lzTokenFee: bigint; lzTokenMint: PublicKey; }; export type SendWithLzTokenInstructionDataArgs = { packet: PacketArgs; options: Uint8Array; nativeFee: number | bigint; lzTokenFee: number | bigint; lzTokenMint: PublicKey; }; export function getSendWithLzTokenInstructionDataSerializer(): Serializer< SendWithLzTokenInstructionDataArgs, SendWithLzTokenInstructionData > { return mapSerializer< SendWithLzTokenInstructionDataArgs, any, SendWithLzTokenInstructionData >( struct( [ ['discriminator', bytes({ size: 8 })], ['packet', getPacketSerializer()], ['options', bytes({ size: u32() })], ['nativeFee', u64()], ['lzTokenFee', u64()], ['lzTokenMint', publicKeySerializer()], ], { description: 'SendWithLzTokenInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([165, 161, 84, 48, 129, 26, 193, 19]), }) ) as Serializer< SendWithLzTokenInstructionDataArgs, SendWithLzTokenInstructionData >; } // Args. export type SendWithLzTokenInstructionArgs = SendWithLzTokenInstructionDataArgs; // Instruction. export function sendWithLzToken( context: Pick, accounts: SendWithLzTokenInstructionAccounts, args: SendWithLzTokenInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'uln', '7a4WjyR8VZ7yZz5XJAKm39BUGn5iT9CKcv2pmG9tdXVH' ); // Accounts. const resolvedAccounts = { endpoint: { index: 0, isWritable: false as boolean, value: accounts.endpoint ?? null, }, uln: { index: 1, isWritable: false as boolean, value: accounts.uln ?? null, }, sendConfig: { index: 2, isWritable: false as boolean, value: accounts.sendConfig ?? null, }, defaultSendConfig: { index: 3, isWritable: false as boolean, value: accounts.defaultSendConfig ?? null, }, payer: { index: 4, isWritable: true as boolean, value: accounts.payer ?? null, }, systemProgram: { index: 5, isWritable: false as boolean, value: accounts.systemProgram ?? null, }, lzTokenSource: { index: 6, isWritable: true as boolean, value: accounts.lzTokenSource ?? null, }, lzTokenTreasury: { index: 7, isWritable: true as boolean, value: accounts.lzTokenTreasury ?? null, }, lzTokenMint: { index: 8, isWritable: false as boolean, value: accounts.lzTokenMint ?? null, }, tokenProgram: { index: 9, isWritable: false as boolean, value: accounts.tokenProgram ?? null, }, eventAuthority: { index: 10, isWritable: false as boolean, value: accounts.eventAuthority ?? null, }, program: { index: 11, isWritable: false as boolean, value: accounts.program ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: SendWithLzTokenInstructionArgs = { ...args }; // 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; } if (!resolvedAccounts.tokenProgram.value) { resolvedAccounts.tokenProgram.value = context.programs.getPublicKey( 'splToken', 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' ); resolvedAccounts.tokenProgram.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 = getSendWithLzTokenInstructionDataSerializer().serialize( resolvedArgs as SendWithLzTokenInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }