"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GET_NONCE_PDA_DISCRIMINATOR = void 0;
exports.getGetNoncePdaDiscriminatorBytes = getGetNoncePdaDiscriminatorBytes;
exports.getGetNoncePdaInstructionDataEncoder = getGetNoncePdaInstructionDataEncoder;
exports.getGetNoncePdaInstructionDataDecoder = getGetNoncePdaInstructionDataDecoder;
exports.getGetNoncePdaInstructionDataCodec = getGetNoncePdaInstructionDataCodec;
exports.getGetNoncePdaInstruction = getGetNoncePdaInstruction;
exports.parseGetNoncePdaInstruction = parseGetNoncePdaInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.GET_NONCE_PDA_DISCRIMINATOR = new Uint8Array([
    114, 70, 229, 212, 223, 50, 33, 39,
]);
function getGetNoncePdaDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.GET_NONCE_PDA_DISCRIMINATOR);
}
function getGetNoncePdaInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["nonce", (0, kit_1.getU64Encoder)()],
        ["sourceDomain", (0, kit_1.getU32Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.GET_NONCE_PDA_DISCRIMINATOR })); });
}
function getGetNoncePdaInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["nonce", (0, kit_1.getU64Decoder)()],
        ["sourceDomain", (0, kit_1.getU32Decoder)()],
    ]);
}
function getGetNoncePdaInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getGetNoncePdaInstructionDataEncoder(), getGetNoncePdaInstructionDataDecoder());
}
function getGetNoncePdaInstruction(input, config) {
    var _a, _b;
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : programs_1.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS;
    var originalAccounts = {
        messageTransmitter: {
            value: (_b = input.messageTransmitter) !== null && _b !== void 0 ? _b : null,
            isWritable: false,
        },
    };
    var accounts = originalAccounts;
    var args = tslib_1.__assign({}, input);
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [getAccountMeta(accounts.messageTransmitter)],
        data: getGetNoncePdaInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
function parseGetNoncePdaInstruction(instruction) {
    if (instruction.accounts.length < 1) {
        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: { messageTransmitter: getNextAccount() },
        data: getGetNoncePdaInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=getNoncePda.js.map