"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.safeFetchAddressLookupTableFromSeeds = exports.fetchAddressLookupTableFromSeeds = exports.findAddressLookupTablePda = exports.getAddressLookupTableGpaBuilder = exports.safeFetchAllAddressLookupTable = exports.fetchAllAddressLookupTable = exports.safeFetchAddressLookupTable = exports.fetchAddressLookupTable = exports.deserializeAddressLookupTable = exports.getAddressLookupTableAccountDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
function getAddressLookupTableAccountDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['discriminator', (0, serializers_1.u32)()],
        ['deactivationSlot', (0, serializers_1.u64)()],
        ['lastExtendedSlot', (0, serializers_1.u64)()],
        ['lastExtendedStartIndex', (0, serializers_1.u8)()],
        ['authority', (0, serializers_1.option)((0, serializers_1.publicKey)(), { fixed: true })],
        ['padding', (0, serializers_1.u16)()],
        ['addresses', (0, serializers_1.array)((0, serializers_1.publicKey)(), { size: 'remainder' })],
    ], { description: 'AddressLookupTableAccountData' }), (value) => ({ ...value, discriminator: 1, padding: 0 }));
}
exports.getAddressLookupTableAccountDataSerializer = getAddressLookupTableAccountDataSerializer;
function deserializeAddressLookupTable(rawAccount) {
    return (0, umi_1.deserializeAccount)(rawAccount, getAddressLookupTableAccountDataSerializer());
}
exports.deserializeAddressLookupTable = deserializeAddressLookupTable;
async function fetchAddressLookupTable(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    (0, umi_1.assertAccountExists)(maybeAccount, 'AddressLookupTable');
    return deserializeAddressLookupTable(maybeAccount);
}
exports.fetchAddressLookupTable = fetchAddressLookupTable;
async function safeFetchAddressLookupTable(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    return maybeAccount.exists
        ? deserializeAddressLookupTable(maybeAccount)
        : null;
}
exports.safeFetchAddressLookupTable = safeFetchAddressLookupTable;
async function fetchAllAddressLookupTable(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts.map((maybeAccount) => {
        (0, umi_1.assertAccountExists)(maybeAccount, 'AddressLookupTable');
        return deserializeAddressLookupTable(maybeAccount);
    });
}
exports.fetchAllAddressLookupTable = fetchAllAddressLookupTable;
async function safeFetchAllAddressLookupTable(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts
        .filter((maybeAccount) => maybeAccount.exists)
        .map((maybeAccount) => deserializeAddressLookupTable(maybeAccount));
}
exports.safeFetchAllAddressLookupTable = safeFetchAllAddressLookupTable;
function getAddressLookupTableGpaBuilder(context) {
    const programId = context.programs.getPublicKey('splAddressLookupTable', 'AddressLookupTab1e1111111111111111111111111');
    return (0, umi_1.gpaBuilder)(context, programId)
        .registerFields({
        discriminator: [0, (0, serializers_1.u32)()],
        deactivationSlot: [4, (0, serializers_1.u64)()],
        lastExtendedSlot: [12, (0, serializers_1.u64)()],
        lastExtendedStartIndex: [20, (0, serializers_1.u8)()],
        authority: [21, (0, serializers_1.option)((0, serializers_1.publicKey)(), { fixed: true })],
        padding: [54, (0, serializers_1.u16)()],
        addresses: [56, (0, serializers_1.array)((0, serializers_1.publicKey)(), { size: 'remainder' })],
    })
        .deserializeUsing((account) => deserializeAddressLookupTable(account))
        .whereField('discriminator', 1);
}
exports.getAddressLookupTableGpaBuilder = getAddressLookupTableGpaBuilder;
function findAddressLookupTablePda(context, seeds) {
    const programId = context.programs.getPublicKey('splAddressLookupTable', 'AddressLookupTab1e1111111111111111111111111');
    return context.eddsa.findPda(programId, [
        (0, serializers_1.publicKey)().serialize(seeds.authority),
        (0, serializers_1.u64)().serialize(seeds.recentSlot),
    ]);
}
exports.findAddressLookupTablePda = findAddressLookupTablePda;
async function fetchAddressLookupTableFromSeeds(context, seeds, options) {
    return fetchAddressLookupTable(context, findAddressLookupTablePda(context, seeds), options);
}
exports.fetchAddressLookupTableFromSeeds = fetchAddressLookupTableFromSeeds;
async function safeFetchAddressLookupTableFromSeeds(context, seeds, options) {
    return safeFetchAddressLookupTable(context, findAddressLookupTablePda(context, seeds), options);
}
exports.safeFetchAddressLookupTableFromSeeds = safeFetchAddressLookupTableFromSeeds;
//# sourceMappingURL=addressLookupTable.js.map