"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.createAccount = exports.getCreateAccountInstructionDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const shared_1 = require("../shared");
function getCreateAccountInstructionDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['discriminator', (0, serializers_1.u32)()],
        ['lamports', (0, umi_1.mapAmountSerializer)((0, serializers_1.u64)(), 'SOL', 9)],
        ['space', (0, serializers_1.u64)()],
        ['programId', (0, serializers_1.publicKey)()],
    ], { description: 'CreateAccountInstructionData' }), (value) => ({ ...value, discriminator: 0 }));
}
exports.getCreateAccountInstructionDataSerializer = getCreateAccountInstructionDataSerializer;
// Instruction.
function createAccount(context, input) {
    // Program ID.
    const programId = context.programs.getPublicKey('splSystem', '11111111111111111111111111111111');
    // Accounts.
    const resolvedAccounts = {
        payer: { index: 0, isWritable: true, value: input.payer ?? null },
        newAccount: { index: 1, isWritable: true, value: input.newAccount ?? null },
    };
    // Arguments.
    const resolvedArgs = { ...input };
    // Default values.
    if (!resolvedAccounts.payer.value) {
        resolvedAccounts.payer.value = context.payer;
    }
    // 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 = getCreateAccountInstructionDataSerializer().serialize(resolvedArgs);
    // Bytes Created On Chain.
    const bytesCreatedOnChain = Number(input.space) + umi_1.ACCOUNT_HEADER_SIZE;
    return (0, umi_1.transactionBuilder)([
        { instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
    ]);
}
exports.createAccount = createAccount;
//# sourceMappingURL=createAccount.js.map