"use strict";
/**
 * 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/metaplex-foundation/kinobi
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEmptyLut = exports.getCreateEmptyLutInstructionDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const accounts_1 = require("../accounts");
const shared_1 = require("../shared");
function getCreateEmptyLutInstructionDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['discriminator', (0, serializers_1.u32)()],
        ['recentSlot', (0, serializers_1.u64)()],
        ['bump', (0, serializers_1.u8)()],
    ], { description: 'CreateEmptyLutInstructionData' }), (value) => ({ ...value, discriminator: 0 }));
}
exports.getCreateEmptyLutInstructionDataSerializer = getCreateEmptyLutInstructionDataSerializer;
// Instruction.
function createEmptyLut(context, input) {
    // Program ID.
    const programId = context.programs.getPublicKey('splAddressLookupTable', 'AddressLookupTab1e1111111111111111111111111');
    // Accounts.
    const resolvedAccounts = {
        address: { index: 0, isWritable: true, value: input.address ?? null },
        authority: { index: 1, isWritable: false, value: input.authority ?? null },
        payer: { index: 2, isWritable: true, value: input.payer ?? null },
        systemProgram: {
            index: 3,
            isWritable: false,
            value: input.systemProgram ?? null,
        },
    };
    // Arguments.
    const resolvedArgs = { ...input };
    // Default values.
    if (!resolvedAccounts.authority.value) {
        resolvedAccounts.authority.value = context.identity;
    }
    if (!resolvedAccounts.address.value) {
        resolvedAccounts.address.value = (0, accounts_1.findAddressLookupTablePda)(context, {
            authority: (0, shared_1.expectPublicKey)(resolvedAccounts.authority.value),
            recentSlot: (0, shared_1.expectSome)(resolvedArgs.recentSlot),
        });
    }
    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 (!resolvedArgs.bump) {
        resolvedArgs.bump = (0, shared_1.expectPda)(resolvedAccounts.address.value)[1];
    }
    // Accounts in order.
    const orderedAccounts = Object.values(resolvedAccounts).sort((a, b) => a.index - b.index);
    // Keys and Signers.
    const [keys, signers] = (0, shared_1.getAccountMetasAndSigners)(orderedAccounts, 'programId', programId);
    // Data.
    const data = getCreateEmptyLutInstructionDataSerializer().serialize(resolvedArgs);
    // Bytes Created On Chain.
    const bytesCreatedOnChain = 56 + umi_1.ACCOUNT_HEADER_SIZE;
    return (0, umi_1.transactionBuilder)([
        { instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
    ]);
}
exports.createEmptyLut = createEmptyLut;
//# sourceMappingURL=createEmptyLut.js.map