"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ADD_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = void 0;
exports.getAddRemoteTokenMessengerDiscriminatorBytes = getAddRemoteTokenMessengerDiscriminatorBytes;
exports.getAddRemoteTokenMessengerInstructionDataEncoder = getAddRemoteTokenMessengerInstructionDataEncoder;
exports.getAddRemoteTokenMessengerInstructionDataDecoder = getAddRemoteTokenMessengerInstructionDataDecoder;
exports.getAddRemoteTokenMessengerInstructionDataCodec = getAddRemoteTokenMessengerInstructionDataCodec;
exports.getAddRemoteTokenMessengerInstruction = getAddRemoteTokenMessengerInstruction;
exports.parseAddRemoteTokenMessengerInstruction = parseAddRemoteTokenMessengerInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.ADD_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = new Uint8Array([
    12, 149, 172, 165, 111, 202, 24, 33,
]);
function getAddRemoteTokenMessengerDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ADD_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR);
}
function getAddRemoteTokenMessengerInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["domain", (0, kit_1.getU32Encoder)()],
        ["tokenMessenger", (0, kit_1.getAddressEncoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.ADD_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR })); });
}
function getAddRemoteTokenMessengerInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["domain", (0, kit_1.getU32Decoder)()],
        ["tokenMessenger", (0, kit_1.getAddressDecoder)()],
    ]);
}
function getAddRemoteTokenMessengerInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getAddRemoteTokenMessengerInstructionDataEncoder(), getAddRemoteTokenMessengerInstructionDataDecoder());
}
function getAddRemoteTokenMessengerInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    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 = {
        payer: { value: (_b = input.payer) !== null && _b !== void 0 ? _b : null, isWritable: true },
        owner: { value: (_c = input.owner) !== null && _c !== void 0 ? _c : null, isWritable: false },
        tokenMessenger: { value: (_d = input.tokenMessenger) !== null && _d !== void 0 ? _d : null, isWritable: false },
        remoteTokenMessenger: {
            value: (_e = input.remoteTokenMessenger) !== null && _e !== void 0 ? _e : null,
            isWritable: true,
        },
        systemProgram: { value: (_f = input.systemProgram) !== null && _f !== void 0 ? _f : null, isWritable: false },
        eventAuthority: { value: (_g = input.eventAuthority) !== null && _g !== void 0 ? _g : null, isWritable: false },
        program: { value: (_h = input.program) !== null && _h !== void 0 ? _h : null, isWritable: false },
    };
    var accounts = originalAccounts;
    var args = tslib_1.__assign(tslib_1.__assign({}, input), { tokenMessenger: input.tokenMessengerArg });
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            "11111111111111111111111111111111";
    }
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.payer),
            getAccountMeta(accounts.owner),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getAddRemoteTokenMessengerInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
function parseAddRemoteTokenMessengerInstruction(instruction) {
    if (instruction.accounts.length < 7) {
        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: {
            payer: getNextAccount(),
            owner: getNextAccount(),
            tokenMessenger: getNextAccount(),
            remoteTokenMessenger: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getAddRemoteTokenMessengerInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=addRemoteTokenMessenger.js.map