"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.safeFetchHolderDelegateRecordFromSeeds = exports.fetchHolderDelegateRecordFromSeeds = exports.findHolderDelegateRecordPda = exports.getHolderDelegateRecordSize = exports.getHolderDelegateRecordGpaBuilder = exports.safeFetchAllHolderDelegateRecord = exports.fetchAllHolderDelegateRecord = exports.safeFetchHolderDelegateRecord = exports.fetchHolderDelegateRecord = exports.deserializeHolderDelegateRecord = exports.getHolderDelegateRecordAccountDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const hooked_1 = require("../../hooked");
const types_1 = require("../types");
function getHolderDelegateRecordAccountDataSerializer() {
    return (0, serializers_1.struct)([
        ['key', (0, types_1.getKeySerializer)()],
        ['bump', (0, serializers_1.u8)()],
        ['mint', (0, serializers_1.publicKey)()],
        ['delegate', (0, serializers_1.publicKey)()],
        ['updateAuthority', (0, serializers_1.publicKey)()],
    ], { description: 'HolderDelegateRecordAccountData' });
}
exports.getHolderDelegateRecordAccountDataSerializer = getHolderDelegateRecordAccountDataSerializer;
function deserializeHolderDelegateRecord(rawAccount) {
    return (0, umi_1.deserializeAccount)(rawAccount, getHolderDelegateRecordAccountDataSerializer());
}
exports.deserializeHolderDelegateRecord = deserializeHolderDelegateRecord;
async function fetchHolderDelegateRecord(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    (0, umi_1.assertAccountExists)(maybeAccount, 'HolderDelegateRecord');
    return deserializeHolderDelegateRecord(maybeAccount);
}
exports.fetchHolderDelegateRecord = fetchHolderDelegateRecord;
async function safeFetchHolderDelegateRecord(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    return maybeAccount.exists
        ? deserializeHolderDelegateRecord(maybeAccount)
        : null;
}
exports.safeFetchHolderDelegateRecord = safeFetchHolderDelegateRecord;
async function fetchAllHolderDelegateRecord(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, 'HolderDelegateRecord');
        return deserializeHolderDelegateRecord(maybeAccount);
    });
}
exports.fetchAllHolderDelegateRecord = fetchAllHolderDelegateRecord;
async function safeFetchAllHolderDelegateRecord(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) => deserializeHolderDelegateRecord(maybeAccount));
}
exports.safeFetchAllHolderDelegateRecord = safeFetchAllHolderDelegateRecord;
function getHolderDelegateRecordGpaBuilder(context) {
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    return (0, umi_1.gpaBuilder)(context, programId)
        .registerFields({
        key: [0, (0, types_1.getKeySerializer)()],
        bump: [1, (0, serializers_1.u8)()],
        mint: [2, (0, serializers_1.publicKey)()],
        delegate: [34, (0, serializers_1.publicKey)()],
        updateAuthority: [66, (0, serializers_1.publicKey)()],
    })
        .deserializeUsing((account) => deserializeHolderDelegateRecord(account));
}
exports.getHolderDelegateRecordGpaBuilder = getHolderDelegateRecordGpaBuilder;
function getHolderDelegateRecordSize() {
    return 98;
}
exports.getHolderDelegateRecordSize = getHolderDelegateRecordSize;
function findHolderDelegateRecordPda(context, seeds) {
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    return context.eddsa.findPda(programId, [
        (0, serializers_1.string)({ size: 'variable' }).serialize('metadata'),
        (0, serializers_1.publicKey)().serialize(programId),
        (0, serializers_1.publicKey)().serialize(seeds.mint),
        (0, hooked_1.getHolderDelegateRoleSeedSerializer)().serialize(seeds.delegateRole),
        (0, serializers_1.publicKey)().serialize(seeds.owner),
        (0, serializers_1.publicKey)().serialize(seeds.delegate),
    ]);
}
exports.findHolderDelegateRecordPda = findHolderDelegateRecordPda;
async function fetchHolderDelegateRecordFromSeeds(context, seeds, options) {
    return fetchHolderDelegateRecord(context, findHolderDelegateRecordPda(context, seeds), options);
}
exports.fetchHolderDelegateRecordFromSeeds = fetchHolderDelegateRecordFromSeeds;
async function safeFetchHolderDelegateRecordFromSeeds(context, seeds, options) {
    return safeFetchHolderDelegateRecord(context, findHolderDelegateRecordPda(context, seeds), options);
}
exports.safeFetchHolderDelegateRecordFromSeeds = safeFetchHolderDelegateRecordFromSeeds;
//# sourceMappingURL=holderDelegateRecord.js.map