"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR = void 0;
exports.getDepositForBurnWithHookDiscriminatorBytes = getDepositForBurnWithHookDiscriminatorBytes;
exports.getDepositForBurnWithHookInstructionDataEncoder = getDepositForBurnWithHookInstructionDataEncoder;
exports.getDepositForBurnWithHookInstructionDataDecoder = getDepositForBurnWithHookInstructionDataDecoder;
exports.getDepositForBurnWithHookInstructionDataCodec = getDepositForBurnWithHookInstructionDataCodec;
exports.getDepositForBurnWithHookInstructionAsync = getDepositForBurnWithHookInstructionAsync;
exports.getDepositForBurnWithHookInstruction = getDepositForBurnWithHookInstruction;
exports.parseDepositForBurnWithHookInstruction = parseDepositForBurnWithHookInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var pdas_1 = require("../pdas");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR = new Uint8Array([
    111, 245, 62, 131, 204, 108, 223, 155,
]);
function getDepositForBurnWithHookDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR);
}
function getDepositForBurnWithHookInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["amount", (0, kit_1.getU64Encoder)()],
        ["destinationDomain", (0, kit_1.getU32Encoder)()],
        ["mintRecipient", (0, kit_1.getAddressEncoder)()],
        ["destinationCaller", (0, kit_1.getAddressEncoder)()],
        ["maxFee", (0, kit_1.getU64Encoder)()],
        ["minFinalityThreshold", (0, kit_1.getU32Encoder)()],
        ["hookData", (0, kit_1.addEncoderSizePrefix)((0, kit_1.getBytesEncoder)(), (0, kit_1.getU32Encoder)())],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR })); });
}
function getDepositForBurnWithHookInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["amount", (0, kit_1.getU64Decoder)()],
        ["destinationDomain", (0, kit_1.getU32Decoder)()],
        ["mintRecipient", (0, kit_1.getAddressDecoder)()],
        ["destinationCaller", (0, kit_1.getAddressDecoder)()],
        ["maxFee", (0, kit_1.getU64Decoder)()],
        ["minFinalityThreshold", (0, kit_1.getU32Decoder)()],
        ["hookData", (0, kit_1.addDecoderSizePrefix)((0, kit_1.getBytesDecoder)(), (0, kit_1.getU32Decoder)())],
    ]);
}
function getDepositForBurnWithHookInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getDepositForBurnWithHookInstructionDataEncoder(), getDepositForBurnWithHookInstructionDataDecoder());
}
function getDepositForBurnWithHookInstructionAsync(input, config) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var programAddress, originalAccounts, accounts, args, _a, _b, _c, _d, getAccountMeta;
        var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
        return tslib_1.__generator(this, function (_z) {
            switch (_z.label) {
                case 0:
                    programAddress = (_e = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _e !== void 0 ? _e : programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
                    originalAccounts = {
                        owner: { value: (_f = input.owner) !== null && _f !== void 0 ? _f : null, isWritable: false },
                        eventRentPayer: { value: (_g = input.eventRentPayer) !== null && _g !== void 0 ? _g : null, isWritable: true },
                        senderAuthorityPda: {
                            value: (_h = input.senderAuthorityPda) !== null && _h !== void 0 ? _h : null,
                            isWritable: false,
                        },
                        burnTokenAccount: {
                            value: (_j = input.burnTokenAccount) !== null && _j !== void 0 ? _j : null,
                            isWritable: true,
                        },
                        denylistAccount: {
                            value: (_k = input.denylistAccount) !== null && _k !== void 0 ? _k : null,
                            isWritable: false,
                        },
                        messageTransmitter: {
                            value: (_l = input.messageTransmitter) !== null && _l !== void 0 ? _l : null,
                            isWritable: true,
                        },
                        tokenMessenger: { value: (_m = input.tokenMessenger) !== null && _m !== void 0 ? _m : null, isWritable: false },
                        remoteTokenMessenger: {
                            value: (_o = input.remoteTokenMessenger) !== null && _o !== void 0 ? _o : null,
                            isWritable: false,
                        },
                        tokenMinter: { value: (_p = input.tokenMinter) !== null && _p !== void 0 ? _p : null, isWritable: false },
                        localToken: { value: (_q = input.localToken) !== null && _q !== void 0 ? _q : null, isWritable: true },
                        burnTokenMint: { value: (_r = input.burnTokenMint) !== null && _r !== void 0 ? _r : null, isWritable: true },
                        messageSentEventData: {
                            value: (_s = input.messageSentEventData) !== null && _s !== void 0 ? _s : null,
                            isWritable: true,
                        },
                        messageTransmitterProgram: {
                            value: (_t = input.messageTransmitterProgram) !== null && _t !== void 0 ? _t : null,
                            isWritable: false,
                        },
                        tokenMessengerMinterProgram: {
                            value: (_u = input.tokenMessengerMinterProgram) !== null && _u !== void 0 ? _u : null,
                            isWritable: false,
                        },
                        tokenProgram: { value: (_v = input.tokenProgram) !== null && _v !== void 0 ? _v : null, isWritable: false },
                        systemProgram: { value: (_w = input.systemProgram) !== null && _w !== void 0 ? _w : null, isWritable: false },
                        eventAuthority: { value: (_x = input.eventAuthority) !== null && _x !== void 0 ? _x : null, isWritable: false },
                        program: { value: (_y = input.program) !== null && _y !== void 0 ? _y : null, isWritable: false },
                    };
                    accounts = originalAccounts;
                    args = tslib_1.__assign({}, input);
                    if (!!accounts.senderAuthorityPda.value) return [3, 2];
                    _a = accounts.senderAuthorityPda;
                    return [4, (0, pdas_1.findSenderAuthorityPdaPda)()];
                case 1:
                    _a.value = _z.sent();
                    _z.label = 2;
                case 2:
                    if (!!accounts.denylistAccount.value) return [3, 4];
                    _b = accounts.denylistAccount;
                    return [4, (0, pdas_1.findDenylistAccountPda)({
                            owner: (0, shared_1.expectAddress)(accounts.owner.value),
                        })];
                case 3:
                    _b.value = _z.sent();
                    _z.label = 4;
                case 4:
                    if (!!accounts.localToken.value) return [3, 6];
                    _c = accounts.localToken;
                    return [4, (0, pdas_1.findDepositForBurnLocalTokenPda)({
                            burnTokenMint: (0, shared_1.expectAddress)(accounts.burnTokenMint.value),
                        })];
                case 5:
                    _c.value = _z.sent();
                    _z.label = 6;
                case 6:
                    if (!accounts.messageTransmitterProgram.value) {
                        accounts.messageTransmitterProgram.value =
                            "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC";
                    }
                    if (!accounts.tokenMessengerMinterProgram.value) {
                        accounts.tokenMessengerMinterProgram.value =
                            "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe";
                    }
                    if (!accounts.tokenProgram.value) {
                        accounts.tokenProgram.value =
                            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
                    }
                    if (!accounts.systemProgram.value) {
                        accounts.systemProgram.value =
                            "11111111111111111111111111111111";
                    }
                    if (!!accounts.eventAuthority.value) return [3, 8];
                    _d = accounts.eventAuthority;
                    return [4, (0, pdas_1.findEventAuthorityPda)()];
                case 7:
                    _d.value = _z.sent();
                    _z.label = 8;
                case 8:
                    getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
                    return [2, Object.freeze({
                            accounts: [
                                getAccountMeta(accounts.owner),
                                getAccountMeta(accounts.eventRentPayer),
                                getAccountMeta(accounts.senderAuthorityPda),
                                getAccountMeta(accounts.burnTokenAccount),
                                getAccountMeta(accounts.denylistAccount),
                                getAccountMeta(accounts.messageTransmitter),
                                getAccountMeta(accounts.tokenMessenger),
                                getAccountMeta(accounts.remoteTokenMessenger),
                                getAccountMeta(accounts.tokenMinter),
                                getAccountMeta(accounts.localToken),
                                getAccountMeta(accounts.burnTokenMint),
                                getAccountMeta(accounts.messageSentEventData),
                                getAccountMeta(accounts.messageTransmitterProgram),
                                getAccountMeta(accounts.tokenMessengerMinterProgram),
                                getAccountMeta(accounts.tokenProgram),
                                getAccountMeta(accounts.systemProgram),
                                getAccountMeta(accounts.eventAuthority),
                                getAccountMeta(accounts.program),
                            ],
                            data: getDepositForBurnWithHookInstructionDataEncoder().encode(args),
                            programAddress: programAddress,
                        })];
            }
        });
    });
}
function getDepositForBurnWithHookInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : programs_1.TOKEN_MESSENGER_MINTER_V2_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,
        },
        burnTokenAccount: {
            value: (_e = input.burnTokenAccount) !== null && _e !== void 0 ? _e : null,
            isWritable: true,
        },
        denylistAccount: {
            value: (_f = input.denylistAccount) !== null && _f !== void 0 ? _f : null,
            isWritable: false,
        },
        messageTransmitter: {
            value: (_g = input.messageTransmitter) !== null && _g !== void 0 ? _g : null,
            isWritable: true,
        },
        tokenMessenger: { value: (_h = input.tokenMessenger) !== null && _h !== void 0 ? _h : null, isWritable: false },
        remoteTokenMessenger: {
            value: (_j = input.remoteTokenMessenger) !== null && _j !== void 0 ? _j : null,
            isWritable: false,
        },
        tokenMinter: { value: (_k = input.tokenMinter) !== null && _k !== void 0 ? _k : null, isWritable: false },
        localToken: { value: (_l = input.localToken) !== null && _l !== void 0 ? _l : null, isWritable: true },
        burnTokenMint: { value: (_m = input.burnTokenMint) !== null && _m !== void 0 ? _m : null, isWritable: true },
        messageSentEventData: {
            value: (_o = input.messageSentEventData) !== null && _o !== void 0 ? _o : null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: (_p = input.messageTransmitterProgram) !== null && _p !== void 0 ? _p : null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: (_q = input.tokenMessengerMinterProgram) !== null && _q !== void 0 ? _q : null,
            isWritable: false,
        },
        tokenProgram: { value: (_r = input.tokenProgram) !== null && _r !== void 0 ? _r : null, isWritable: false },
        systemProgram: { value: (_s = input.systemProgram) !== null && _s !== void 0 ? _s : null, isWritable: false },
        eventAuthority: { value: (_t = input.eventAuthority) !== null && _t !== void 0 ? _t : null, isWritable: false },
        program: { value: (_u = input.program) !== null && _u !== void 0 ? _u : null, isWritable: false },
    };
    var accounts = originalAccounts;
    var args = tslib_1.__assign({}, input);
    if (!accounts.messageTransmitterProgram.value) {
        accounts.messageTransmitterProgram.value =
            "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC";
    }
    if (!accounts.tokenMessengerMinterProgram.value) {
        accounts.tokenMessengerMinterProgram.value =
            "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe";
    }
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    }
    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.burnTokenAccount),
            getAccountMeta(accounts.denylistAccount),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.burnTokenMint),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.messageTransmitterProgram),
            getAccountMeta(accounts.tokenMessengerMinterProgram),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getDepositForBurnWithHookInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
function parseDepositForBurnWithHookInstruction(instruction) {
    if (instruction.accounts.length < 18) {
        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(),
            burnTokenAccount: getNextAccount(),
            denylistAccount: getNextAccount(),
            messageTransmitter: getNextAccount(),
            tokenMessenger: getNextAccount(),
            remoteTokenMessenger: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            burnTokenMint: getNextAccount(),
            messageSentEventData: getNextAccount(),
            messageTransmitterProgram: getNextAccount(),
            tokenMessengerMinterProgram: getNextAccount(),
            tokenProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getDepositForBurnWithHookInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=depositForBurnWithHook.js.map