"use strict";
/**
 * 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
 */
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;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
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)],
        ['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)()],
    ]), (value) => ({ ...value, discriminator: exports.DEPOSIT_FOR_BURN_DISCRIMINATOR }));
}
function getDepositForBurnInstructionDataDecoder() {
    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)()],
    ]);
}
function getDepositForBurnInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getDepositForBurnInstructionDataEncoder(), getDepositForBurnInstructionDataDecoder());
}
async function getDepositForBurnInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        owner: { value: input.owner ?? null, isWritable: false },
        eventRentPayer: { value: input.eventRentPayer ?? null, isWritable: true },
        senderAuthorityPda: {
            value: input.senderAuthorityPda ?? null,
            isWritable: false,
        },
        burnTokenAccount: {
            value: input.burnTokenAccount ?? null,
            isWritable: true,
        },
        denylistAccount: {
            value: input.denylistAccount ?? null,
            isWritable: false,
        },
        messageTransmitter: {
            value: input.messageTransmitter ?? null,
            isWritable: true,
        },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        remoteTokenMessenger: {
            value: input.remoteTokenMessenger ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        burnTokenMint: { value: input.burnTokenMint ?? null, isWritable: true },
        messageSentEventData: {
            value: input.messageSentEventData ?? null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: input.messageTransmitterProgram ?? null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: input.tokenMessengerMinterProgram ?? null,
            isWritable: false,
        },
        tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
        systemProgram: { value: input.systemProgram ?? null, isWritable: false },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    // Resolve default values.
    if (!accounts.senderAuthorityPda.value) {
        accounts.senderAuthorityPda.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    115, 101, 110, 100, 101, 114, 95, 97, 117, 116, 104, 111, 114, 105,
                    116, 121,
                ])),
            ],
        });
    }
    if (!accounts.denylistAccount.value) {
        accounts.denylistAccount.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    100, 101, 110, 121, 108, 105, 115, 116, 95, 97, 99, 99, 111, 117,
                    110, 116,
                ])),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.owner.value)),
            ],
        });
    }
    if (!accounts.localToken.value) {
        accounts.localToken.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([108, 111, 99, 97, 108, 95, 116, 111, 107, 101, 110])),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.burnTokenMint.value)),
            ],
        });
    }
    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) {
        accounts.eventAuthority.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    95, 95, 101, 118, 101, 110, 116, 95, 97, 117, 116, 104, 111, 114,
                    105, 116, 121,
                ])),
            ],
        });
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        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),
        ],
        programAddress,
        data: getDepositForBurnInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getDepositForBurnInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        owner: { value: input.owner ?? null, isWritable: false },
        eventRentPayer: { value: input.eventRentPayer ?? null, isWritable: true },
        senderAuthorityPda: {
            value: input.senderAuthorityPda ?? null,
            isWritable: false,
        },
        burnTokenAccount: {
            value: input.burnTokenAccount ?? null,
            isWritable: true,
        },
        denylistAccount: {
            value: input.denylistAccount ?? null,
            isWritable: false,
        },
        messageTransmitter: {
            value: input.messageTransmitter ?? null,
            isWritable: true,
        },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        remoteTokenMessenger: {
            value: input.remoteTokenMessenger ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        burnTokenMint: { value: input.burnTokenMint ?? null, isWritable: true },
        messageSentEventData: {
            value: input.messageSentEventData ?? null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: input.messageTransmitterProgram ?? null,
            isWritable: false,
        },
        tokenMessengerMinterProgram: {
            value: input.tokenMessengerMinterProgram ?? null,
            isWritable: false,
        },
        tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
        systemProgram: { value: input.systemProgram ?? null, isWritable: false },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...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';
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        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),
        ],
        programAddress,
        data: getDepositForBurnInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseDepositForBurnInstruction(instruction) {
    if (instruction.accounts.length < 18) {
        // TODO: Coded error.
        throw new Error('Not enough accounts');
    }
    let accountIndex = 0;
    const getNextAccount = () => {
        const 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),
    };
}
