"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.ADD_LOCAL_TOKEN_DISCRIMINATOR = void 0;
exports.getAddLocalTokenDiscriminatorBytes = getAddLocalTokenDiscriminatorBytes;
exports.getAddLocalTokenInstructionDataEncoder = getAddLocalTokenInstructionDataEncoder;
exports.getAddLocalTokenInstructionDataDecoder = getAddLocalTokenInstructionDataDecoder;
exports.getAddLocalTokenInstructionDataCodec = getAddLocalTokenInstructionDataCodec;
exports.getAddLocalTokenInstructionAsync = getAddLocalTokenInstructionAsync;
exports.getAddLocalTokenInstruction = getAddLocalTokenInstruction;
exports.parseAddLocalTokenInstruction = parseAddLocalTokenInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.ADD_LOCAL_TOKEN_DISCRIMINATOR = new Uint8Array([
    213, 199, 205, 18, 98, 124, 73, 198,
]);
function getAddLocalTokenDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ADD_LOCAL_TOKEN_DISCRIMINATOR);
}
function getAddLocalTokenInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({ ...value, discriminator: exports.ADD_LOCAL_TOKEN_DISCRIMINATOR }));
}
function getAddLocalTokenInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getAddLocalTokenInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getAddLocalTokenInstructionDataEncoder(), getAddLocalTokenInstructionDataDecoder());
}
async function getAddLocalTokenInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payer: { value: input.payer ?? null, isWritable: true },
        tokenController: {
            value: input.tokenController ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        custodyTokenAccount: {
            value: input.custodyTokenAccount ?? null,
            isWritable: true,
        },
        localTokenMint: { value: input.localTokenMint ?? 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;
    // Resolve default values.
    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.localTokenMint.value)),
            ],
        });
    }
    if (!accounts.custodyTokenAccount.value) {
        accounts.custodyTokenAccount.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([99, 117, 115, 116, 111, 100, 121])),
                (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.localTokenMint.value)),
            ],
        });
    }
    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.payer),
            getAccountMeta(accounts.tokenController),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.custodyTokenAccount),
            getAccountMeta(accounts.localTokenMint),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getAddLocalTokenInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function getAddLocalTokenInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payer: { value: input.payer ?? null, isWritable: true },
        tokenController: {
            value: input.tokenController ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        custodyTokenAccount: {
            value: input.custodyTokenAccount ?? null,
            isWritable: true,
        },
        localTokenMint: { value: input.localTokenMint ?? 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;
    // Resolve default values.
    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.payer),
            getAccountMeta(accounts.tokenController),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.custodyTokenAccount),
            getAccountMeta(accounts.localTokenMint),
            getAccountMeta(accounts.tokenProgram),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getAddLocalTokenInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function parseAddLocalTokenInstruction(instruction) {
    if (instruction.accounts.length < 10) {
        // 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: {
            payer: getNextAccount(),
            tokenController: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            custodyTokenAccount: getNextAccount(),
            localTokenMint: getNextAccount(),
            tokenProgram: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getAddLocalTokenInstructionDataDecoder().decode(instruction.data),
    };
}
