"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REMOVE_LOCAL_TOKEN_DISCRIMINATOR = void 0;
exports.getRemoveLocalTokenDiscriminatorBytes = getRemoveLocalTokenDiscriminatorBytes;
exports.getRemoveLocalTokenInstructionDataEncoder = getRemoveLocalTokenInstructionDataEncoder;
exports.getRemoveLocalTokenInstructionDataDecoder = getRemoveLocalTokenInstructionDataDecoder;
exports.getRemoveLocalTokenInstructionDataCodec = getRemoveLocalTokenInstructionDataCodec;
exports.getRemoveLocalTokenInstruction = getRemoveLocalTokenInstruction;
exports.parseRemoveLocalTokenInstruction = parseRemoveLocalTokenInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.REMOVE_LOCAL_TOKEN_DISCRIMINATOR = new Uint8Array([
    27, 43, 66, 170, 188, 44, 109, 97,
]);
function getRemoveLocalTokenDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.REMOVE_LOCAL_TOKEN_DISCRIMINATOR);
}
function getRemoveLocalTokenInstructionDataEncoder() {
    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.REMOVE_LOCAL_TOKEN_DISCRIMINATOR })); });
}
function getRemoveLocalTokenInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getRemoveLocalTokenInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getRemoveLocalTokenInstructionDataEncoder(), getRemoveLocalTokenInstructionDataDecoder());
}
function getRemoveLocalTokenInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    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 = {
        payee: { value: (_b = input.payee) !== null && _b !== void 0 ? _b : null, isWritable: true },
        tokenController: {
            value: (_c = input.tokenController) !== null && _c !== void 0 ? _c : null,
            isWritable: false,
        },
        tokenMinter: { value: (_d = input.tokenMinter) !== null && _d !== void 0 ? _d : null, isWritable: false },
        localToken: { value: (_e = input.localToken) !== null && _e !== void 0 ? _e : null, isWritable: true },
        custodyTokenAccount: {
            value: (_f = input.custodyTokenAccount) !== null && _f !== void 0 ? _f : null,
            isWritable: true,
        },
        tokenProgram: { value: (_g = input.tokenProgram) !== null && _g !== void 0 ? _g : null, isWritable: false },
        eventAuthority: { value: (_h = input.eventAuthority) !== null && _h !== void 0 ? _h : null, isWritable: false },
        program: { value: (_j = input.program) !== null && _j !== void 0 ? _j : null, isWritable: false },
    };
    var accounts = originalAccounts;
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    }
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.payee),
            getAccountMeta(accounts.tokenController),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.custodyTokenAccount),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getRemoveLocalTokenInstructionDataEncoder().encode({}),
        programAddress: programAddress,
    });
}
function parseRemoveLocalTokenInstruction(instruction) {
    if (instruction.accounts.length < 8) {
        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: {
            payee: getNextAccount(),
            tokenController: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            custodyTokenAccount: getNextAccount(),
            tokenProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getRemoveLocalTokenInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=removeLocalToken.js.map