/**
 * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from "@solana/kit";
import { findEventAuthorityPda, findMinimumDepositPda, findRentClaimPda, findRentFundPda, findStatePda, } from "../pdas";
import { SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS } from "../programs";
import { expectAddress, getAccountMetaFactory, } from "../shared";
import { getSponsoredCCTPQuoteDecoder, getSponsoredCCTPQuoteEncoder, } from "../types";
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)],
        ["quote", getSponsoredCCTPQuoteEncoder()],
        ["signature", fixEncoderSize(getBytesEncoder(), 65)],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: DEPOSIT_FOR_BURN_DISCRIMINATOR })); });
}
export function getDepositForBurnInstructionDataDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["quote", getSponsoredCCTPQuoteDecoder()],
        ["signature", fixDecoderSize(getBytesDecoder(), 65)],
    ]);
}
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, _e, _f, getAccountMeta;
        var _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
        return __generator(this, function (_6) {
            switch (_6.label) {
                case 0:
                    programAddress = (_g = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _g !== void 0 ? _g : SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
                    originalAccounts = {
                        signer: { value: (_h = input.signer) !== null && _h !== void 0 ? _h : null, isWritable: true },
                        state: { value: (_j = input.state) !== null && _j !== void 0 ? _j : null, isWritable: false },
                        rentFund: { value: (_k = input.rentFund) !== null && _k !== void 0 ? _k : null, isWritable: true },
                        minimumDeposit: { value: (_l = input.minimumDeposit) !== null && _l !== void 0 ? _l : null, isWritable: false },
                        usedNonce: { value: (_m = input.usedNonce) !== null && _m !== void 0 ? _m : null, isWritable: true },
                        rentClaim: { value: (_o = input.rentClaim) !== null && _o !== void 0 ? _o : null, isWritable: true },
                        depositorTokenAccount: {
                            value: (_p = input.depositorTokenAccount) !== null && _p !== void 0 ? _p : null,
                            isWritable: true,
                        },
                        burnToken: { value: (_q = input.burnToken) !== null && _q !== void 0 ? _q : null, isWritable: true },
                        denylistAccount: {
                            value: (_r = input.denylistAccount) !== null && _r !== void 0 ? _r : null,
                            isWritable: false,
                        },
                        tokenMessengerMinterSenderAuthority: {
                            value: (_s = input.tokenMessengerMinterSenderAuthority) !== null && _s !== void 0 ? _s : null,
                            isWritable: false,
                        },
                        messageTransmitter: {
                            value: (_t = input.messageTransmitter) !== null && _t !== void 0 ? _t : null,
                            isWritable: true,
                        },
                        tokenMessenger: { value: (_u = input.tokenMessenger) !== null && _u !== void 0 ? _u : null, isWritable: false },
                        remoteTokenMessenger: {
                            value: (_v = input.remoteTokenMessenger) !== null && _v !== void 0 ? _v : null,
                            isWritable: false,
                        },
                        tokenMinter: { value: (_w = input.tokenMinter) !== null && _w !== void 0 ? _w : null, isWritable: false },
                        localToken: { value: (_x = input.localToken) !== null && _x !== void 0 ? _x : null, isWritable: true },
                        cctpEventAuthority: {
                            value: (_y = input.cctpEventAuthority) !== null && _y !== void 0 ? _y : null,
                            isWritable: false,
                        },
                        messageSentEventData: {
                            value: (_z = input.messageSentEventData) !== null && _z !== void 0 ? _z : null,
                            isWritable: true,
                        },
                        messageTransmitterProgram: {
                            value: (_0 = input.messageTransmitterProgram) !== null && _0 !== void 0 ? _0 : null,
                            isWritable: false,
                        },
                        tokenMessengerMinterProgram: {
                            value: (_1 = input.tokenMessengerMinterProgram) !== null && _1 !== void 0 ? _1 : null,
                            isWritable: false,
                        },
                        tokenProgram: { value: (_2 = input.tokenProgram) !== null && _2 !== void 0 ? _2 : null, isWritable: false },
                        systemProgram: { value: (_3 = input.systemProgram) !== null && _3 !== void 0 ? _3 : null, isWritable: false },
                        eventAuthority: { value: (_4 = input.eventAuthority) !== null && _4 !== void 0 ? _4 : null, isWritable: false },
                        program: { value: (_5 = input.program) !== null && _5 !== void 0 ? _5 : null, isWritable: false },
                    };
                    accounts = originalAccounts;
                    args = __assign({}, input);
                    if (!!accounts.state.value) return [3 /*break*/, 2];
                    _a = accounts.state;
                    return [4 /*yield*/, findStatePda()];
                case 1:
                    _a.value = _6.sent();
                    _6.label = 2;
                case 2:
                    if (!!accounts.rentFund.value) return [3 /*break*/, 4];
                    _b = accounts.rentFund;
                    return [4 /*yield*/, findRentFundPda()];
                case 3:
                    _b.value = _6.sent();
                    _6.label = 4;
                case 4:
                    if (!!accounts.minimumDeposit.value) return [3 /*break*/, 6];
                    _c = accounts.minimumDeposit;
                    return [4 /*yield*/, findMinimumDepositPda({
                            burnToken: expectAddress(accounts.burnToken.value),
                        })];
                case 5:
                    _c.value = _6.sent();
                    _6.label = 6;
                case 6:
                    if (!!accounts.rentClaim.value) return [3 /*break*/, 8];
                    _d = accounts.rentClaim;
                    return [4 /*yield*/, findRentClaimPda({
                            signer: expectAddress(accounts.signer.value),
                        })];
                case 7:
                    _d.value = _6.sent();
                    _6.label = 8;
                case 8:
                    if (!accounts.tokenProgram.value) {
                        accounts.tokenProgram.value =
                            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
                    }
                    if (!!accounts.depositorTokenAccount.value) return [3 /*break*/, 10];
                    _e = accounts.depositorTokenAccount;
                    return [4 /*yield*/, getProgramDerivedAddress({
                            programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
                            seeds: [
                                getAddressEncoder().encode(expectAddress(accounts.signer.value)),
                                getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
                                getAddressEncoder().encode(expectAddress(accounts.burnToken.value)),
                            ],
                        })];
                case 9:
                    _e.value = _6.sent();
                    _6.label = 10;
                case 10:
                    if (!accounts.messageTransmitterProgram.value) {
                        accounts.messageTransmitterProgram.value =
                            "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC";
                    }
                    if (!accounts.tokenMessengerMinterProgram.value) {
                        accounts.tokenMessengerMinterProgram.value =
                            "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe";
                    }
                    if (!accounts.systemProgram.value) {
                        accounts.systemProgram.value =
                            "11111111111111111111111111111111";
                    }
                    if (!!accounts.eventAuthority.value) return [3 /*break*/, 12];
                    _f = accounts.eventAuthority;
                    return [4 /*yield*/, findEventAuthorityPda()];
                case 11:
                    _f.value = _6.sent();
                    _6.label = 12;
                case 12:
                    getAccountMeta = getAccountMetaFactory(programAddress, "programId");
                    return [2 /*return*/, Object.freeze({
                            accounts: [
                                getAccountMeta(accounts.signer),
                                getAccountMeta(accounts.state),
                                getAccountMeta(accounts.rentFund),
                                getAccountMeta(accounts.minimumDeposit),
                                getAccountMeta(accounts.usedNonce),
                                getAccountMeta(accounts.rentClaim),
                                getAccountMeta(accounts.depositorTokenAccount),
                                getAccountMeta(accounts.burnToken),
                                getAccountMeta(accounts.denylistAccount),
                                getAccountMeta(accounts.tokenMessengerMinterSenderAuthority),
                                getAccountMeta(accounts.messageTransmitter),
                                getAccountMeta(accounts.tokenMessenger),
                                getAccountMeta(accounts.remoteTokenMessenger),
                                getAccountMeta(accounts.tokenMinter),
                                getAccountMeta(accounts.localToken),
                                getAccountMeta(accounts.cctpEventAuthority),
                                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, _v, _w, _x, _y, _z;
    // Program address.
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    // Original accounts.
    var originalAccounts = {
        signer: { value: (_b = input.signer) !== null && _b !== void 0 ? _b : null, isWritable: true },
        state: { value: (_c = input.state) !== null && _c !== void 0 ? _c : null, isWritable: false },
        rentFund: { value: (_d = input.rentFund) !== null && _d !== void 0 ? _d : null, isWritable: true },
        minimumDeposit: { value: (_e = input.minimumDeposit) !== null && _e !== void 0 ? _e : null, isWritable: false },
        usedNonce: { value: (_f = input.usedNonce) !== null && _f !== void 0 ? _f : null, isWritable: true },
        rentClaim: { value: (_g = input.rentClaim) !== null && _g !== void 0 ? _g : null, isWritable: true },
        depositorTokenAccount: {
            value: (_h = input.depositorTokenAccount) !== null && _h !== void 0 ? _h : null,
            isWritable: true,
        },
        burnToken: { value: (_j = input.burnToken) !== null && _j !== void 0 ? _j : null, isWritable: true },
        denylistAccount: {
            value: (_k = input.denylistAccount) !== null && _k !== void 0 ? _k : null,
            isWritable: false,
        },
        tokenMessengerMinterSenderAuthority: {
            value: (_l = input.tokenMessengerMinterSenderAuthority) !== null && _l !== void 0 ? _l : null,
            isWritable: false,
        },
        messageTransmitter: {
            value: (_m = input.messageTransmitter) !== null && _m !== void 0 ? _m : null,
            isWritable: true,
        },
        tokenMessenger: { value: (_o = input.tokenMessenger) !== null && _o !== void 0 ? _o : null, isWritable: false },
        remoteTokenMessenger: {
            value: (_p = input.remoteTokenMessenger) !== null && _p !== void 0 ? _p : null,
            isWritable: false,
        },
        tokenMinter: { value: (_q = input.tokenMinter) !== null && _q !== void 0 ? _q : null, isWritable: false },
        localToken: { value: (_r = input.localToken) !== null && _r !== void 0 ? _r : null, isWritable: true },
        cctpEventAuthority: {
            value: (_s = input.cctpEventAuthority) !== null && _s !== void 0 ? _s : null,
            isWritable: false,
        },
        messageSentEventData: {
            value: (_t = input.messageSentEventData) !== null && _t !== void 0 ? _t : null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: (_u = input.messageTransmitterProgram) !== null && _u !== void 0 ? _u : null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: (_v = input.tokenMessengerMinterProgram) !== null && _v !== void 0 ? _v : null,
            isWritable: false,
        },
        tokenProgram: { value: (_w = input.tokenProgram) !== null && _w !== void 0 ? _w : null, isWritable: false },
        systemProgram: { value: (_x = input.systemProgram) !== null && _x !== void 0 ? _x : null, isWritable: false },
        eventAuthority: { value: (_y = input.eventAuthority) !== null && _y !== void 0 ? _y : null, isWritable: false },
        program: { value: (_z = input.program) !== null && _z !== void 0 ? _z : null, isWritable: false },
    };
    var accounts = originalAccounts;
    // Original args.
    var args = __assign({}, input);
    // Resolve default values.
    if (!accounts.tokenProgram.value) {
        accounts.tokenProgram.value =
            "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    }
    if (!accounts.messageTransmitterProgram.value) {
        accounts.messageTransmitterProgram.value =
            "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC";
    }
    if (!accounts.tokenMessengerMinterProgram.value) {
        accounts.tokenMessengerMinterProgram.value =
            "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe";
    }
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            "11111111111111111111111111111111";
    }
    var getAccountMeta = getAccountMetaFactory(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.signer),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.rentFund),
            getAccountMeta(accounts.minimumDeposit),
            getAccountMeta(accounts.usedNonce),
            getAccountMeta(accounts.rentClaim),
            getAccountMeta(accounts.depositorTokenAccount),
            getAccountMeta(accounts.burnToken),
            getAccountMeta(accounts.denylistAccount),
            getAccountMeta(accounts.tokenMessengerMinterSenderAuthority),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.cctpEventAuthority),
            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 < 23) {
        // TODO: Coded error.
        throw new Error("Not enough accounts");
    }
    var accountIndex = 0;
    var getNextAccount = function () {
        var accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    var getNextOptionalAccount = function () {
        var accountMeta = getNextAccount();
        return accountMeta.address === SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS
            ? undefined
            : accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            signer: getNextAccount(),
            state: getNextAccount(),
            rentFund: getNextAccount(),
            minimumDeposit: getNextAccount(),
            usedNonce: getNextAccount(),
            rentClaim: getNextOptionalAccount(),
            depositorTokenAccount: getNextAccount(),
            burnToken: getNextAccount(),
            denylistAccount: getNextAccount(),
            tokenMessengerMinterSenderAuthority: getNextAccount(),
            messageTransmitter: getNextAccount(),
            tokenMessenger: getNextAccount(),
            remoteTokenMessenger: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            cctpEventAuthority: getNextAccount(),
            messageSentEventData: getNextAccount(),
            messageTransmitterProgram: getNextAccount(),
            tokenMessengerMinterProgram: getNextAccount(),
            tokenProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getDepositForBurnInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=depositForBurn.js.map