"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REPLACE_DEPOSIT_FOR_BURN_DISCRIMINATOR = void 0;
exports.getReplaceDepositForBurnDiscriminatorBytes = getReplaceDepositForBurnDiscriminatorBytes;
exports.getReplaceDepositForBurnInstructionDataEncoder = getReplaceDepositForBurnInstructionDataEncoder;
exports.getReplaceDepositForBurnInstructionDataDecoder = getReplaceDepositForBurnInstructionDataDecoder;
exports.getReplaceDepositForBurnInstructionDataCodec = getReplaceDepositForBurnInstructionDataCodec;
exports.getReplaceDepositForBurnInstruction = getReplaceDepositForBurnInstruction;
exports.parseReplaceDepositForBurnInstruction = parseReplaceDepositForBurnInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.REPLACE_DEPOSIT_FOR_BURN_DISCRIMINATOR = new Uint8Array([
    7, 27, 93, 132, 1, 80, 19, 163,
]);
function getReplaceDepositForBurnDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.REPLACE_DEPOSIT_FOR_BURN_DISCRIMINATOR);
}
function getReplaceDepositForBurnInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        [
            "originalMessage",
            (0, kit_1.addEncoderSizePrefix)((0, kit_1.getBytesEncoder)(), (0, kit_1.getU32Encoder)()),
        ],
        [
            "originalAttestation",
            (0, kit_1.addEncoderSizePrefix)((0, kit_1.getBytesEncoder)(), (0, kit_1.getU32Encoder)()),
        ],
        ["newDestinationCaller", (0, kit_1.getAddressEncoder)()],
        ["newMintRecipient", (0, kit_1.getAddressEncoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.REPLACE_DEPOSIT_FOR_BURN_DISCRIMINATOR })); });
}
function getReplaceDepositForBurnInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        [
            "originalMessage",
            (0, kit_1.addDecoderSizePrefix)((0, kit_1.getBytesDecoder)(), (0, kit_1.getU32Decoder)()),
        ],
        [
            "originalAttestation",
            (0, kit_1.addDecoderSizePrefix)((0, kit_1.getBytesDecoder)(), (0, kit_1.getU32Decoder)()),
        ],
        ["newDestinationCaller", (0, kit_1.getAddressDecoder)()],
        ["newMintRecipient", (0, kit_1.getAddressDecoder)()],
    ]);
}
function getReplaceDepositForBurnInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getReplaceDepositForBurnInstructionDataEncoder(), getReplaceDepositForBurnInstructionDataDecoder());
}
function getReplaceDepositForBurnInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
    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 = {
        owner: { value: (_b = input.owner) !== null && _b !== void 0 ? _b : null, isWritable: false },
        eventRentPayer: { value: (_c = input.eventRentPayer) !== null && _c !== void 0 ? _c : null, isWritable: true },
        senderAuthorityPda: {
            value: (_d = input.senderAuthorityPda) !== null && _d !== void 0 ? _d : null,
            isWritable: false,
        },
        messageTransmitter: {
            value: (_e = input.messageTransmitter) !== null && _e !== void 0 ? _e : null,
            isWritable: true,
        },
        tokenMessenger: { value: (_f = input.tokenMessenger) !== null && _f !== void 0 ? _f : null, isWritable: false },
        messageSentEventData: {
            value: (_g = input.messageSentEventData) !== null && _g !== void 0 ? _g : null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: (_h = input.messageTransmitterProgram) !== null && _h !== void 0 ? _h : null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: (_j = input.tokenMessengerMinterProgram) !== null && _j !== void 0 ? _j : null,
            isWritable: false,
        },
        systemProgram: { value: (_k = input.systemProgram) !== null && _k !== void 0 ? _k : null, isWritable: false },
        eventAuthority: { value: (_l = input.eventAuthority) !== null && _l !== void 0 ? _l : null, isWritable: false },
        program: { value: (_m = input.program) !== null && _m !== void 0 ? _m : null, isWritable: false },
    };
    var accounts = originalAccounts;
    var args = tslib_1.__assign({}, input);
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            "11111111111111111111111111111111";
    }
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.owner),
            getAccountMeta(accounts.eventRentPayer),
            getAccountMeta(accounts.senderAuthorityPda),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.messageTransmitterProgram),
            getAccountMeta(accounts.tokenMessengerMinterProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getReplaceDepositForBurnInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
function parseReplaceDepositForBurnInstruction(instruction) {
    if (instruction.accounts.length < 11) {
        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: {
            owner: getNextAccount(),
            eventRentPayer: getNextAccount(),
            senderAuthorityPda: getNextAccount(),
            messageTransmitter: getNextAccount(),
            tokenMessenger: getNextAccount(),
            messageSentEventData: getNextAccount(),
            messageTransmitterProgram: getNextAccount(),
            tokenMessengerMinterProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getReplaceDepositForBurnInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=replaceDepositForBurn.js.map