"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ACCEPT_OWNERSHIP_DISCRIMINATOR = void 0;
exports.getAcceptOwnershipDiscriminatorBytes = getAcceptOwnershipDiscriminatorBytes;
exports.getAcceptOwnershipInstructionDataEncoder = getAcceptOwnershipInstructionDataEncoder;
exports.getAcceptOwnershipInstructionDataDecoder = getAcceptOwnershipInstructionDataDecoder;
exports.getAcceptOwnershipInstructionDataCodec = getAcceptOwnershipInstructionDataCodec;
exports.getAcceptOwnershipInstruction = getAcceptOwnershipInstruction;
exports.parseAcceptOwnershipInstruction = parseAcceptOwnershipInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.ACCEPT_OWNERSHIP_DISCRIMINATOR = new Uint8Array([
    172, 23, 43, 13, 238, 213, 85, 150,
]);
function getAcceptOwnershipDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ACCEPT_OWNERSHIP_DISCRIMINATOR);
}
function getAcceptOwnershipInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.ACCEPT_OWNERSHIP_DISCRIMINATOR })); });
}
function getAcceptOwnershipInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getAcceptOwnershipInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getAcceptOwnershipInstructionDataEncoder(), getAcceptOwnershipInstructionDataDecoder());
}
function getAcceptOwnershipInstruction(input, config) {
    var _a, _b, _c, _d, _e;
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : programs_1.TOKEN_MESSENGER_MINTER_PROGRAM_ADDRESS;
    var originalAccounts = {
        pendingOwner: { value: (_b = input.pendingOwner) !== null && _b !== void 0 ? _b : null, isWritable: false },
        tokenMessenger: { value: (_c = input.tokenMessenger) !== null && _c !== void 0 ? _c : null, isWritable: true },
        eventAuthority: { value: (_d = input.eventAuthority) !== null && _d !== void 0 ? _d : null, isWritable: false },
        program: { value: (_e = input.program) !== null && _e !== void 0 ? _e : null, isWritable: false },
    };
    var accounts = originalAccounts;
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.pendingOwner),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getAcceptOwnershipInstructionDataEncoder().encode({}),
        programAddress: programAddress,
    });
}
function parseAcceptOwnershipInstruction(instruction) {
    if (instruction.accounts.length < 4) {
        throw new Error("Not enough accounts");
    }
    var accountIndex = 0;
    var getNextAccount = function () {
        var accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            pendingOwner: getNextAccount(),
            tokenMessenger: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getAcceptOwnershipInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=acceptOwnership.js.map