"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEPOSIT_FOR_BURN_DISCRIMINATOR = void 0;
exports.getDepositForBurnDiscriminatorBytes = getDepositForBurnDiscriminatorBytes;
exports.getDepositForBurnInstructionDataEncoder = getDepositForBurnInstructionDataEncoder;
exports.getDepositForBurnInstructionDataDecoder = getDepositForBurnInstructionDataDecoder;
exports.getDepositForBurnInstructionDataCodec = getDepositForBurnInstructionDataCodec;
exports.getDepositForBurnInstructionAsync = getDepositForBurnInstructionAsync;
exports.getDepositForBurnInstruction = getDepositForBurnInstruction;
exports.parseDepositForBurnInstruction = parseDepositForBurnInstruction;
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");
var types_1 = require("../types");
exports.DEPOSIT_FOR_BURN_DISCRIMINATOR = new Uint8Array([
    215, 60, 61, 46, 114, 55, 128, 176,
]);
function getDepositForBurnDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.DEPOSIT_FOR_BURN_DISCRIMINATOR);
}
function getDepositForBurnInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["quote", (0, types_1.getSponsoredCCTPQuoteEncoder)()],
        ["signature", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 65)],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.DEPOSIT_FOR_BURN_DISCRIMINATOR })); });
}
function getDepositForBurnInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["quote", (0, types_1.getSponsoredCCTPQuoteDecoder)()],
        ["signature", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 65)],
    ]);
}
function getDepositForBurnInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getDepositForBurnInstructionDataEncoder(), getDepositForBurnInstructionDataDecoder());
}
function getDepositForBurnInstructionAsync(input, config) {
    return tslib_1.__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 tslib_1.__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 : programs_1.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 = tslib_1.__assign({}, input);
                    if (!!accounts.state.value) return [3, 2];
                    _a = accounts.state;
                    return [4, (0, pdas_1.findStatePda)()];
                case 1:
                    _a.value = _6.sent();
                    _6.label = 2;
                case 2:
                    if (!!accounts.rentFund.value) return [3, 4];
                    _b = accounts.rentFund;
                    return [4, (0, pdas_1.findRentFundPda)()];
                case 3:
                    _b.value = _6.sent();
                    _6.label = 4;
                case 4:
                    if (!!accounts.minimumDeposit.value) return [3, 6];
                    _c = accounts.minimumDeposit;
                    return [4, (0, pdas_1.findMinimumDepositPda)({
                            burnToken: (0, shared_1.expectAddress)(accounts.burnToken.value),
                        })];
                case 5:
                    _c.value = _6.sent();
                    _6.label = 6;
                case 6:
                    if (!!accounts.rentClaim.value) return [3, 8];
                    _d = accounts.rentClaim;
                    return [4, (0, pdas_1.findRentClaimPda)({
                            signer: (0, shared_1.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, 10];
                    _e = accounts.depositorTokenAccount;
                    return [4, (0, kit_1.getProgramDerivedAddress)({
                            programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
                            seeds: [
                                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.signer.value)),
                                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.tokenProgram.value)),
                                (0, kit_1.getAddressEncoder)().encode((0, shared_1.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, 12];
                    _f = accounts.eventAuthority;
                    return [4, (0, pdas_1.findEventAuthorityPda)()];
                case 11:
                    _f.value = _6.sent();
                    _6.label = 12;
                case 12:
                    getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
                    return [2, 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,
                        })];
            }
        });
    });
}
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;
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : programs_1.SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    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;
    var args = tslib_1.__assign({}, input);
    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 = (0, shared_1.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,
    });
}
function parseDepositForBurnInstruction(instruction) {
    if (instruction.accounts.length < 23) {
        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 === programs_1.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