/**
 * This code was AUTOGENERATED using the Codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun Codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */
import { __assign, __awaiter, __generator } from "tslib";
import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, transformEncoder, } from "@solana/kit";
import { findDenylistAccountPda, findDepositForBurnLocalTokenPda, findEventAuthorityPda, findSenderAuthorityPdaPda, } from "../pdas";
import { TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS } from "../programs";
import { expectAddress, getAccountMetaFactory, } from "../shared";
export var DEPOSIT_FOR_BURN_DISCRIMINATOR = new Uint8Array([
    215, 60, 61, 46, 114, 55, 128, 176,
]);
export function getDepositForBurnDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(DEPOSIT_FOR_BURN_DISCRIMINATOR);
}
export function getDepositForBurnInstructionDataEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["amount", getU64Encoder()],
        ["destinationDomain", getU32Encoder()],
        ["mintRecipient", getAddressEncoder()],
        ["destinationCaller", getAddressEncoder()],
        ["maxFee", getU64Encoder()],
        ["minFinalityThreshold", getU32Encoder()],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: DEPOSIT_FOR_BURN_DISCRIMINATOR })); });
}
export function getDepositForBurnInstructionDataDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["amount", getU64Decoder()],
        ["destinationDomain", getU32Decoder()],
        ["mintRecipient", getAddressDecoder()],
        ["destinationCaller", getAddressDecoder()],
        ["maxFee", getU64Decoder()],
        ["minFinalityThreshold", getU32Decoder()],
    ]);
}
export function getDepositForBurnInstructionDataCodec() {
    return combineCodec(getDepositForBurnInstructionDataEncoder(), getDepositForBurnInstructionDataDecoder());
}
export function getDepositForBurnInstructionAsync(input, config) {
    return __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 __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 : 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 = __assign({}, input);
                    if (!!accounts.senderAuthorityPda.value) return [3 /*break*/, 2];
                    _a = accounts.senderAuthorityPda;
                    return [4 /*yield*/, findSenderAuthorityPdaPda()];
                case 1:
                    _a.value = _z.sent();
                    _z.label = 2;
                case 2:
                    if (!!accounts.denylistAccount.value) return [3 /*break*/, 4];
                    _b = accounts.denylistAccount;
                    return [4 /*yield*/, findDenylistAccountPda({
                            owner: expectAddress(accounts.owner.value),
                        })];
                case 3:
                    _b.value = _z.sent();
                    _z.label = 4;
                case 4:
                    if (!!accounts.localToken.value) return [3 /*break*/, 6];
                    _c = accounts.localToken;
                    return [4 /*yield*/, findDepositForBurnLocalTokenPda({
                            burnTokenMint: 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 /*break*/, 8];
                    _d = accounts.eventAuthority;
                    return [4 /*yield*/, findEventAuthorityPda()];
                case 7:
                    _d.value = _z.sent();
                    _z.label = 8;
                case 8:
                    getAccountMeta = getAccountMetaFactory(programAddress, "programId");
                    return [2 /*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: getDepositForBurnInstructionDataEncoder().encode(args),
                            programAddress: programAddress,
                        })];
            }
        });
    });
}
export function getDepositForBurnInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
    // Program address.
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    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;
    // Original args.
    var args = __assign({}, input);
    // Resolve default values.
    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 = 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: getDepositForBurnInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
export function parseDepositForBurnInstruction(instruction) {
    if (instruction.accounts.length < 18) {
        // TODO: Coded error.
        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: getDepositForBurnInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=depositForBurn.js.map